Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ignoring Otto annotations when used separately from AA annotated classes

  • Loading branch information...
commit 26199a5e7be88420d568b34d20ac8da2d0af0948 1 parent e22ca8e
@pyricau pyricau authored
View
15 ...ions/androidannotations/src/main/java/org/androidannotations/helper/AnnotationHelper.java
@@ -16,6 +16,7 @@
package org.androidannotations.helper;
import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX;
+import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_COMPONENT_ANNOTATIONS;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
@@ -382,4 +383,18 @@ public boolean enclosingElementIsGenerated(Element element) {
return enclosingElement.getSimpleName().toString().endsWith(GENERATION_SUFFIX);
}
+ public boolean enclosingElementHasEnhancedComponentAnnotation(Element element) {
+ Element enclosingElement = element.getEnclosingElement();
+ return hasOneOfClassAnnotations(enclosingElement, VALID_ENHANCED_COMPONENT_ANNOTATIONS);
+ }
+
+ public boolean hasOneOfClassAnnotations(Element element, List<Class<? extends Annotation>> validAnnotations) {
+ for (Class<? extends Annotation> validAnnotation : validAnnotations) {
+ if (element.getAnnotation(validAnnotation) != null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
View
21 ...ations/androidannotations/src/main/java/org/androidannotations/helper/ModelConstants.java
@@ -15,12 +15,33 @@
*/
package org.androidannotations.helper;
+import static java.util.Arrays.asList;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import org.androidannotations.annotations.EActivity;
+import org.androidannotations.annotations.EApplication;
+import org.androidannotations.annotations.EBean;
+import org.androidannotations.annotations.EFragment;
+import org.androidannotations.annotations.EProvider;
+import org.androidannotations.annotations.EReceiver;
+import org.androidannotations.annotations.EService;
+import org.androidannotations.annotations.EView;
+import org.androidannotations.annotations.EViewGroup;
+
public abstract class ModelConstants {
public static final String GENERATION_SUFFIX = "_";
public static final String TRACE_OPTION = "trace";
+ @SuppressWarnings("unchecked")
+ public static final List<Class<? extends Annotation>> VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS = asList(EActivity.class, EViewGroup.class, EView.class, EBean.class, EFragment.class);
+
+ @SuppressWarnings("unchecked")
+ 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);
+
private ModelConstants() {
}
View
14 ...tions/androidannotations/src/main/java/org/androidannotations/helper/ValidatorHelper.java
@@ -25,6 +25,8 @@
import static org.androidannotations.helper.CanonicalNameConstants.HTTP_MESSAGE_CONVERTER;
import static org.androidannotations.helper.CanonicalNameConstants.INTERNET_PERMISSION;
import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX;
+import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_COMPONENT_ANNOTATIONS;
+import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
@@ -49,14 +51,8 @@
import javax.lang.model.util.Elements;
import org.androidannotations.annotations.EActivity;
-import org.androidannotations.annotations.EApplication;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.EFragment;
-import org.androidannotations.annotations.EProvider;
-import org.androidannotations.annotations.EReceiver;
-import org.androidannotations.annotations.EService;
-import org.androidannotations.annotations.EView;
-import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.Trace;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.rest.Delete;
@@ -91,12 +87,6 @@
private static final Collection<Integer> VALID_LOG_LEVELS = Arrays.asList(LOG_VERBOSE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR);
- @SuppressWarnings("unchecked")
- private static final List<Class<? extends Annotation>> VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS = asList(EActivity.class, EViewGroup.class, EView.class, EBean.class, EFragment.class);
-
- @SuppressWarnings("unchecked")
- 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);
-
protected final TargetAnnotationHelper annotationHelper;
public ValidatorHelper(TargetAnnotationHelper targetAnnotationHelper) {
View
9 .../androidannotations/src/main/java/org/androidannotations/validation/ProduceValidator.java
@@ -43,16 +43,19 @@ public String getTarget() {
@Override
public boolean validate(Element element, AnnotationElements validatedElements) {
- if (annotationHelper.enclosingElementIsGenerated(element)) {
+ if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) {
return false;
}
IsValid valid = new IsValid();
- validatorHelper.enclosingElementHasEnhancedComponentAnnotation(element, validatedElements, valid);
-
ExecutableElement executableElement = (ExecutableElement) element;
+ /*
+ * We check that twice to skip invalid annotated elements
+ */
+ validatorHelper.enclosingElementHasEnhancedComponentAnnotation(executableElement, validatedElements, valid);
+
validatorHelper.returnTypeIsNotVoid(executableElement, valid);
validatorHelper.isPublic(element, valid);
View
9 ...ndroidannotations/src/main/java/org/androidannotations/validation/SubscribeValidator.java
@@ -43,16 +43,19 @@ public String getTarget() {
@Override
public boolean validate(Element element, AnnotationElements validatedElements) {
- if (annotationHelper.enclosingElementIsGenerated(element)) {
+ if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) {
return false;
}
IsValid valid = new IsValid();
- validatorHelper.enclosingElementHasEnhancedComponentAnnotation(element, validatedElements, valid);
-
ExecutableElement executableElement = (ExecutableElement) element;
+ /*
+ * We check that twice to skip invalid annotated elements
+ */
+ validatorHelper.enclosingElementHasEnhancedComponentAnnotation(executableElement, validatedElements, valid);
+
validatorHelper.returnTypeIsVoid(executableElement, valid);
validatorHelper.isPublic(element, valid);
Please sign in to comment.
Something went wrong with that request. Please try again.