Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 1239f62

Browse files
committed
Use new method to check class in classpath
1 parent d4f72ee commit 1239f62

4 files changed

Lines changed: 20 additions & 24 deletions

File tree

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ private ModelProcessor buildModelProcessor(IRClass rClass, AndroidSystemServices
487487
ModelProcessor modelProcessor = new ModelProcessor();
488488
modelProcessor.register(new EApplicationProcessor());
489489
modelProcessor.register(new EActivityProcessor(processingEnv, rClass));
490-
modelProcessor.register(new EServiceProcessor());
490+
modelProcessor.register(new EServiceProcessor(processingEnv));
491491
modelProcessor.register(new EReceiverProcessor());
492492
modelProcessor.register(new EProviderProcessor());
493493
modelProcessor.register(new EFragmentProcessor(processingEnv, rClass));

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java‎

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import javax.lang.model.type.DeclaredType;
3636
import javax.lang.model.type.TypeMirror;
3737
import javax.lang.model.type.WildcardType;
38+
import javax.lang.model.util.Elements;
3839

3940
import org.androidannotations.processing.EBeanHolder;
4041
import org.androidannotations.processing.EBeansHolder.Classes;
@@ -313,15 +314,15 @@ public JVar findParameterByName(JMethod method, String name) {
313314
return null;
314315
}
315316

316-
public void addActivityIntentBuilder(JCodeModel codeModel, EBeanHolder holder) throws Exception {
317-
addIntentBuilder(codeModel, holder, true);
317+
public void addActivityIntentBuilder(JCodeModel codeModel, EBeanHolder holder, AnnotationHelper annotationHelper) throws Exception {
318+
addIntentBuilder(codeModel, holder, annotationHelper, true);
318319
}
319320

320-
public void addServiceIntentBuilder(JCodeModel codeModel, EBeanHolder holder) throws Exception {
321-
addIntentBuilder(codeModel, holder, false);
321+
public void addServiceIntentBuilder(JCodeModel codeModel, EBeanHolder holder, AnnotationHelper annotationHelper) throws Exception {
322+
addIntentBuilder(codeModel, holder, annotationHelper, false);
322323
}
323324

324-
private void addIntentBuilder(JCodeModel codeModel, EBeanHolder holder, boolean isActivity) throws JClassAlreadyExistsException {
325+
private void addIntentBuilder(JCodeModel codeModel, EBeanHolder holder, AnnotationHelper annotationHelper, boolean isActivity) throws JClassAlreadyExistsException {
325326
JClass contextClass = holder.classes().CONTEXT;
326327
JClass intentClass = holder.classes().INTENT;
327328
JClass fragmentClass = holder.classes().FRAGMENT;
@@ -342,27 +343,17 @@ private void addIntentBuilder(JCodeModel codeModel, EBeanHolder holder, boolean
342343
constructorBody.assign(holder.intentField, _new(intentClass).arg(constructorContextParam).arg(holder.generatedClass.dotclass()));
343344
}
344345
// Additional constructor for fragments (issue #541)
345-
boolean fragmentInClasspath = true;
346-
try {
347-
Class.forName(fragmentClass.fullName(), false, getClass().getClassLoader());
348-
} catch (ClassNotFoundException e) {
349-
fragmentInClasspath = false;
346+
Elements elementUtils = annotationHelper.getElementUtils();
347+
boolean fragmentInClasspath = elementUtils.getTypeElement(CanonicalNameConstants.FRAGMENT) != null;
348+
boolean fragmentSupportInClasspath = elementUtils.getTypeElement(CanonicalNameConstants.SUPPORT_V4_FRAGMENT) != null;
350349

351-
}
352-
boolean fragmentSupportInClasspath = true;
353-
try {
354-
Class.forName(fragmentSupportClass.fullName(), false, getClass().getClassLoader());
355-
} catch (ClassNotFoundException e) {
356-
fragmentSupportInClasspath = false;
357-
358-
}
359350
JFieldVar fragmentField = null;
360351
if (fragmentInClasspath) {
361-
fragmentField = addIntentBuilderFragmentConstructor(holder, holder.classes().FRAGMENT, "fragment_", contextField);
352+
fragmentField = addIntentBuilderFragmentConstructor(holder, fragmentClass, "fragment_", contextField);
362353
}
363354
JFieldVar fragmentSupportField = null;
364355
if (fragmentSupportInClasspath) {
365-
fragmentSupportField = addIntentBuilderFragmentConstructor(holder, holder.classes().SUPPORT_V4_FRAGMENT, "fragmentSupport_", contextField);
356+
fragmentSupportField = addIntentBuilderFragmentConstructor(holder, fragmentSupportClass, "fragmentSupport_", contextField);
366357
}
367358

368359
{

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EActivityProcessor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void process(Element element, JCodeModel codeModel, EBeansHolder eBeansHo
201201

202202
}
203203

204-
aptCodeModelHelper.addActivityIntentBuilder(codeModel, holder);
204+
aptCodeModelHelper.addActivityIntentBuilder(codeModel, holder, annotationHelper);
205205

206206
}
207207

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EServiceProcessor.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
import static com.sun.codemodel.JMod.PRIVATE;
2121
import static com.sun.codemodel.JMod.PUBLIC;
2222

23+
import javax.annotation.processing.ProcessingEnvironment;
2324
import javax.lang.model.element.Element;
2425
import javax.lang.model.element.TypeElement;
2526

2627
import org.androidannotations.annotations.EService;
2728
import org.androidannotations.helper.APTCodeModelHelper;
29+
import org.androidannotations.helper.AnnotationHelper;
2830
import org.androidannotations.helper.ModelConstants;
2931

3032
import com.sun.codemodel.ClassType;
@@ -39,8 +41,11 @@ public class EServiceProcessor implements GeneratingElementProcessor {
3941

4042
private final APTCodeModelHelper aptCodeModelHelper;
4143

42-
public EServiceProcessor() {
44+
private final AnnotationHelper annotationHelper;
45+
46+
public EServiceProcessor(ProcessingEnvironment processingEnv) {
4347
aptCodeModelHelper = new APTCodeModelHelper();
48+
annotationHelper = new AnnotationHelper(processingEnv);
4449
}
4550

4651
@Override
@@ -88,7 +93,7 @@ public void process(Element element, JCodeModel codeModel, EBeansHolder eBeansHo
8893
holder.initActivityRef = null;
8994
}
9095

91-
aptCodeModelHelper.addServiceIntentBuilder(codeModel, holder);
96+
aptCodeModelHelper.addServiceIntentBuilder(codeModel, holder, annotationHelper);
9297

9398
}
9499

0 commit comments

Comments
 (0)