|
21 | 21 | import org.androidannotations.ElementValidation; |
22 | 22 | import org.androidannotations.annotations.InjectMenu; |
23 | 23 | import org.androidannotations.handler.BaseAnnotationHandler; |
| 24 | +import org.androidannotations.handler.MethodInjectionHandler; |
| 25 | +import org.androidannotations.helper.InjectHelper; |
24 | 26 | import org.androidannotations.holder.HasOptionsMenu; |
25 | 27 |
|
| 28 | +import com.helger.jcodemodel.IJAssignmentTarget; |
26 | 29 | import com.helger.jcodemodel.JBlock; |
27 | | -import com.helger.jcodemodel.JExpr; |
28 | | -import com.helger.jcodemodel.JVar; |
29 | 30 |
|
30 | | -public class InjectMenuHandler extends BaseAnnotationHandler<HasOptionsMenu> { |
| 31 | +public class InjectMenuHandler extends BaseAnnotationHandler<HasOptionsMenu>implements MethodInjectionHandler<HasOptionsMenu> { |
| 32 | + |
| 33 | + private final InjectHelper<HasOptionsMenu> injectHelper; |
31 | 34 |
|
32 | 35 | public InjectMenuHandler(AndroidAnnotationsEnvironment environment) { |
33 | 36 | super(InjectMenu.class, environment); |
| 37 | + injectHelper = new InjectHelper<>(validatorHelper, this); |
34 | 38 | } |
35 | 39 |
|
36 | 40 | @Override |
37 | 41 | public void validate(Element element, ElementValidation valid) { |
38 | | - validatorHelper.enclosingElementHasEActivityOrEFragment(element, valid); |
| 42 | + injectHelper.validate(InjectMenu.class, element, valid); |
39 | 43 |
|
40 | | - validatorHelper.isDeclaredType(element, valid); |
| 44 | + Element param = injectHelper.getParam(element); |
| 45 | + validatorHelper.isDeclaredType(param, valid); |
41 | 46 |
|
42 | | - validatorHelper.extendsMenu(element, valid); |
| 47 | + validatorHelper.extendsMenu(param, valid); |
43 | 48 |
|
44 | 49 | validatorHelper.isNotPrivate(element, valid); |
45 | 50 | } |
46 | 51 |
|
47 | 52 | @Override |
48 | 53 | public void process(Element element, HasOptionsMenu holder) { |
49 | | - String fieldName = element.getSimpleName().toString(); |
50 | | - JBlock body = holder.getOnCreateOptionsMenuMethodBody(); |
51 | | - JVar menuParam = holder.getOnCreateOptionsMenuMenuParam(); |
| 54 | + injectHelper.process(element, holder); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public JBlock getInvocationBlock(HasOptionsMenu holder) { |
| 59 | + return holder.getOnCreateOptionsMenuMethodBody(); |
| 60 | + } |
52 | 61 |
|
53 | | - body.assign(JExpr._this().ref(fieldName), menuParam); |
| 62 | + @Override |
| 63 | + public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, HasOptionsMenu holder, Element element, Element param) { |
| 64 | + targetBlock.add(fieldRef.assign(holder.getOnCreateOptionsMenuMenuParam())); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public void validateEnclosingElement(Element element, ElementValidation valid) { |
| 69 | + validatorHelper.enclosingElementHasEActivityOrEFragment(element, valid); |
54 | 70 | } |
55 | 71 | } |
0 commit comments