src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java

Print this page
rev 224 : 6498938: Faulty comparison of TypeMirror objects in getElementsAnnotatedWith implementation
Reviewed-by: jjg

*** 1,7 **** /* ! * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this --- 1,7 ---- /* ! * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this
*** 109,118 **** --- 109,119 ---- * @return the elements annotated with the given annotation type, * or an empty set if there are none */ public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) { Set<Element> result = Collections.emptySet(); + Types typeUtil = processingEnv.getTypeUtils(); if (a.getKind() != ElementKind.ANNOTATION_TYPE) throw new IllegalArgumentException(NOT_AN_ANNOTATION_TYPE + a); DeclaredType annotationTypeElement; TypeMirror tm = a.asType();
*** 120,130 **** annotationTypeElement = (DeclaredType) a.asType(); else throw new AssertionError("Bad implementation type for " + tm); ElementScanner6<Set<Element>, DeclaredType> scanner = ! new AnnotationSetScanner(result); for (Element element : rootElements) result = scanner.scan(element, annotationTypeElement); return result; --- 121,131 ---- annotationTypeElement = (DeclaredType) a.asType(); else throw new AssertionError("Bad implementation type for " + tm); ElementScanner6<Set<Element>, DeclaredType> scanner = ! new AnnotationSetScanner(result, typeUtil); for (Element element : rootElements) result = scanner.scan(element, annotationTypeElement); return result;
*** 133,153 **** // Could be written as a local class inside getElementsAnnotatedWith private class AnnotationSetScanner extends ElementScanner6<Set<Element>, DeclaredType> { // Insertion-order preserving set Set<Element> annotatedElements = new LinkedHashSet<Element>(); ! AnnotationSetScanner(Set<Element> defaultSet) { super(defaultSet); } @Override public Set<Element> scan(Element e, DeclaredType p) { java.util.List<? extends AnnotationMirror> annotationMirrors = processingEnv.getElementUtils().getAllAnnotationMirrors(e); for (AnnotationMirror annotationMirror : annotationMirrors) { ! if (annotationMirror.getAnnotationType().equals(p)) annotatedElements.add(e); } e.accept(this, p); return annotatedElements; } --- 134,156 ---- // Could be written as a local class inside getElementsAnnotatedWith private class AnnotationSetScanner extends ElementScanner6<Set<Element>, DeclaredType> { // Insertion-order preserving set Set<Element> annotatedElements = new LinkedHashSet<Element>(); + Types typeUtil; ! AnnotationSetScanner(Set<Element> defaultSet, Types typeUtil) { super(defaultSet); + this.typeUtil = typeUtil; } @Override public Set<Element> scan(Element e, DeclaredType p) { java.util.List<? extends AnnotationMirror> annotationMirrors = processingEnv.getElementUtils().getAllAnnotationMirrors(e); for (AnnotationMirror annotationMirror : annotationMirrors) { ! if (typeUtil.isSameType(annotationMirror.getAnnotationType(), p)) annotatedElements.add(e); } e.accept(this, p); return annotatedElements; }