src/share/classes/com/sun/tools/javac/code/Symbol.java

changeset 2427
a3ad6e2ede44
parent 2390
b06c2db45ddb
child 2525
2eb010b6cb22
child 2717
11743872bfc9
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Jun 19 12:22:39 2014 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Jun 18 10:44:16 2014 +0200
     1.3 @@ -779,42 +779,41 @@
     1.4  
     1.5          @Override
     1.6          public List<Attribute.Compound> getAnnotationMirrors() {
     1.7 -            return onlyTypeVariableAnnotations(owner.getRawTypeAttributes());
     1.8 -        }
     1.9 -
    1.10 -        private List<Attribute.Compound> onlyTypeVariableAnnotations(
    1.11 -                List<Attribute.TypeCompound> candidates) {
    1.12 -            // Declaration annotations on TypeParameters are stored in type attributes
    1.13 +            // Declaration annotations on type variables are stored in type attributes
    1.14 +            // on the owner of the TypeVariableSymbol
    1.15 +            List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes();
    1.16 +            int index = owner.getTypeParameters().indexOf(this);
    1.17              List<Attribute.Compound> res = List.nil();
    1.18              for (Attribute.TypeCompound a : candidates) {
    1.19 -                if (a.position.type == TargetType.CLASS_TYPE_PARAMETER ||
    1.20 -                    a.position.type == TargetType.METHOD_TYPE_PARAMETER)
    1.21 +                if (isCurrentSymbolsAnnotation(a, index))
    1.22                      res = res.prepend(a);
    1.23              }
    1.24  
    1.25 -            return res = res.reverse();
    1.26 +            return res.reverse();
    1.27          }
    1.28  
    1.29 -
    1.30 -
    1.31          // Helper to getAnnotation[s]
    1.32          @Override
    1.33          public <A extends Annotation> Attribute.Compound getAttribute(Class<A> annoType) {
    1.34 -
    1.35              String name = annoType.getName();
    1.36  
    1.37              // Declaration annotations on type variables are stored in type attributes
    1.38              // on the owner of the TypeVariableSymbol
    1.39              List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes();
    1.40 +            int index = owner.getTypeParameters().indexOf(this);
    1.41              for (Attribute.TypeCompound anno : candidates)
    1.42 -                if (anno.position.type == TargetType.CLASS_TYPE_PARAMETER ||
    1.43 -                        anno.position.type == TargetType.METHOD_TYPE_PARAMETER)
    1.44 -                    if (name.contentEquals(anno.type.tsym.flatName()))
    1.45 -                        return anno;
    1.46 +                if (isCurrentSymbolsAnnotation(anno, index) &&
    1.47 +                    name.contentEquals(anno.type.tsym.flatName()))
    1.48 +                    return anno;
    1.49  
    1.50              return null;
    1.51          }
    1.52 -
    1.53 +            //where:
    1.54 +            boolean isCurrentSymbolsAnnotation(Attribute.TypeCompound anno, int index) {
    1.55 +                return (anno.position.type == TargetType.CLASS_TYPE_PARAMETER ||
    1.56 +                        anno.position.type == TargetType.METHOD_TYPE_PARAMETER) &&
    1.57 +                       anno.position.parameter_index == index;
    1.58 +            }
    1.59  
    1.60  
    1.61          @Override

mercurial