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

changeset 2427
a3ad6e2ede44
parent 2390
b06c2db45ddb
child 2525
2eb010b6cb22
child 2717
11743872bfc9
equal deleted inserted replaced
2426:829f01e7f732 2427:a3ad6e2ede44
777 } 777 }
778 } 778 }
779 779
780 @Override 780 @Override
781 public List<Attribute.Compound> getAnnotationMirrors() { 781 public List<Attribute.Compound> getAnnotationMirrors() {
782 return onlyTypeVariableAnnotations(owner.getRawTypeAttributes()); 782 // Declaration annotations on type variables are stored in type attributes
783 } 783 // on the owner of the TypeVariableSymbol
784 784 List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes();
785 private List<Attribute.Compound> onlyTypeVariableAnnotations( 785 int index = owner.getTypeParameters().indexOf(this);
786 List<Attribute.TypeCompound> candidates) {
787 // Declaration annotations on TypeParameters are stored in type attributes
788 List<Attribute.Compound> res = List.nil(); 786 List<Attribute.Compound> res = List.nil();
789 for (Attribute.TypeCompound a : candidates) { 787 for (Attribute.TypeCompound a : candidates) {
790 if (a.position.type == TargetType.CLASS_TYPE_PARAMETER || 788 if (isCurrentSymbolsAnnotation(a, index))
791 a.position.type == TargetType.METHOD_TYPE_PARAMETER)
792 res = res.prepend(a); 789 res = res.prepend(a);
793 } 790 }
794 791
795 return res = res.reverse(); 792 return res.reverse();
796 } 793 }
797
798
799 794
800 // Helper to getAnnotation[s] 795 // Helper to getAnnotation[s]
801 @Override 796 @Override
802 public <A extends Annotation> Attribute.Compound getAttribute(Class<A> annoType) { 797 public <A extends Annotation> Attribute.Compound getAttribute(Class<A> annoType) {
803
804 String name = annoType.getName(); 798 String name = annoType.getName();
805 799
806 // Declaration annotations on type variables are stored in type attributes 800 // Declaration annotations on type variables are stored in type attributes
807 // on the owner of the TypeVariableSymbol 801 // on the owner of the TypeVariableSymbol
808 List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); 802 List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes();
803 int index = owner.getTypeParameters().indexOf(this);
809 for (Attribute.TypeCompound anno : candidates) 804 for (Attribute.TypeCompound anno : candidates)
810 if (anno.position.type == TargetType.CLASS_TYPE_PARAMETER || 805 if (isCurrentSymbolsAnnotation(anno, index) &&
811 anno.position.type == TargetType.METHOD_TYPE_PARAMETER) 806 name.contentEquals(anno.type.tsym.flatName()))
812 if (name.contentEquals(anno.type.tsym.flatName())) 807 return anno;
813 return anno;
814 808
815 return null; 809 return null;
816 } 810 }
817 811 //where:
812 boolean isCurrentSymbolsAnnotation(Attribute.TypeCompound anno, int index) {
813 return (anno.position.type == TargetType.CLASS_TYPE_PARAMETER ||
814 anno.position.type == TargetType.METHOD_TYPE_PARAMETER) &&
815 anno.position.parameter_index == index;
816 }
818 817
819 818
820 @Override 819 @Override
821 public <R, P> R accept(ElementVisitor<R, P> v, P p) { 820 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
822 return v.visitTypeParameter(this, p); 821 return v.visitTypeParameter(this, p);

mercurial