Skip to content

Commit

Permalink
[fixes #3761] Update annotation value index
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Oct 19, 2024
1 parent 4aa58fb commit 5caea32
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/core/lombok/core/AnnotationValues.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2022 The Project Lombok Authors.
* Copyright (C) 2009-2024 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -182,6 +182,7 @@ public List<String> getAsStringList(String methodName) {
"I can't make sense of this annotation value. Try using a fully qualified literal.", idx);
}
out.add((String) result);
idx++;
}

return Collections.unmodifiableList(out);
Expand Down
12 changes: 9 additions & 3 deletions test/core/src/lombok/CompilerMessageMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public class CompilerMessageMatcher {
/** Line Number (starting at 1) */
private final List<Integer> lineNumbers = new ArrayList<Integer>();
private final List<Long> positions = new ArrayList<Long>();
private final List<List<String>> messages = new ArrayList<List<String>>();
private boolean optional;

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

@Override public String toString() {
StringBuilder out = new StringBuilder();
for (int i = 0; i < lineNumbers.size(); i++) {
out.append(lineNumbers.get(i)).append(" ");
out.append(lineNumbers.get(i));
if (positions.get(i) != null) out.append(":").append(positions.get(i));
out.append(" ");
for (String part : messages.get(i)) out.append(part).append(" ");
if (out.length() > 0) out.setLength(out.length() - 1);
out.append(" |||| ");
Expand All @@ -68,6 +72,7 @@ public boolean matches(CompilerMessage message) {
outer:
for (int i = 0; i < lineNumbers.size(); i++) {
if (message.getLine() != lineNumbers.get(i)) continue;
if (positions.get(i) != null && !positions.get(i).equals(message.getPosition())) continue;
for (String token : messages.get(i)) {
if (!message.getMessage().contains(token)) continue outer;
}
Expand All @@ -87,7 +92,7 @@ public static List<CompilerMessageMatcher> readAll(InputStream rawIn) throws IOE
return out;
}

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

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

return cmm;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// skip-compare-contents
@lombok.EqualsAndHashCode(of={"x", Const.A})
final class EqualsAndHashCodeErrorOf {
int x;
}

@lombok.EqualsAndHashCode(exclude={"x", Const.A})
final class EqualsAndHashCodeErrorExclude {
int x;
}

class Const {
static final String A = "A";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2:60 You must use constant literals in lombok annotations; they cannot be references to (static) fields.
7:160 You must use constant literals in lombok annotations; they cannot be references to (static) fields.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2:60 You must use constant literals in lombok annotations; they cannot be references to (static) fields.
7:160 You must use constant literals in lombok annotations; they cannot be references to (static) fields.

0 comments on commit 5caea32

Please sign in to comment.