|
31 | 31 | import javax.lang.model.element.ExecutableElement; |
32 | 32 |
|
33 | 33 | import org.androidannotations.annotations.RoboGuice; |
| 34 | +import org.androidannotations.helper.APTCodeModelHelper; |
34 | 35 | import org.androidannotations.holder.EActivityHolder; |
35 | 36 | import org.androidannotations.holder.RoboGuiceHolder; |
36 | 37 | import org.androidannotations.model.AnnotationElements; |
37 | 38 | import org.androidannotations.process.IsValid; |
38 | | -import org.androidannotations.process.ProcessHolder; |
39 | 39 |
|
40 | 40 | import com.sun.codemodel.JBlock; |
41 | 41 | import com.sun.codemodel.JClass; |
|
49 | 49 |
|
50 | 50 | public class RoboGuiceHandler extends BaseAnnotationHandler<EActivityHolder> { |
51 | 51 |
|
| 52 | + private APTCodeModelHelper codeModelHelper = new APTCodeModelHelper(); |
| 53 | + |
52 | 54 | public RoboGuiceHandler(ProcessingEnvironment processingEnvironment) { |
53 | 55 | super(RoboGuice.class, processingEnvironment); |
54 | 56 | } |
@@ -177,29 +179,35 @@ private void onNewIntentMethod(RoboGuiceHolder holder, JFieldVar scope, JFieldVa |
177 | 179 | } |
178 | 180 |
|
179 | 181 | private void onStopMethod(RoboGuiceHolder holder, JFieldVar scope, JFieldVar eventManager) { |
180 | | - JBlock onStopBeforeSuperBlock = holder.getOnStopBeforeSuperBlock(); |
181 | | - onStopBeforeSuperBlock.invoke(scope, "enter").arg(_this()); |
| 182 | + JBlock onStopBlock = new JBlock(false, false); |
| 183 | + onStopBlock.invoke(scope, "enter").arg(_this()); |
182 | 184 |
|
183 | | - JTryBlock tryBlock = onStopBeforeSuperBlock._try(); |
| 185 | + JTryBlock tryBlock = onStopBlock._try(); |
184 | 186 | fireEvent(eventManager, tryBlock.body(), classes().ON_STOP_EVENT); |
185 | 187 | JBlock finallyBody = tryBlock._finally(); |
186 | 188 |
|
187 | 189 | finallyBody.invoke(scope, "exit").arg(_this()); |
188 | 190 | finallyBody.invoke(_super(), "onStop"); |
| 191 | + |
| 192 | + JMethod onStop = holder.getOnStop(); |
| 193 | + codeModelHelper.replaceSuperCall(onStop, onStopBlock); |
189 | 194 | } |
190 | 195 |
|
191 | 196 | private void onDestroyMethod(RoboGuiceHolder holder, JFieldVar scope, JFieldVar eventManager) { |
192 | | - JBlock onDestroyBeforeSuperBlock = holder.getOnDestroyBeforeSuperBlock(); |
193 | | - onDestroyBeforeSuperBlock.invoke(scope, "enter").arg(_this()); |
| 197 | + JBlock onDestroyBlock = new JBlock(false, false); |
| 198 | + onDestroyBlock.invoke(scope, "enter").arg(_this()); |
194 | 199 |
|
195 | | - JTryBlock tryBlock = onDestroyBeforeSuperBlock._try(); |
| 200 | + JTryBlock tryBlock = onDestroyBlock._try(); |
196 | 201 | fireEvent(eventManager, tryBlock.body(), classes().ON_DESTROY_EVENT); |
197 | 202 | JBlock finallyBody = tryBlock._finally(); |
198 | 203 |
|
199 | 204 | finallyBody.invoke(eventManager, "clear").arg(_this()); |
200 | 205 | finallyBody.invoke(scope, "exit").arg(_this()); |
201 | 206 | finallyBody.invoke(scope, "dispose").arg(_this()); |
202 | 207 | finallyBody.invoke(_super(), "onDestroy"); |
| 208 | + |
| 209 | + JMethod onDestroy = holder.getOnDestroy(); |
| 210 | + codeModelHelper.replaceSuperCall(onDestroy, onDestroyBlock); |
203 | 211 | } |
204 | 212 |
|
205 | 213 | private void onConfigurationChangedMethod(RoboGuiceHolder holder, JFieldVar eventManager) { |
|
0 commit comments