From ffeeeee7a57857bc82d0a91422c22b10bf8f7a57 Mon Sep 17 00:00:00 2001 From: mohamedsamehsalah Date: Sun, 30 Jul 2023 15:11:31 +0200 Subject: [PATCH 01/10] Exclude classes annotated with lombok's @Data from `DirectReturn` bug checker While here, add a new Matcher that determines whether a class is annotated with lombok's @Data. --- .../errorprone/bugpatterns/DirectReturn.java | 8 ++++++- .../bugpatterns/DirectReturnTest.java | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java index 212d0b1245..62900529f1 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java @@ -12,6 +12,7 @@ import static com.google.errorprone.matchers.Matchers.staticMethod; import static com.google.errorprone.matchers.Matchers.toType; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; +import static tech.picnic.errorprone.bugpatterns.util.MoreMatchers.isClassAnnotatedWithLombokData; import com.google.auto.service.AutoService; import com.google.common.collect.Streams; @@ -25,6 +26,7 @@ import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.AssignmentTree; import com.sun.source.tree.BlockTree; +import com.sun.source.tree.ClassTree; import com.sun.source.tree.ExpressionStatementTree; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.IdentifierTree; @@ -60,6 +62,8 @@ public final class DirectReturn extends BugChecker implements BlockTreeMatcher { allOf( not(toType(MethodInvocationTree.class, argument(0, isSameType(Class.class.getName())))), staticMethod().onClass("org.mockito.Mockito").namedAnyOf("mock", "spy")); + private static final Matcher IS_CLASS_ANNOTATED_WITH_LOMBOK_DATA = + isClassAnnotatedWithLombokData(); /** Instantiates a new {@link DirectReturn} instance. */ public DirectReturn() {} @@ -67,7 +71,9 @@ public DirectReturn() {} @Override public Description matchBlock(BlockTree tree, VisitorState state) { List statements = tree.getStatements(); - if (statements.size() < 2) { + ClassTree enclosingNode = ASTHelpers.findEnclosingNode(state.getPath(), ClassTree.class); + if (statements.size() < 2 + || IS_CLASS_ANNOTATED_WITH_LOMBOK_DATA.matches(enclosingNode, state)) { return Description.NO_MATCH; } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java index 42e1889414..b51a7da3aa 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java @@ -223,4 +223,26 @@ void replacement() { "}") .doTest(TestMode.TEXT_MATCH); } + + @Test + void excludeClassesAnnotatedWithLombokData() { + BugCheckerRefactoringTestHelper.newInstance(DirectReturn.class, getClass()) + .addInputLines( + "A.java", + "import lombok.Data;", + "", + "@Data", + "public class A {", + " private String field;", + "}") + .addOutputLines( + "A.java", + "import lombok.Data;", + "", + "@Data", + "public class A {", + " private String field;", + "}") + .doTest(TestMode.TEXT_MATCH); + } } From 747af1b8d14351c767cbfea0dfa02bb7bda9e260 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 11 Aug 2023 16:26:30 +0200 Subject: [PATCH 02/10] Suggestions --- .../errorprone/bugpatterns/DirectReturn.java | 7 +--- .../bugpatterns/util/MoreMatchers.java | 4 ++ .../bugpatterns/DirectReturnTest.java | 8 ++-- .../bugpatterns/util/MoreMatchersTest.java | 38 +++++++++++++++++++ 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java index 62900529f1..1f7dec3416 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java @@ -12,7 +12,7 @@ import static com.google.errorprone.matchers.Matchers.staticMethod; import static com.google.errorprone.matchers.Matchers.toType; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; -import static tech.picnic.errorprone.bugpatterns.util.MoreMatchers.isClassAnnotatedWithLombokData; +import static tech.picnic.errorprone.bugpatterns.util.MoreMatchers.HAS_LOMBOK_DATA; import com.google.auto.service.AutoService; import com.google.common.collect.Streams; @@ -62,8 +62,6 @@ public final class DirectReturn extends BugChecker implements BlockTreeMatcher { allOf( not(toType(MethodInvocationTree.class, argument(0, isSameType(Class.class.getName())))), staticMethod().onClass("org.mockito.Mockito").namedAnyOf("mock", "spy")); - private static final Matcher IS_CLASS_ANNOTATED_WITH_LOMBOK_DATA = - isClassAnnotatedWithLombokData(); /** Instantiates a new {@link DirectReturn} instance. */ public DirectReturn() {} @@ -72,8 +70,7 @@ public DirectReturn() {} public Description matchBlock(BlockTree tree, VisitorState state) { List statements = tree.getStatements(); ClassTree enclosingNode = ASTHelpers.findEnclosingNode(state.getPath(), ClassTree.class); - if (statements.size() < 2 - || IS_CLASS_ANNOTATED_WITH_LOMBOK_DATA.matches(enclosingNode, state)) { + if (statements.size() < 2 || HAS_LOMBOK_DATA.matches(enclosingNode, state)) { return Description.NO_MATCH; } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java index eaa683c650..175c828a03 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java @@ -9,6 +9,7 @@ import com.sun.source.tree.AnnotationTree; import com.sun.source.tree.Tree; import com.sun.tools.javac.code.Type; +import com.sun.source.tree.ClassTree; /** * A collection of general-purpose {@link Matcher}s. @@ -16,6 +17,9 @@ *

These methods are additions to the ones found in {@link Matchers}. */ public final class MoreMatchers { + /** Matches classes annotated with Lombok's `@Data` annotation. */ + public static final Matcher HAS_LOMBOK_DATA = Matchers.hasAnnotation("lombok.Data"); + private MoreMatchers() {} /** diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java index b51a7da3aa..319481b241 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java @@ -225,14 +225,16 @@ void replacement() { } @Test - void excludeClassesAnnotatedWithLombokData() { + void ignoreClassesAnnotatedWithLombokData() { BugCheckerRefactoringTestHelper.newInstance(DirectReturn.class, getClass()) + .addInputLines("Data.java", "package lombok;", "public @interface Data {}") + .expectUnchanged() .addInputLines( "A.java", "import lombok.Data;", "", "@Data", - "public class A {", + "class A {", " private String field;", "}") .addOutputLines( @@ -240,7 +242,7 @@ void excludeClassesAnnotatedWithLombokData() { "import lombok.Data;", "", "@Data", - "public class A {", + "class A {", " private String field;", "}") .doTest(TestMode.TEXT_MATCH); diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java index faed5900f3..8a2a64f07e 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java @@ -1,6 +1,7 @@ package tech.picnic.errorprone.bugpatterns.util; import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static tech.picnic.errorprone.bugpatterns.util.MoreMatchers.HAS_LOMBOK_DATA; import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.generic; import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.subOf; import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.type; @@ -11,11 +12,13 @@ import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.bugpatterns.BugChecker.AnnotationTreeMatcher; +import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; import com.google.errorprone.suppliers.Supplier; import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.ClassTree; import com.sun.source.tree.MethodInvocationTree; import com.sun.source.tree.Tree; import org.junit.jupiter.api.Test; @@ -104,6 +107,29 @@ void isSubTypeOfBoundTypeUnknown() { .doTest(); } +@Test + void hasLombokDataAnnotation() { + CompilationTestHelper.newInstance(LombokDataAnnotationMatcher.class, getClass()) + .addSourceLines("Data.java", "package lombok;", "public @interface Data {}") + .addSourceLines( + "A.java", + "import lombok.Data;", + "", + "@Data", + "// BUG: Diagnostic contains:", + "public class A {", + " private String field;", + "", + " static class B { }", + "", + " @Data", + " // BUG: Diagnostic contains:", + " static class C { }", + "}") + .addSourceLines("D.java", "import lombok.Data;", "", "public class D { }") + .doTest(); + } + /** A {@link BugChecker} that delegates to {@link MoreMatchers#hasMetaAnnotation(String)}. */ @BugPattern(summary = "Interacts with `MoreMatchers` for testing purposes", severity = ERROR) public static final class HasMetaAnnotationTestChecker extends BugChecker @@ -130,6 +156,18 @@ public static final class IsSubTypeOfTestChecker extends BugChecker @Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { return DELEGATE.matches(tree, state) ? describeMatch(tree) : Description.NO_MATCH; +} +} + + /** A {@link BugChecker} that delegates to {@link MoreMatchers#HAS_LOMBOK_DATA} . */ + @BugPattern(summary = "Interacts with `MoreMatchers` for testing purposes", severity = ERROR) + public static final class LombokDataAnnotationMatcher extends BugChecker + implements ClassTreeMatcher { + private static final long serialVersionUID = 1L; + + @Override + public Description matchClass(ClassTree tree, VisitorState state) { + return HAS_LOMBOK_DATA.matches(tree, state) ? describeMatch(tree) : Description.NO_MATCH; } } } From 7e649bd9aee0a2fa6ee5251d541658e6c8b0744a Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 11 Aug 2023 16:58:59 +0200 Subject: [PATCH 03/10] Tweaks --- .../errorprone/bugpatterns/DirectReturnTest.java | 2 +- .../errorprone/bugpatterns/util/MoreMatchersTest.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java index 319481b241..f5d3e15298 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java @@ -227,7 +227,7 @@ void replacement() { @Test void ignoreClassesAnnotatedWithLombokData() { BugCheckerRefactoringTestHelper.newInstance(DirectReturn.class, getClass()) - .addInputLines("Data.java", "package lombok;", "public @interface Data {}") + .addInputLines("Data.java", "package lombok;", "", "public @interface Data {}") .expectUnchanged() .addInputLines( "A.java", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java index 8a2a64f07e..776fd17604 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java @@ -110,7 +110,7 @@ void isSubTypeOfBoundTypeUnknown() { @Test void hasLombokDataAnnotation() { CompilationTestHelper.newInstance(LombokDataAnnotationMatcher.class, getClass()) - .addSourceLines("Data.java", "package lombok;", "public @interface Data {}") + .addSourceLines("Data.java", "package lombok;", "", "public @interface Data {}") .addSourceLines( "A.java", "import lombok.Data;", @@ -120,13 +120,13 @@ void hasLombokDataAnnotation() { "public class A {", " private String field;", "", - " static class B { }", + " static class B {}", "", " @Data", " // BUG: Diagnostic contains:", - " static class C { }", + " static class C {}", "}") - .addSourceLines("D.java", "import lombok.Data;", "", "public class D { }") + .addSourceLines("D.java", "public class D {}") .doTest(); } @@ -159,7 +159,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState } } - /** A {@link BugChecker} that delegates to {@link MoreMatchers#HAS_LOMBOK_DATA} . */ + /** A {@link BugChecker} that delegates to {@link MoreMatchers#HAS_LOMBOK_DATA}. */ @BugPattern(summary = "Interacts with `MoreMatchers` for testing purposes", severity = ERROR) public static final class LombokDataAnnotationMatcher extends BugChecker implements ClassTreeMatcher { From 1d2d286e070306c54a35e0ce87f754cc5b9e4bfd Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 11 Aug 2023 17:06:39 +0200 Subject: [PATCH 04/10] Tweak --- .../java/tech/picnic/errorprone/bugpatterns/DirectReturn.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java index 1f7dec3416..98799bec80 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java @@ -69,8 +69,8 @@ public DirectReturn() {} @Override public Description matchBlock(BlockTree tree, VisitorState state) { List statements = tree.getStatements(); - ClassTree enclosingNode = ASTHelpers.findEnclosingNode(state.getPath(), ClassTree.class); - if (statements.size() < 2 || HAS_LOMBOK_DATA.matches(enclosingNode, state)) { + ClassTree enclosingClass = ASTHelpers.findEnclosingNode(state.getPath(), ClassTree.class); + if (statements.size() < 2 || HAS_LOMBOK_DATA.matches(enclosingClass, state)) { return Description.NO_MATCH; } From 7f78ac52fe5b97a11007b02fdefefc07e5fbaae8 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 29 Aug 2023 10:04:40 +0200 Subject: [PATCH 05/10] Apply suggestions --- .../bugpatterns/util/MoreMatchersTest.java | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java index 776fd17604..cda4e28c88 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java @@ -1,7 +1,6 @@ package tech.picnic.errorprone.bugpatterns.util; import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; -import static tech.picnic.errorprone.bugpatterns.util.MoreMatchers.HAS_LOMBOK_DATA; import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.generic; import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.subOf; import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.type; @@ -24,6 +23,29 @@ import org.junit.jupiter.api.Test; final class MoreMatchersTest { + @Test + void hasLombokDataAnnotation() { + CompilationTestHelper.newInstance(HasLombokDataTestChecker.class, getClass()) + .addSourceLines("Data.java", "package lombok;", "", "public @interface Data {}") + .addSourceLines( + "A.java", + "import lombok.Data;", + "", + "@Data", + "// BUG: Diagnostic contains:", + "public class A {", + " private String field;", + "", + " static class B {}", + "", + " @Data", + " // BUG: Diagnostic contains:", + " static class C {}", + "}") + .addSourceLines("D.java", "public class D {}") + .doTest(); + } + @Test void hasMetaAnnotation() { CompilationTestHelper.newInstance(HasMetaAnnotationTestChecker.class, getClass()) @@ -107,27 +129,17 @@ void isSubTypeOfBoundTypeUnknown() { .doTest(); } -@Test - void hasLombokDataAnnotation() { - CompilationTestHelper.newInstance(LombokDataAnnotationMatcher.class, getClass()) - .addSourceLines("Data.java", "package lombok;", "", "public @interface Data {}") - .addSourceLines( - "A.java", - "import lombok.Data;", - "", - "@Data", - "// BUG: Diagnostic contains:", - "public class A {", - " private String field;", - "", - " static class B {}", - "", - " @Data", - " // BUG: Diagnostic contains:", - " static class C {}", - "}") - .addSourceLines("D.java", "public class D {}") - .doTest(); + /** A {@link BugChecker} that delegates to {@link MoreMatchers#HAS_LOMBOK_DATA}. */ + @BugPattern(summary = "Interacts with `MoreMatchers` for testing purposes", severity = ERROR) + public static final class HasLombokDataTestChecker extends BugChecker + implements ClassTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher DELEGATE = MoreMatchers.HAS_LOMBOK_DATA; + + @Override + public Description matchClass(ClassTree tree, VisitorState state) { + return DELEGATE.matches(tree, state) ? describeMatch(tree) : Description.NO_MATCH; + } } /** A {@link BugChecker} that delegates to {@link MoreMatchers#hasMetaAnnotation(String)}. */ @@ -156,18 +168,6 @@ public static final class IsSubTypeOfTestChecker extends BugChecker @Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { return DELEGATE.matches(tree, state) ? describeMatch(tree) : Description.NO_MATCH; -} -} - - /** A {@link BugChecker} that delegates to {@link MoreMatchers#HAS_LOMBOK_DATA}. */ - @BugPattern(summary = "Interacts with `MoreMatchers` for testing purposes", severity = ERROR) - public static final class LombokDataAnnotationMatcher extends BugChecker - implements ClassTreeMatcher { - private static final long serialVersionUID = 1L; - - @Override - public Description matchClass(ClassTree tree, VisitorState state) { - return HAS_LOMBOK_DATA.matches(tree, state) ? describeMatch(tree) : Description.NO_MATCH; } } } From bec7cddcb6b388c0d29f517360771afbce66a43e Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 29 Aug 2023 11:22:54 +0200 Subject: [PATCH 06/10] Format --- .../tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java index 175c828a03..77bb015594 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java @@ -7,9 +7,9 @@ import com.google.errorprone.matchers.Matchers; import com.google.errorprone.suppliers.Supplier; import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.ClassTree; import com.sun.source.tree.Tree; import com.sun.tools.javac.code.Type; -import com.sun.source.tree.ClassTree; /** * A collection of general-purpose {@link Matcher}s. From 0f245037549b0088a53634ee21728f18e1ab8465 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Wed, 30 Aug 2023 13:05:05 +0200 Subject: [PATCH 07/10] Revert to Mo s suggestion --- error-prone-contrib/pom.xml | 5 +++++ .../bugpatterns/DirectReturnTest.java | 17 ++++------------- pom.xml | 5 +++++ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index cd4016dfe8..d04e1b5ef5 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -181,6 +181,11 @@ mongodb-driver-core test + + org.projectlombok + lombok + test + org.reactivestreams reactive-streams diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java index f5d3e15298..19af8b4a34 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java @@ -226,18 +226,8 @@ void replacement() { @Test void ignoreClassesAnnotatedWithLombokData() { - BugCheckerRefactoringTestHelper.newInstance(DirectReturn.class, getClass()) - .addInputLines("Data.java", "package lombok;", "", "public @interface Data {}") - .expectUnchanged() - .addInputLines( - "A.java", - "import lombok.Data;", - "", - "@Data", - "class A {", - " private String field;", - "}") - .addOutputLines( + CompilationTestHelper.newInstance(DirectReturn.class, getClass()) + .addSourceLines( "A.java", "import lombok.Data;", "", @@ -245,6 +235,7 @@ void ignoreClassesAnnotatedWithLombokData() { "class A {", " private String field;", "}") - .doTest(TestMode.TEXT_MATCH); + .expectNoDiagnostics() + .doTest(); } } diff --git a/pom.xml b/pom.xml index f073c04cc1..232d622c4e 100644 --- a/pom.xml +++ b/pom.xml @@ -456,6 +456,11 @@ + + org.projectlombok + lombok + 1.18.28 + org.slf4j slf4j-api From e98cc88c2db0284b09d9fce9cec42485614bf826 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Wed, 30 Aug 2023 13:07:24 +0200 Subject: [PATCH 08/10] Further improvements --- .../picnic/errorprone/bugpatterns/util/MoreMatchersTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java index cda4e28c88..d3bd03b4d7 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java @@ -26,7 +26,6 @@ final class MoreMatchersTest { @Test void hasLombokDataAnnotation() { CompilationTestHelper.newInstance(HasLombokDataTestChecker.class, getClass()) - .addSourceLines("Data.java", "package lombok;", "", "public @interface Data {}") .addSourceLines( "A.java", "import lombok.Data;", From 245dcf903a315ec96e4eb4d8014b378b874a5b83 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Wed, 30 Aug 2023 13:09:09 +0200 Subject: [PATCH 09/10] Drop another line --- .../tech/picnic/errorprone/bugpatterns/DirectReturnTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java index 19af8b4a34..ecb9b9582a 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java @@ -235,7 +235,6 @@ void ignoreClassesAnnotatedWithLombokData() { "class A {", " private String field;", "}") - .expectNoDiagnostics() .doTest(); } } From 6423d397fa38a7dfa43d003c77e9d57efa03ab88 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Thu, 7 Sep 2023 19:13:30 +0200 Subject: [PATCH 10/10] Suggestions --- .../tech/picnic/errorprone/bugpatterns/DirectReturnTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java index ecb9b9582a..1d8c5fe8cc 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/DirectReturnTest.java @@ -227,6 +227,7 @@ void replacement() { @Test void ignoreClassesAnnotatedWithLombokData() { CompilationTestHelper.newInstance(DirectReturn.class, getClass()) + .setArgs("-processor", "lombok.launch.AnnotationProcessorHider$AnnotationProcessor") .addSourceLines( "A.java", "import lombok.Data;",