Skip to content

Commit 5caea32

Browse files
committed
[fixes #3761] Update annotation value index
1 parent 4aa58fb commit 5caea32

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

src/core/lombok/core/AnnotationValues.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009-2022 The Project Lombok Authors.
2+
* Copyright (C) 2009-2024 The Project Lombok Authors.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -182,6 +182,7 @@ public List<String> getAsStringList(String methodName) {
182182
"I can't make sense of this annotation value. Try using a fully qualified literal.", idx);
183183
}
184184
out.add((String) result);
185+
idx++;
185186
}
186187

187188
return Collections.unmodifiableList(out);

test/core/src/lombok/CompilerMessageMatcher.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
public class CompilerMessageMatcher {
3737
/** Line Number (starting at 1) */
3838
private final List<Integer> lineNumbers = new ArrayList<Integer>();
39+
private final List<Long> positions = new ArrayList<Long>();
3940
private final List<List<String>> messages = new ArrayList<List<String>>();
4041
private boolean optional;
4142

@@ -48,14 +49,17 @@ public boolean isOptional() {
4849
public static CompilerMessageMatcher asCompilerMessageMatcher(CompilerMessage message) {
4950
CompilerMessageMatcher cmm = new CompilerMessageMatcher();
5051
cmm.lineNumbers.add((int) message.getLine());
52+
cmm.positions.add(message.getPosition());
5153
cmm.messages.add(Arrays.asList(message.getMessage().split("\\s+")));
5254
return cmm;
5355
}
5456

5557
@Override public String toString() {
5658
StringBuilder out = new StringBuilder();
5759
for (int i = 0; i < lineNumbers.size(); i++) {
58-
out.append(lineNumbers.get(i)).append(" ");
60+
out.append(lineNumbers.get(i));
61+
if (positions.get(i) != null) out.append(":").append(positions.get(i));
62+
out.append(" ");
5963
for (String part : messages.get(i)) out.append(part).append(" ");
6064
if (out.length() > 0) out.setLength(out.length() - 1);
6165
out.append(" |||| ");
@@ -68,6 +72,7 @@ public boolean matches(CompilerMessage message) {
6872
outer:
6973
for (int i = 0; i < lineNumbers.size(); i++) {
7074
if (message.getLine() != lineNumbers.get(i)) continue;
75+
if (positions.get(i) != null && !positions.get(i).equals(message.getPosition())) continue;
7176
for (String token : messages.get(i)) {
7277
if (!message.getMessage().contains(token)) continue outer;
7378
}
@@ -87,7 +92,7 @@ public static List<CompilerMessageMatcher> readAll(InputStream rawIn) throws IOE
8792
return out;
8893
}
8994

90-
private static final Pattern PATTERN = Pattern.compile("^(-?\\d+) (.*)$");
95+
private static final Pattern PATTERN = Pattern.compile("^(-?\\d+)(?::(\\d+))? (.*)$");
9196

9297
private static CompilerMessageMatcher read(String line) {
9398
line = line.trim();
@@ -107,7 +112,8 @@ private static CompilerMessageMatcher read(String line) {
107112
Matcher m = PATTERN.matcher(part);
108113
if (!m.matches()) throw new IllegalArgumentException("Typo in test file: " + line);
109114
cmm.lineNumbers.add(Integer.parseInt(m.group(1)));
110-
cmm.messages.add(Arrays.asList(m.group(2).split("\\s+")));
115+
cmm.positions.add(m.group(2) != null ? Long.parseLong(m.group(2)) : null);
116+
cmm.messages.add(Arrays.asList(m.group(3).split("\\s+")));
111117
}
112118

113119
return cmm;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// skip-compare-contents
2+
@lombok.EqualsAndHashCode(of={"x", Const.A})
3+
final class EqualsAndHashCodeErrorOf {
4+
int x;
5+
}
6+
7+
@lombok.EqualsAndHashCode(exclude={"x", Const.A})
8+
final class EqualsAndHashCodeErrorExclude {
9+
int x;
10+
}
11+
12+
class Const {
13+
static final String A = "A";
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2:60 You must use constant literals in lombok annotations; they cannot be references to (static) fields.
2+
7:160 You must use constant literals in lombok annotations; they cannot be references to (static) fields.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2:60 You must use constant literals in lombok annotations; they cannot be references to (static) fields.
2+
7:160 You must use constant literals in lombok annotations; they cannot be references to (static) fields.

0 commit comments

Comments
 (0)