3232import javax .lang .model .type .TypeMirror ;
3333
3434import com .googlecode .androidannotations .processing .EBeanHolder ;
35+ import com .googlecode .androidannotations .processing .EBeansHolder .Classes ;
3536import com .sun .codemodel .JBlock ;
3637import com .sun .codemodel .JCatchBlock ;
3738import com .sun .codemodel .JClass ;
@@ -90,7 +91,7 @@ public Parameter(String name, JClass jClass) {
9091 this .jClass = jClass ;
9192 }
9293 }
93-
94+
9495 public JMethod overrideAnnotatedMethod (ExecutableElement executableElement , EBeanHolder holder ) {
9596
9697 String methodName = executableElement .getSimpleName ().toString ();
@@ -103,13 +104,13 @@ public JMethod overrideAnnotatedMethod(ExecutableElement executableElement, EBea
103104 JClass parameterClass = typeMirrorToJClass (parameter .asType (), holder );
104105 parameters .add (new Parameter (parameterName , parameterClass ));
105106 }
106-
107+
107108 JMethod existingMethod = findAlreadyGeneratedMethod (holder .eBean , methodName , parameters );
108-
109+
109110 if (existingMethod != null ) {
110111 return existingMethod ;
111112 }
112-
113+
113114 JMethod method = holder .eBean .method (JMod .PUBLIC , returnType , methodName );
114115 method .annotate (Override .class );
115116
@@ -125,7 +126,7 @@ public JMethod overrideAnnotatedMethod(ExecutableElement executableElement, EBea
125126 JClass thrownType = typeMirrorToJClass (superThrownType , holder );
126127 method ._throws (thrownType );
127128 }
128-
129+
129130 callSuperMethod (method , holder , method .body ());
130131
131132 return method ;
@@ -163,7 +164,7 @@ public void callSuperMethod(JMethod superMethod, EBeanHolder holder, JBlock call
163164 callBlock ._return (superCall );
164165 }
165166 }
166-
167+
167168 public JBlock removeBody (JMethod method ) {
168169 JBlock body = method .body ();
169170 try {
@@ -173,16 +174,16 @@ public JBlock removeBody(JMethod method) {
173174 } catch (Exception e ) {
174175 throw new RuntimeException (e );
175176 }
176-
177+
177178 JBlock clonedBody = new JBlock (false , false );
178-
179- for (Object statement : body .getContents ()) {
179+
180+ for (Object statement : body .getContents ()) {
180181 clonedBody .add ((JStatement ) statement );
181182 }
182-
183+
183184 return clonedBody ;
184185 }
185-
186+
186187 public String getIdStringFromIdFieldRef (JFieldRef idRef ) {
187188 try {
188189 Field nameField = JFieldRef .class .getDeclaredField ("name" );
@@ -208,7 +209,11 @@ public String getIdStringFromIdFieldRef(JFieldRef idRef) {
208209 throw new IllegalStateException ("Unable to extract target name from JFieldRef" );
209210 }
210211
211- public JDefinedClass createDelegatingAnonymousRunnableClass (JCodeModel codeModel , EBeanHolder holder , JMethod delegatedMethod ) {
212+ public JDefinedClass createDelegatingAnonymousRunnableClass (EBeanHolder holder , JMethod delegatedMethod ) {
213+
214+ JCodeModel codeModel = holder .codeModel ();
215+ Classes classes = holder .classes ();
216+
212217 JDefinedClass anonymousRunnableClass ;
213218 JBlock previousMethodBody = removeBody (delegatedMethod );
214219
@@ -222,12 +227,10 @@ public JDefinedClass createDelegatingAnonymousRunnableClass(JCodeModel codeModel
222227
223228 runTry .body ().add (previousMethodBody );
224229
225- JCatchBlock runCatch = runTry ._catch (holder . refClass ( RuntimeException . class ) );
230+ JCatchBlock runCatch = runTry ._catch (classes . RUNTIME_EXCEPTION );
226231 JVar exceptionParam = runCatch .param ("e" );
227232
228- JClass logClass = holder .refClass ("android.util.Log" );
229-
230- JInvocation errorInvoke = logClass .staticInvoke ("e" );
233+ JInvocation errorInvoke = classes .LOG .staticInvoke ("e" );
231234
232235 errorInvoke .arg (holder .eBean .name ());
233236 errorInvoke .arg ("A runtime exception was thrown while executing code in a runnable" );
@@ -236,18 +239,16 @@ public JDefinedClass createDelegatingAnonymousRunnableClass(JCodeModel codeModel
236239 runCatch .body ().add (errorInvoke );
237240 return anonymousRunnableClass ;
238241 }
239-
242+
240243 public JVar castContextToActivity (EBeanHolder holder , JBlock ifActivityBody ) {
241- JClass activityClass = holder .refClass ( "android.app.Activity" ) ;
244+ JClass activityClass = holder .classes (). ACTIVITY ;
242245 return ifActivityBody .decl (activityClass , "activity" , cast (activityClass , holder .contextRef ));
243246 }
244247
245248 public JBlock ifContextInstanceOfActivity (EBeanHolder holder , JBlock methodBody ) {
246- JClass activityClass = holder .refClass ("android.app.Activity" );
247- return methodBody ._if (holder .contextRef ._instanceof (activityClass ))._then ();
249+ return methodBody ._if (holder .contextRef ._instanceof (holder .classes ().ACTIVITY ))._then ();
248250 }
249251
250-
251252 public void copyConstructorsAndAddStaticEViewBuilders (Element element , JCodeModel codeModel , JClass eBeanClass , EBeanHolder holder , JMethod setContentViewMethod ) {
252253 List <ExecutableElement > constructors = new ArrayList <ExecutableElement >();
253254 for (Element e : element .getEnclosedElements ()) {
@@ -261,7 +262,7 @@ public void copyConstructorsAndAddStaticEViewBuilders(Element element, JCodeMode
261262 JMethod staticHelper = holder .eBean .method (PUBLIC | STATIC , eBeanClass , "build" );
262263 JBlock body = copyConstructor .body ();
263264 JInvocation superCall = body .invoke ("super" );
264- JInvocation newInvocation = JExpr ._new (holder .eBean );
265+ JInvocation newInvocation = JExpr ._new (holder .eBean );
265266 for (VariableElement param : userConstructor .getParameters ()) {
266267 String paramName = param .getSimpleName ().toString ();
267268 String paramType = param .asType ().toString ();
@@ -277,7 +278,7 @@ public void copyConstructorsAndAddStaticEViewBuilders(Element element, JCodeMode
277278 body .invoke (holder .init );
278279 }
279280 }
280-
281+
281282 public JVar findParameterByName (JMethod method , String name ) {
282283 for (JVar parameter : method .params ()) {
283284 if (parameter .name ().equals (name )) {
0 commit comments