diff --git a/.idea/misc.xml b/.idea/misc.xml index a2f29b9..df4c9cd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -39,7 +39,6 @@ - @@ -78,21 +77,11 @@ - - - - - - - - - - - + \ No newline at end of file diff --git a/.idea/saveactions_settings.xml b/.idea/saveactions_settings.xml new file mode 100644 index 0000000..7cf45e2 --- /dev/null +++ b/.idea/saveactions_settings.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 7dfb97d..46d5dae 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,13 @@ In the `build.gradle` file of the module project: ```gradle dependencies { // Android Annotations for Greenrobot - apt 'com.tmtron:green-annotations:1.0.1' - compile 'com.tmtron:green-annotations-api:1.0.1' + apt 'com.tmtron:green-annotations:1.0.2' + compile 'com.tmtron:green-annotations-api:1.0.2' } ``` +Note: Green-Annotations version `1.0.2` requires Android-Annotations version `4.4.0` + ## Details ### Before diff --git a/green-annotations-api/green-annotations-api.iml b/green-annotations-api/green-annotations-api.iml index 35b43b0..2007079 100644 --- a/green-annotations-api/green-annotations-api.iml +++ b/green-annotations-api/green-annotations-api.iml @@ -1,6 +1,6 @@ - + diff --git a/green-annotations-api/pom.xml b/green-annotations-api/pom.xml index 5afa407..8d8cf7e 100644 --- a/green-annotations-api/pom.xml +++ b/green-annotations-api/pom.xml @@ -23,7 +23,7 @@ com.tmtron green-annotations-parent - 1.0.2-SNAPSHOT + 1.0.2 green-annotations-api diff --git a/green-annotations-parent.iml b/green-annotations-parent.iml index 66b3d79..4fd5057 100644 --- a/green-annotations-parent.iml +++ b/green-annotations-parent.iml @@ -1,6 +1,6 @@ - + diff --git a/green-annotations-test/green-annotations-test.iml b/green-annotations-test/green-annotations-test.iml index 46d2f47..0c3255b 100644 --- a/green-annotations-test/green-annotations-test.iml +++ b/green-annotations-test/green-annotations-test.iml @@ -10,6 +10,7 @@ - + - - - - - - - - - - - - - - - - - - - - - + - + - - + + + + - - + + diff --git a/green-annotations-test/pom.xml b/green-annotations-test/pom.xml index 30fd2ea..f6ff73b 100644 --- a/green-annotations-test/pom.xml +++ b/green-annotations-test/pom.xml @@ -22,7 +22,7 @@ com.tmtron green-annotations-parent - 1.0.2-SNAPSHOT + 1.0.2 green-annotations-test diff --git a/green-annotations/green-annotations.iml b/green-annotations/green-annotations.iml index 43cc27f..975674d 100644 --- a/green-annotations/green-annotations.iml +++ b/green-annotations/green-annotations.iml @@ -1,6 +1,6 @@ - + @@ -10,33 +10,21 @@ - - - - - - - - - - - - - - - + - - - + + + - - + + + + diff --git a/green-annotations/pom.xml b/green-annotations/pom.xml index beee1ad..e9be356 100644 --- a/green-annotations/pom.xml +++ b/green-annotations/pom.xml @@ -23,7 +23,7 @@ com.tmtron green-annotations-parent - 1.0.2-SNAPSHOT + 1.0.2 green-annotations diff --git a/green-annotations/src/main/java/com/tmtron/greenannotations/handler/EventBusGreenRobotHandler.java b/green-annotations/src/main/java/com/tmtron/greenannotations/handler/EventBusGreenRobotHandler.java index c8164f0..f5909f7 100644 --- a/green-annotations/src/main/java/com/tmtron/greenannotations/handler/EventBusGreenRobotHandler.java +++ b/green-annotations/src/main/java/com/tmtron/greenannotations/handler/EventBusGreenRobotHandler.java @@ -15,24 +15,30 @@ */ package com.tmtron.greenannotations.handler; -import com.helger.jcodemodel.*; +import com.helger.jcodemodel.AbstractJClass; +import com.helger.jcodemodel.IJAssignmentTarget; +import com.helger.jcodemodel.IJExpression; +import com.helger.jcodemodel.IJStatement; +import com.helger.jcodemodel.JBlock; +import com.helger.jcodemodel.JExpr; import com.tmtron.greenannotations.EventBusGreenRobot; + import org.androidannotations.AndroidAnnotationsEnvironment; import org.androidannotations.ElementValidation; import org.androidannotations.handler.BaseAnnotationHandler; import org.androidannotations.handler.MethodInjectionHandler; import org.androidannotations.helper.InjectHelper; import org.androidannotations.holder.EComponentHolder; -import org.androidannotations.holder.EServiceHolder; -import org.androidannotations.holder.HasLifecycleMethods; +import org.androidannotations.holder.HasSimpleLifecycleMethods; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; +import java.util.ArrayList; +import java.util.List; + import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.type.TypeMirror; -import java.util.ArrayList; -import java.util.List; /** * Handler for the {@link EventBusGreenRobot} annotation. @@ -40,17 +46,17 @@ *
  • When the class contains an instance of {@link EventBus} which is annotated with {@link EventBusGreenRobot}, we * it will automatically be initialized with the default event bus: {@link EventBus#getDefault()}
  • *
  • In addition, when the parent class has - *
      - *
    • life-cycle methods (e.g. {@link org.androidannotations.annotations.EActivity}, - * {@link org.androidannotations.annotations.EService}, etc.)
    • - *
    • AND at least one {@link Subscribe} annotation
    • + *
        + *
      • life-cycle methods (e.g. {@link org.androidannotations.annotations.EActivity}, + * {@link org.androidannotations.annotations.EService}, etc.)
      • + *
      • AND at least one {@link Subscribe} annotation
      • *
      * We will also add {@link EventBus#register(Object)}/{@link EventBus#unregister(Object)} calls: *
        - *
      • {@link org.androidannotations.annotations.EService @EService}: {@code onCreate}/{@code onDestroy}
      • - *
      • for others (e.g. {@link org.androidannotations.annotations.EActivity @EActivity}, - * {@link org.androidannotations.annotations.EBean @EBean}): {@code onStart}/{@code onStop} - *
      • + *
      • {@link org.androidannotations.annotations.EService @EService}: {@code onCreate}/{@code onDestroy}
      • + *
      • for others (e.g. {@link org.androidannotations.annotations.EActivity @EActivity}, + * {@link org.androidannotations.annotations.EBean @EBean}): {@code onStart}/{@code onStop} + *
      • *
      * *
    @@ -96,7 +102,8 @@ public JBlock getInvocationBlock(EComponentHolder holder) { } @Override - public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element element, Element param) { + public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element + element, Element param) { // the InjectHelper will call this function // * targetBlock is a block in the init-method (which is returned by @getInvocationBlock) // * fieldRef is the field reference (this.bus) that is annotated with this EventBusGreenRobot annotation @@ -104,10 +111,10 @@ public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, ECompon initEventBusMember(targetBlock, fieldRef, param); - if (holder instanceof HasLifecycleMethods) { + if (holder instanceof HasSimpleLifecycleMethods) { if (hasSubscribeAnnotation(element)) { // we need to register/unregister the event-bus - handleEventBusRegistration(fieldRef, (HasLifecycleMethods) holder); + handleEventBusRegistration(fieldRef, (HasSimpleLifecycleMethods) holder); } } } @@ -119,10 +126,10 @@ public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, ECompon * and is of type {@link org.greenrobot.eventbus.EventBus} with the * default event-bus: {@link EventBus#getDefault()} *

    - - * @param targetBlock the code block where the initialization code is added to - * @param fieldRef the reference to the event-bus member variable. - * @param param the annotated element + * + * @param targetBlock the code block where the initialization code is added to + * @param fieldRef the reference to the event-bus member variable. + * @param param the annotated element */ private void initEventBusMember(JBlock targetBlock, IJAssignmentTarget fieldRef, Element param) { TypeMirror fieldType = param.asType(); @@ -144,7 +151,7 @@ private void initEventBusMember(JBlock targetBlock, IJAssignmentTarget fieldRef, * then we must register/unregister the class with the EventBus *

    * - * @param element the element to check for the @{@link Subscribe} annotation + * @param element the element to check for the @{@link Subscribe} annotation * @return if we must register/unregister the EventBus */ private boolean hasSubscribeAnnotation(Element element) { @@ -166,21 +173,25 @@ private boolean hasSubscribeAnnotation(Element element) { /** * adds register/unregister calls for the EventBus to the onStart/onStop methods * - * @param fieldRef is the field reference ({@code this.bus}) that is annotated the {@link EventBusGreenRobot} annotation - * @param holderWithLifecycleMethods the component holder which implements {@link HasLifecycleMethods} + * @param fieldRef is the field reference ({@code this.bus}) that is annotated the + * {@link EventBusGreenRobot} annotation + * @param holderWithLifecycleMethods the component holder which implements {@link HasSimpleLifecycleMethods} */ private void handleEventBusRegistration(IJAssignmentTarget fieldRef - , HasLifecycleMethods holderWithLifecycleMethods) { + , HasSimpleLifecycleMethods holderWithLifecycleMethods) { JBlock onStartBlock; JBlock onStopBlock; - if (holderWithLifecycleMethods instanceof EServiceHolder) { - onStartBlock = holderWithLifecycleMethods.getOnCreateAfterSuperBlock(); - onStopBlock = holderWithLifecycleMethods.getOnDestroyBeforeSuperBlock(); - } else { - onStartBlock = holderWithLifecycleMethods.getOnStartAfterSuperBlock(); - onStopBlock = holderWithLifecycleMethods.getOnStopBeforeSuperBlock(); - } + onStartBlock = holderWithLifecycleMethods.getStartLifecycleAfterSuperBlock(); + onStopBlock = holderWithLifecycleMethods.getEndLifecycleBeforeSuperBlock(); + +// if (holderWithLifecycleMethods instanceof EServiceHolder) { +// onStartBlock = holderWithLifecycleMethods.getOnCreateAfterSuperBlock(); +// onStopBlock = holderWithLifecycleMethods.getOnDestroyBeforeSuperBlock(); +// } else { +// onStartBlock = holderWithLifecycleMethods.getOnStartAfterSuperBlock(); +// onStopBlock = holderWithLifecycleMethods.getOnStopBeforeSuperBlock(); +// } onStartBlock.invoke(fieldRef, "register").arg(JExpr._this()); onStopBlock.invoke(fieldRef, "unregister").arg(JExpr._this()); } diff --git a/pom.xml b/pom.xml index cd984c8..6f24263 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ com.tmtron green-annotations-parent - 1.0.2-SNAPSHOT + 1.0.2 GreenRobot AndroidAnnotations parent An AndroidAnnotations plugin to support GreenRobot @@ -51,7 +51,7 @@ --> 1.7 - 4.1.0 + 4.4.0 @@ -188,7 +188,7 @@ com.helger jcodemodel - 2.8.5 + 3.0.1 junit @@ -263,7 +263,7 @@ 4.4.1 - 17 + 25 true