src/share/classes/com/sun/tools/javac/model/JavacAnnoConstructs.java

changeset 1709
bae8387d16aa
parent 1645
97f6839673d6
child 1918
a218f7befd55
     1.1 --- a/src/share/classes/com/sun/tools/javac/model/JavacAnnoConstructs.java	Fri Apr 19 11:10:40 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/model/JavacAnnoConstructs.java	Mon Apr 22 10:24:19 2013 +0200
     1.3 @@ -33,10 +33,13 @@
     1.4  import com.sun.tools.javac.code.Kinds;
     1.5  import com.sun.tools.javac.code.Symbol;
     1.6  import com.sun.tools.javac.code.Symbol.ClassSymbol;
     1.7 +import com.sun.tools.javac.code.Symbol.TypeVariableSymbol;
     1.8 +import com.sun.tools.javac.code.TargetType;
     1.9  import com.sun.tools.javac.code.Type;
    1.10  import com.sun.tools.javac.code.Type.AnnotatedType;
    1.11  import com.sun.tools.javac.util.ListBuffer;
    1.12  import static com.sun.tools.javac.code.TypeTag.CLASS;
    1.13 +import com.sun.tools.javac.util.List;
    1.14  
    1.15  /**
    1.16   * Utility methods for operating on annotated constructs.
    1.17 @@ -61,8 +64,12 @@
    1.18              throw new IllegalArgumentException("Not an annotation type: "
    1.19                                                 + annoType);
    1.20          Attribute.Compound c;
    1.21 -        if (annotated.kind == Kinds.TYP && annotated instanceof ClassSymbol) {
    1.22 +        if (annotated.kind == Kinds.TYP &&
    1.23 +                annotated instanceof ClassSymbol) {
    1.24              c = getAttributeOnClass((ClassSymbol)annotated, annoType);
    1.25 +        } else if (annotated.kind == Kinds.TYP &&
    1.26 +                   annotated instanceof TypeVariableSymbol) {
    1.27 +            c = getAttributeOnTypeVariable((TypeVariableSymbol)annotated, annoType);
    1.28          } else {
    1.29              c = getAttribute(annotated, annoType);
    1.30          }
    1.31 @@ -83,6 +90,24 @@
    1.32      }
    1.33  
    1.34      // Helper to getAnnotation[s]
    1.35 +    private static <A extends Annotation> Attribute.Compound
    1.36 +            getAttributeOnTypeVariable(TypeVariableSymbol annotated, Class<A> annoType) {
    1.37 +        String name = annoType.getName();
    1.38 +
    1.39 +        // Declaration annotations on type variables are stored in type attributes
    1.40 +        // on the owner of the TypeVariableSymbol
    1.41 +        List<Attribute.Compound> res = List.nil();
    1.42 +        List<Attribute.TypeCompound> candidates = annotated.owner.getRawTypeAttributes();
    1.43 +        for (Attribute.TypeCompound anno : candidates)
    1.44 +            if (anno.position.type == TargetType.CLASS_TYPE_PARAMETER ||
    1.45 +                    anno.position.type == TargetType.METHOD_TYPE_PARAMETER)
    1.46 +                if (name.equals(anno.type.tsym.flatName().toString()))
    1.47 +                    return anno;
    1.48 +
    1.49 +        return null;
    1.50 +    }
    1.51 +
    1.52 +    // Helper to getAnnotation[s]
    1.53      private static <A extends Annotation> Attribute.Compound getAttributeOnClass(ClassSymbol annotated,
    1.54                                                                  Class<A> annoType) {
    1.55          boolean inherited = annoType.isAnnotationPresent(Inherited.class);

mercurial