Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,41 @@
*/
package org.androidannotations.helper;

import static com.sun.codemodel.JExpr._new;
import static com.sun.codemodel.JExpr.lit;
import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX;

import java.io.StringWriter;
import java.lang.annotation.Annotation;
import java.lang.annotation.Inherited;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.WildcardType;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Types;

import org.androidannotations.annotations.EBean;
import org.androidannotations.holder.EBeanHolder;
import org.androidannotations.holder.EComponentHolder;
import org.androidannotations.holder.GeneratedClassHolder;

import com.sun.codemodel.JAnnotatable;
import com.sun.codemodel.JAnnotationUse;
import com.sun.codemodel.JBlock;
Expand All @@ -32,38 +67,6 @@
import com.sun.codemodel.JSuperWildcard;
import com.sun.codemodel.JType;
import com.sun.codemodel.JVar;
import org.androidannotations.annotations.EBean;
import org.androidannotations.holder.EBeanHolder;
import org.androidannotations.holder.EComponentHolder;
import org.androidannotations.holder.GeneratedClassHolder;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.WildcardType;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Types;
import java.io.StringWriter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static com.sun.codemodel.JExpr._new;
import static com.sun.codemodel.JExpr.lit;
import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX;

public class APTCodeModelHelper {

Expand Down Expand Up @@ -249,9 +252,11 @@ private void addParamToMethod(JMethod method, VariableElement parameter, int mod

public void addNonAAAnotations(JAnnotatable annotatable, List<? extends AnnotationMirror> annotationMirrors, GeneratedClassHolder holder) {
for (AnnotationMirror annotationMirror : annotationMirrors) {
JClass annotationClass = typeMirrorToJClass(annotationMirror.getAnnotationType(), holder);
if (!annotationClass.fullName().startsWith("org.androidannotations")) {
addAnnotation(annotatable, annotationMirror, holder);
if (annotationMirror.getAnnotationType().asElement().getAnnotation(Inherited.class) == null) {
JClass annotationClass = typeMirrorToJClass(annotationMirror.getAnnotationType(), holder);
if (!annotationClass.fullName().startsWith("org.androidannotations")) {
addAnnotation(annotatable, annotationMirror, holder);
}
}
}
}
Expand Down Expand Up @@ -402,7 +407,7 @@ public JDefinedClass createDelegatingAnonymousRunnableClass(EComponentHolder hol
/**
* Gets all of the methods of the class and includes the methods of any
* implemented interfaces.
*
*
* @param typeElement
* @return full list of methods.
*/
Expand Down Expand Up @@ -508,7 +513,7 @@ public JExpression litObject(Object o) {
}
}

//TODO it would be nice to cache the result map for better performance
// TODO it would be nice to cache the result map for better performance
public TypeMirror getActualType(Element element, GeneratedClassHolder holder) {
Types types = holder.processingEnvironment().getTypeUtils();
DeclaredType typeMirror = (DeclaredType) element.getEnclosingElement().asType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ public void testOverrideDoesNotAddedTwice() {

assertGeneratedClassDoesNotContain(toGeneratedFile(HasOtherAnnotations.class), methodSignature);
}

@Test
public void testInheritedAnnotationsNotCopied() {
compileFiles(HasOtherAnnotations.class);

String[] annotation = { "@RunWith(Runner.class)" };

assertGeneratedClassDoesNotContain(toGeneratedFile(HasOtherAnnotations.class), annotation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.Trace;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;

import dalvik.annotation.TestTargetClass;

@RunWith(Runner.class)
@EBean
@XmlType
@TestTargetClass(String.class)
Expand Down