Skip to content

Commit 26199a5

Browse files
committed
Ignoring Otto annotations when used separately from AA annotated classes
1 parent e22ca8e commit 26199a5

5 files changed

Lines changed: 50 additions & 18 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.androidannotations.helper;
1717

1818
import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX;
19+
import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_COMPONENT_ANNOTATIONS;
1920

2021
import java.lang.annotation.Annotation;
2122
import java.lang.reflect.InvocationTargetException;
@@ -382,4 +383,18 @@ public boolean enclosingElementIsGenerated(Element element) {
382383
return enclosingElement.getSimpleName().toString().endsWith(GENERATION_SUFFIX);
383384
}
384385

386+
public boolean enclosingElementHasEnhancedComponentAnnotation(Element element) {
387+
Element enclosingElement = element.getEnclosingElement();
388+
return hasOneOfClassAnnotations(enclosingElement, VALID_ENHANCED_COMPONENT_ANNOTATIONS);
389+
}
390+
391+
public boolean hasOneOfClassAnnotations(Element element, List<Class<? extends Annotation>> validAnnotations) {
392+
for (Class<? extends Annotation> validAnnotation : validAnnotations) {
393+
if (element.getAnnotation(validAnnotation) != null) {
394+
return true;
395+
}
396+
}
397+
return false;
398+
}
399+
385400
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,33 @@
1515
*/
1616
package org.androidannotations.helper;
1717

18+
import static java.util.Arrays.asList;
19+
20+
import java.lang.annotation.Annotation;
21+
import java.util.List;
22+
23+
import org.androidannotations.annotations.EActivity;
24+
import org.androidannotations.annotations.EApplication;
25+
import org.androidannotations.annotations.EBean;
26+
import org.androidannotations.annotations.EFragment;
27+
import org.androidannotations.annotations.EProvider;
28+
import org.androidannotations.annotations.EReceiver;
29+
import org.androidannotations.annotations.EService;
30+
import org.androidannotations.annotations.EView;
31+
import org.androidannotations.annotations.EViewGroup;
32+
1833
public abstract class ModelConstants {
1934

2035
public static final String GENERATION_SUFFIX = "_";
2136

2237
public static final String TRACE_OPTION = "trace";
2338

39+
@SuppressWarnings("unchecked")
40+
public static final List<Class<? extends Annotation>> VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS = asList(EActivity.class, EViewGroup.class, EView.class, EBean.class, EFragment.class);
41+
42+
@SuppressWarnings("unchecked")
43+
public static final List<Class<? extends Annotation>> VALID_ENHANCED_COMPONENT_ANNOTATIONS = asList(EApplication.class, EActivity.class, EViewGroup.class, EView.class, EBean.class, EService.class, EReceiver.class, EProvider.class, EFragment.class);
44+
2445
private ModelConstants() {
2546
}
2647

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import static org.androidannotations.helper.CanonicalNameConstants.HTTP_MESSAGE_CONVERTER;
2626
import static org.androidannotations.helper.CanonicalNameConstants.INTERNET_PERMISSION;
2727
import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX;
28+
import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_COMPONENT_ANNOTATIONS;
29+
import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS;
2830

2931
import java.lang.annotation.Annotation;
3032
import java.util.ArrayList;
@@ -49,14 +51,8 @@
4951
import javax.lang.model.util.Elements;
5052

5153
import org.androidannotations.annotations.EActivity;
52-
import org.androidannotations.annotations.EApplication;
5354
import org.androidannotations.annotations.EBean;
5455
import org.androidannotations.annotations.EFragment;
55-
import org.androidannotations.annotations.EProvider;
56-
import org.androidannotations.annotations.EReceiver;
57-
import org.androidannotations.annotations.EService;
58-
import org.androidannotations.annotations.EView;
59-
import org.androidannotations.annotations.EViewGroup;
6056
import org.androidannotations.annotations.Trace;
6157
import org.androidannotations.annotations.ViewById;
6258
import org.androidannotations.annotations.rest.Delete;
@@ -91,12 +87,6 @@ public class ValidatorHelper {
9187

9288
private static final Collection<Integer> VALID_LOG_LEVELS = Arrays.asList(LOG_VERBOSE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR);
9389

94-
@SuppressWarnings("unchecked")
95-
private static final List<Class<? extends Annotation>> VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS = asList(EActivity.class, EViewGroup.class, EView.class, EBean.class, EFragment.class);
96-
97-
@SuppressWarnings("unchecked")
98-
private static final List<Class<? extends Annotation>> VALID_ENHANCED_COMPONENT_ANNOTATIONS = asList(EApplication.class, EActivity.class, EViewGroup.class, EView.class, EBean.class, EService.class, EReceiver.class, EProvider.class, EFragment.class);
99-
10090
protected final TargetAnnotationHelper annotationHelper;
10191

10292
public ValidatorHelper(TargetAnnotationHelper targetAnnotationHelper) {

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/validation/ProduceValidator.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ public String getTarget() {
4343
@Override
4444
public boolean validate(Element element, AnnotationElements validatedElements) {
4545

46-
if (annotationHelper.enclosingElementIsGenerated(element)) {
46+
if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) {
4747
return false;
4848
}
4949

5050
IsValid valid = new IsValid();
5151

52-
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(element, validatedElements, valid);
53-
5452
ExecutableElement executableElement = (ExecutableElement) element;
5553

54+
/*
55+
* We check that twice to skip invalid annotated elements
56+
*/
57+
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(executableElement, validatedElements, valid);
58+
5659
validatorHelper.returnTypeIsNotVoid(executableElement, valid);
5760

5861
validatorHelper.isPublic(element, valid);

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/validation/SubscribeValidator.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ public String getTarget() {
4343
@Override
4444
public boolean validate(Element element, AnnotationElements validatedElements) {
4545

46-
if (annotationHelper.enclosingElementIsGenerated(element)) {
46+
if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) {
4747
return false;
4848
}
4949

5050
IsValid valid = new IsValid();
5151

52-
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(element, validatedElements, valid);
53-
5452
ExecutableElement executableElement = (ExecutableElement) element;
5553

54+
/*
55+
* We check that twice to skip invalid annotated elements
56+
*/
57+
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(executableElement, validatedElements, valid);
58+
5659
validatorHelper.returnTypeIsVoid(executableElement, valid);
5760

5861
validatorHelper.isPublic(element, valid);

0 commit comments

Comments
 (0)