From 5caea325100c2b76dee6a5d63c1328523a9da671 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Sat, 19 Oct 2024 11:49:29 +0200 Subject: [PATCH] [fixes #3761] Update annotation value index --- src/core/lombok/core/AnnotationValues.java | 3 ++- test/core/src/lombok/CompilerMessageMatcher.java | 12 +++++++++--- .../before/EqualsAndHashCodeOfAndExcludeError.java | 14 ++++++++++++++ ...qualsAndHashCodeOfAndExcludeError.java.messages | 2 ++ ...qualsAndHashCodeOfAndExcludeError.java.messages | 2 ++ 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/transform/resource/before/EqualsAndHashCodeOfAndExcludeError.java create mode 100644 test/transform/resource/messages-delombok/EqualsAndHashCodeOfAndExcludeError.java.messages create mode 100644 test/transform/resource/messages-ecj/EqualsAndHashCodeOfAndExcludeError.java.messages diff --git a/src/core/lombok/core/AnnotationValues.java b/src/core/lombok/core/AnnotationValues.java index 390e9b71b3..19026ca51a 100644 --- a/src/core/lombok/core/AnnotationValues.java +++ b/src/core/lombok/core/AnnotationValues.java @@ -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 @@ -182,6 +182,7 @@ public List 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); diff --git a/test/core/src/lombok/CompilerMessageMatcher.java b/test/core/src/lombok/CompilerMessageMatcher.java index 923b45e623..76eb2ee92c 100644 --- a/test/core/src/lombok/CompilerMessageMatcher.java +++ b/test/core/src/lombok/CompilerMessageMatcher.java @@ -36,6 +36,7 @@ public class CompilerMessageMatcher { /** Line Number (starting at 1) */ private final List lineNumbers = new ArrayList(); + private final List positions = new ArrayList(); private final List> messages = new ArrayList>(); private boolean optional; @@ -48,6 +49,7 @@ 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; } @@ -55,7 +57,9 @@ public static CompilerMessageMatcher asCompilerMessageMatcher(CompilerMessage me @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(" |||| "); @@ -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; } @@ -87,7 +92,7 @@ public static List 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(); @@ -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; diff --git a/test/transform/resource/before/EqualsAndHashCodeOfAndExcludeError.java b/test/transform/resource/before/EqualsAndHashCodeOfAndExcludeError.java new file mode 100644 index 0000000000..cbfb135568 --- /dev/null +++ b/test/transform/resource/before/EqualsAndHashCodeOfAndExcludeError.java @@ -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"; +} \ No newline at end of file diff --git a/test/transform/resource/messages-delombok/EqualsAndHashCodeOfAndExcludeError.java.messages b/test/transform/resource/messages-delombok/EqualsAndHashCodeOfAndExcludeError.java.messages new file mode 100644 index 0000000000..18e7a32b49 --- /dev/null +++ b/test/transform/resource/messages-delombok/EqualsAndHashCodeOfAndExcludeError.java.messages @@ -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. \ No newline at end of file diff --git a/test/transform/resource/messages-ecj/EqualsAndHashCodeOfAndExcludeError.java.messages b/test/transform/resource/messages-ecj/EqualsAndHashCodeOfAndExcludeError.java.messages new file mode 100644 index 0000000000..18e7a32b49 --- /dev/null +++ b/test/transform/resource/messages-ecj/EqualsAndHashCodeOfAndExcludeError.java.messages @@ -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. \ No newline at end of file