|
15 | 15 | */ |
16 | 16 | package org.androidannotations.handler; |
17 | 17 |
|
18 | | -import javax.annotation.processing.ProcessingEnvironment; |
19 | | -import javax.lang.model.element.Element; |
20 | | -import javax.lang.model.element.Name; |
21 | | -import javax.lang.model.element.VariableElement; |
22 | | - |
23 | | -import org.androidannotations.annotations.Result; |
24 | | -import org.androidannotations.helper.APTCodeModelHelper; |
25 | | -import org.androidannotations.helper.AnnotationHelper; |
26 | | -import org.androidannotations.helper.BundleHelper; |
27 | | -import org.androidannotations.helper.IdValidatorHelper; |
28 | | -import org.androidannotations.helper.TargetAnnotationHelper; |
29 | | -import org.androidannotations.helper.ValidatorHelper; |
30 | | -import org.androidannotations.holder.HasOnActivityResult; |
31 | | -import org.androidannotations.model.AnnotationElements; |
32 | | - |
33 | 18 | import com.sun.codemodel.JBlock; |
34 | 19 | import com.sun.codemodel.JClass; |
35 | 20 | import com.sun.codemodel.JExpr; |
36 | 21 | import com.sun.codemodel.JExpression; |
37 | 22 | import com.sun.codemodel.JVar; |
| 23 | +import org.androidannotations.annotations.OnActivityResult; |
| 24 | +import org.androidannotations.helper.APTCodeModelHelper; |
| 25 | +import org.androidannotations.helper.AnnotationHelper; |
| 26 | +import org.androidannotations.helper.BundleHelper; |
| 27 | +import org.androidannotations.holder.HasOnActivityResult; |
| 28 | +import org.androidannotations.model.AnnotationElements; |
38 | 29 | import org.androidannotations.process.IsValid; |
39 | 30 |
|
40 | | -public class ResultHandler { |
| 31 | +import javax.annotation.processing.ProcessingEnvironment; |
| 32 | +import javax.lang.model.element.Element; |
| 33 | +import javax.lang.model.element.VariableElement; |
| 34 | + |
| 35 | +public class OnActivityResultExtraHandler extends BaseAnnotationHandler<HasOnActivityResult> { |
41 | 36 |
|
42 | 37 | private final static APTCodeModelHelper codeModelHelper = new APTCodeModelHelper(); |
43 | 38 |
|
44 | | - public static JExpression getExtraValue(HasOnActivityResult holder, JBlock block, |
45 | | - VariableElement parameter) { |
46 | | - Result annotation = parameter.getAnnotation(Result.class); |
| 39 | + public OnActivityResultExtraHandler(ProcessingEnvironment processingEnvironment) { |
| 40 | + super(OnActivityResult.Extra.class, processingEnvironment); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected void validate(Element element, AnnotationElements validatedElements, IsValid valid) { |
| 45 | + validatorHelper.enclosingMethodHasAnnotation(OnActivityResult.class, element, validatedElements, valid); |
| 46 | + |
| 47 | + validatorHelper.canBePutInABundle(element, valid); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public void process(Element element, HasOnActivityResult holder) throws Exception { |
| 52 | + // Don't do anything |
| 53 | + } |
| 54 | + |
| 55 | + public static JExpression getExtraValue(HasOnActivityResult holder, JBlock block, VariableElement parameter) { |
| 56 | + OnActivityResult.Extra annotation = parameter.getAnnotation(OnActivityResult.Extra.class); |
47 | 57 | String parameterName = parameter.getSimpleName().toString(); |
48 | 58 | String extraKey = annotation.value(); |
49 | 59 | if (extraKey.isEmpty()) { |
50 | 60 | extraKey = parameterName; |
51 | 61 | } |
52 | 62 |
|
53 | 63 | JVar extras = holder.getOnActivityResultExtras(); |
54 | | - BundleHelper bundleHelper = new BundleHelper(new AnnotationHelper(holder.processingEnvironment()), parameter); |
| 64 | + BundleHelper bundleHelper = new BundleHelper(new AnnotationHelper(holder.processingEnvironment()), parameter.asType()); |
55 | 65 | JExpression restoreMethodCall = JExpr.invoke(extras, bundleHelper.getMethodNameToRestore()).arg(extraKey); |
56 | 66 | JClass parameterClass = codeModelHelper.typeMirrorToJClass(parameter.asType(), holder); |
57 | 67 | if (bundleHelper.restoreCallNeedCastStatement()) { |
|
0 commit comments