Skip to content

Commit

Permalink
BasicAnnoTests doesn't handle multiple annotations at the same position
Browse files Browse the repository at this point in the history
  • Loading branch information
cushon committed Nov 11, 2024
1 parent 7a7d912 commit a968404
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ public Void scan(Element elem, Void ignore) {
*/
class TestTypeScanner extends TypeScanner<Void, Void> {
Element elem;
NavigableMap<Integer, AnnotationMirror> toBeFound;
NavigableMap<Integer, List<AnnotationMirror>> toBeFound;
int count = 0;
Set<TypeMirror> seen = new HashSet<>();

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

NavigableMap<Integer, AnnotationMirror> testByPos = new TreeMap<>();
NavigableMap<Integer, List<AnnotationMirror>> testByPos = new TreeMap<>();
for (AnnotationMirror test : tests) {
for (int pos : getPosn(test)) {
testByPos.put(pos, test);
testByPos.computeIfAbsent(pos, ArrayList::new).add(test);
}
}
this.toBeFound = testByPos;
Expand All @@ -171,17 +171,18 @@ Void scan(TypeMirror t, Void ignore) {
out.println("scan " + count + ": " + t);
if (toBeFound.size() > 0) {
if (toBeFound.firstKey().equals(count)) {
AnnotationMirror test = toBeFound.pollFirstEntry().getValue();
String annoType = getAnnoType(test);
AnnotationMirror anno = getAnnotation(t, annoType);
if (anno == null) {
error(elem, "annotation not found on " + count + ": " + t);
} else {
String v = getValue(anno, "value").toString();
if (v.equals(getExpect(test))) {
out.println("found " + anno + " as expected");
for (AnnotationMirror test : toBeFound.pollFirstEntry().getValue()) {
String annoType = getAnnoType(test);
AnnotationMirror anno = getAnnotation(t, annoType);
if (anno == null) {
error(elem, "annotation not found on " + count + ": " + t);
} else {
error(elem, "Unexpected value: " + v + ", expected: " + getExpect(test));
String v = getValue(anno, "value").toString();
if (v.equals(getExpect(test))) {
out.println("found " + anno + " as expected");
} else {
error(elem, "Unexpected value: " + v + ", expected: " + getExpect(test));
}
}
}
} else if (count > toBeFound.firstKey()) {
Expand Down

0 comments on commit a968404

Please sign in to comment.