Skip to content

Commit 9eb9ce4

Browse files
author
SendaoYan
committed
8343882: BasicAnnoTests doesn't handle multiple annotations at the same position
Backport-of: d562d3c
1 parent f4bef2f commit 9eb9ce4

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,18 @@ public Void scan(Element elem, Void ignore) {
139139
*/
140140
class TestTypeScanner extends TypeScanner<Void, Void> {
141141
Element elem;
142-
NavigableMap<Integer, AnnotationMirror> toBeFound;
142+
NavigableMap<Integer, List<AnnotationMirror>> toBeFound;
143143
int count = 0;
144144
Set<TypeMirror> seen = new HashSet<>();
145145

146146
TestTypeScanner(Element elem, List<AnnotationMirror> tests, Types types) {
147147
super(types);
148148
this.elem = elem;
149149

150-
NavigableMap<Integer, AnnotationMirror> testByPos = new TreeMap<>();
150+
NavigableMap<Integer, List<AnnotationMirror>> testByPos = new TreeMap<>();
151151
for (AnnotationMirror test : tests) {
152152
for (int pos : getPosn(test)) {
153-
testByPos.put(pos, test);
153+
testByPos.computeIfAbsent(pos, ArrayList::new).add(test);
154154
}
155155
}
156156
this.toBeFound = testByPos;
@@ -172,17 +172,18 @@ Void scan(TypeMirror t, Void ignore) {
172172
out.println("scan " + count + ": " + t);
173173
if (toBeFound.size() > 0) {
174174
if (toBeFound.firstKey().equals(count)) {
175-
AnnotationMirror test = toBeFound.pollFirstEntry().getValue();
176-
String annoType = getAnnoType(test);
177-
AnnotationMirror anno = getAnnotation(t, annoType);
178-
if (anno == null) {
179-
error(elem, "annotation not found on " + count + ": " + t);
180-
} else {
181-
String v = getValue(anno, "value").toString();
182-
if (v.equals(getExpect(test))) {
183-
out.println("found " + anno + " as expected");
175+
for (AnnotationMirror test : toBeFound.pollFirstEntry().getValue()) {
176+
String annoType = getAnnoType(test);
177+
AnnotationMirror anno = getAnnotation(t, annoType);
178+
if (anno == null) {
179+
error(elem, "annotation not found on " + count + ": " + t);
184180
} else {
185-
error(elem, "Unexpected value: " + v + ", expected: " + getExpect(test));
181+
String v = getValue(anno, "value").toString();
182+
if (v.equals(getExpect(test))) {
183+
out.println("found " + anno + " as expected");
184+
} else {
185+
error(elem, "Unexpected value: " + v + ", expected: " + getExpect(test));
186+
}
186187
}
187188
}
188189
} else if (count > toBeFound.firstKey()) {

0 commit comments

Comments
 (0)