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 +1,7 @@
/*
- * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * 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,10 +109,11 @@
* @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,11 +121,11 @@
annotationTypeElement = (DeclaredType) a.asType();
else
throw new AssertionError("Bad implementation type for " + tm);
ElementScanner6<Set<Element>, DeclaredType> scanner =
- new AnnotationSetScanner(result);
+ new AnnotationSetScanner(result, typeUtil);
for (Element element : rootElements)
result = scanner.scan(element, annotationTypeElement);
return result;
@@ -133,21 +134,23 @@
// 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) {
+ 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 (annotationMirror.getAnnotationType().equals(p))
+ if (typeUtil.isSameType(annotationMirror.getAnnotationType(), p))
annotatedElements.add(e);
}
e.accept(this, p);
return annotatedElements;
}