Skip to content

Commit 49f96c1

Browse files
committed
add @AfterExtras
1 parent f820f5f commit 49f96c1

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (C) 2010-2014 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.annotations;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
* Methods annotated with @{@link AfterExtras} will be called after the Extras
25+
* from an Intent have been injected.
26+
*
27+
* Any code depending on injected extras should be done in an
28+
* {@link AfterExtras} annotated method.
29+
*
30+
* The method must have zero parameters.
31+
*
32+
* There may be several methods annotated with @{@link AfterExtras} in the same
33+
* class.
34+
*
35+
*/
36+
@Retention(RetentionPolicy.CLASS)
37+
@Target(ElementType.METHOD)
38+
public @interface AfterExtras {
39+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright (C) 2010-2013 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.handler;
17+
18+
import javax.annotation.processing.ProcessingEnvironment;
19+
import javax.lang.model.element.Element;
20+
import javax.lang.model.element.ExecutableElement;
21+
22+
import org.androidannotations.annotations.AfterExtras;
23+
import org.androidannotations.holder.EActivityHolder;
24+
import org.androidannotations.model.AnnotationElements;
25+
import org.androidannotations.process.IsValid;
26+
27+
public class AfterExtrasHandler extends BaseAnnotationHandler<EActivityHolder> {
28+
29+
public AfterExtrasHandler(ProcessingEnvironment processingEnvironment) {
30+
super(AfterExtras.class, processingEnvironment);
31+
}
32+
33+
@Override
34+
public void validate(Element element, AnnotationElements validatedElements, IsValid valid) {
35+
validatorHelper.enclosingElementHasEActivity(element, validatedElements, valid);
36+
37+
ExecutableElement executableElement = (ExecutableElement) element;
38+
39+
validatorHelper.returnTypeIsVoid(executableElement, valid);
40+
41+
validatorHelper.isNotPrivate(element, valid);
42+
43+
validatorHelper.doesntThrowException(executableElement, valid);
44+
45+
validatorHelper.param.zeroParameter(executableElement, valid);
46+
}
47+
48+
@Override
49+
public void process(Element element, EActivityHolder holder) {
50+
String methodName = element.getSimpleName().toString();
51+
holder.getInjectExtrasBlock().invoke(methodName);
52+
}
53+
}

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/handler/AnnotationHandlers.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public AnnotationHandlers(ProcessingEnvironment processingEnvironment) {
109109
add(new IgnoredWhenDetachedHandler(processingEnvironment));
110110
/* After injection methods must be after injections */
111111
add(new AfterInjectHandler(processingEnvironment));
112+
add(new AfterExtrasHandler(processingEnvironment));
112113
add(new AfterViewsHandler(processingEnvironment));
113114

114115
if (optionsHelper.shouldLogTrace()) {

0 commit comments

Comments
 (0)