From 60f575496b3184c2279e9dba470097ed164d5adf Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Sat, 29 May 2021 18:49:05 +0200 Subject: [fixes #2838] Handle anonymous classes properly Generated qualified names (e.g. Outer.Inner) now stop at anonymous classes instead of adding an empty part. All handlers that add static fields/methods/types now add error messages instead of generating invalid code. --- .../resource/before/AccessorsInAnonymousClass.java | 14 ++++++++++++++ .../resource/before/BuilderInAnonymousClass.java | 10 ++++++++++ .../resource/before/ConstructorsInAnonymousClass.java | 17 +++++++++++++++++ .../transform/resource/before/DataInAnonymousClass.java | 10 ++++++++++ .../before/EqualsAndHashCodeInAnonymousClass.java | 10 ++++++++++ .../before/FieldNameConstantsInAnonymousClass.java | 10 ++++++++++ .../resource/before/GetterInAnonymousClass.java | 10 ++++++++++ .../resource/before/GetterLazyInAnonymousClass.java | 10 ++++++++++ .../resource/before/LoggerSlf4jInAnonymousClass.java | 9 +++++++++ .../resource/before/SetterInAnonymousClass.java | 10 ++++++++++ .../resource/before/SuperBuilderInAnonymousClass.java | 15 +++++++++++++++ .../resource/before/SynchronizedInAnonymousClass.java | 12 ++++++++++++ .../resource/before/ToStringInAnonymousClass.java | 10 ++++++++++ .../resource/before/UtilityClassInAnonymousClass.java | 10 ++++++++++ .../resource/before/ValueInAnonymousClass.java | 10 ++++++++++ .../resource/before/WithByInAnonymousClass.java | 12 ++++++++++++ .../transform/resource/before/WithInAnonymousClass.java | 12 ++++++++++++ 17 files changed, 191 insertions(+) create mode 100644 test/transform/resource/before/AccessorsInAnonymousClass.java create mode 100644 test/transform/resource/before/BuilderInAnonymousClass.java create mode 100644 test/transform/resource/before/ConstructorsInAnonymousClass.java create mode 100644 test/transform/resource/before/DataInAnonymousClass.java create mode 100644 test/transform/resource/before/EqualsAndHashCodeInAnonymousClass.java create mode 100644 test/transform/resource/before/FieldNameConstantsInAnonymousClass.java create mode 100644 test/transform/resource/before/GetterInAnonymousClass.java create mode 100644 test/transform/resource/before/GetterLazyInAnonymousClass.java create mode 100644 test/transform/resource/before/LoggerSlf4jInAnonymousClass.java create mode 100644 test/transform/resource/before/SetterInAnonymousClass.java create mode 100644 test/transform/resource/before/SuperBuilderInAnonymousClass.java create mode 100644 test/transform/resource/before/SynchronizedInAnonymousClass.java create mode 100644 test/transform/resource/before/ToStringInAnonymousClass.java create mode 100644 test/transform/resource/before/UtilityClassInAnonymousClass.java create mode 100644 test/transform/resource/before/ValueInAnonymousClass.java create mode 100644 test/transform/resource/before/WithByInAnonymousClass.java create mode 100644 test/transform/resource/before/WithInAnonymousClass.java (limited to 'test/transform/resource/before') diff --git a/test/transform/resource/before/AccessorsInAnonymousClass.java b/test/transform/resource/before/AccessorsInAnonymousClass.java new file mode 100644 index 00000000..0bbab1d6 --- /dev/null +++ b/test/transform/resource/before/AccessorsInAnonymousClass.java @@ -0,0 +1,14 @@ +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +public class AccessorsInAnonymousClass { + Object annonymous = new Object() { + @Getter + @Setter + @Accessors(fluent = true) + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/BuilderInAnonymousClass.java b/test/transform/resource/before/BuilderInAnonymousClass.java new file mode 100644 index 00000000..8291e678 --- /dev/null +++ b/test/transform/resource/before/BuilderInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.Builder; + +public class BuilderInAnonymousClass { + Object annonymous = new Object() { + @Builder + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/ConstructorsInAnonymousClass.java b/test/transform/resource/before/ConstructorsInAnonymousClass.java new file mode 100644 index 00000000..b6e78dd3 --- /dev/null +++ b/test/transform/resource/before/ConstructorsInAnonymousClass.java @@ -0,0 +1,17 @@ +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public class ConstructorsInAnonymousClass { + Object annonymous = new Object() { + @AllArgsConstructor + @RequiredArgsConstructor + @NoArgsConstructor + class Inner { + private String string; + @NonNull + private String string2; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/DataInAnonymousClass.java b/test/transform/resource/before/DataInAnonymousClass.java new file mode 100644 index 00000000..3de5ac0b --- /dev/null +++ b/test/transform/resource/before/DataInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.Data; + +public class DataInAnonymousClass { + Object annonymous = new Object() { + @Data + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/EqualsAndHashCodeInAnonymousClass.java b/test/transform/resource/before/EqualsAndHashCodeInAnonymousClass.java new file mode 100644 index 00000000..0f0995b6 --- /dev/null +++ b/test/transform/resource/before/EqualsAndHashCodeInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.EqualsAndHashCode; + +public class EqualsAndHashCodeInAnonymousClass { + Object annonymous = new Object() { + @EqualsAndHashCode + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/FieldNameConstantsInAnonymousClass.java b/test/transform/resource/before/FieldNameConstantsInAnonymousClass.java new file mode 100644 index 00000000..86325ce5 --- /dev/null +++ b/test/transform/resource/before/FieldNameConstantsInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.experimental.FieldNameConstants; + +public class FieldNameConstantsInAnonymousClass { + Object annonymous = new Object() { + @FieldNameConstants + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/GetterInAnonymousClass.java b/test/transform/resource/before/GetterInAnonymousClass.java new file mode 100644 index 00000000..e8195021 --- /dev/null +++ b/test/transform/resource/before/GetterInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.Getter; + +public class GetterInAnonymousClass { + Object annonymous = new Object() { + @Getter + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/GetterLazyInAnonymousClass.java b/test/transform/resource/before/GetterLazyInAnonymousClass.java new file mode 100644 index 00000000..e342e636 --- /dev/null +++ b/test/transform/resource/before/GetterLazyInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.Getter; + +public class GetterLazyInAnonymousClass { + Object annonymous = new Object() { + class Inner { + @Getter(lazy = true) + private final String string = "test"; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/LoggerSlf4jInAnonymousClass.java b/test/transform/resource/before/LoggerSlf4jInAnonymousClass.java new file mode 100644 index 00000000..4839c7aa --- /dev/null +++ b/test/transform/resource/before/LoggerSlf4jInAnonymousClass.java @@ -0,0 +1,9 @@ +import lombok.extern.slf4j.Slf4j; + +public class LoggerSlf4jInAnonymousClass { + Object annonymous = new Object() { + @Slf4j + class Inner { + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/SetterInAnonymousClass.java b/test/transform/resource/before/SetterInAnonymousClass.java new file mode 100644 index 00000000..1b3c817b --- /dev/null +++ b/test/transform/resource/before/SetterInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.Setter; + +public class SetterInAnonymousClass { + Object annonymous = new Object() { + @Setter + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/SuperBuilderInAnonymousClass.java b/test/transform/resource/before/SuperBuilderInAnonymousClass.java new file mode 100644 index 00000000..bff871aa --- /dev/null +++ b/test/transform/resource/before/SuperBuilderInAnonymousClass.java @@ -0,0 +1,15 @@ +import lombok.experimental.SuperBuilder; + +public class SuperBuilderInAnonymousClass { + Object annonymous = new Object() { + @SuperBuilder + class InnerParent { + private String string; + } + + @SuperBuilder + class InnerChild { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/SynchronizedInAnonymousClass.java b/test/transform/resource/before/SynchronizedInAnonymousClass.java new file mode 100644 index 00000000..11c623ce --- /dev/null +++ b/test/transform/resource/before/SynchronizedInAnonymousClass.java @@ -0,0 +1,12 @@ +import lombok.Synchronized; + +public class SynchronizedInAnonymousClass { + Object annonymous = new Object() { + class Inner { + @Synchronized + public void foo() { + String foo = "bar"; + } + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/ToStringInAnonymousClass.java b/test/transform/resource/before/ToStringInAnonymousClass.java new file mode 100644 index 00000000..87a7a6c1 --- /dev/null +++ b/test/transform/resource/before/ToStringInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.ToString; + +public class ToStringInAnonymousClass { + Object annonymous = new Object() { + @ToString + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/UtilityClassInAnonymousClass.java b/test/transform/resource/before/UtilityClassInAnonymousClass.java new file mode 100644 index 00000000..41757502 --- /dev/null +++ b/test/transform/resource/before/UtilityClassInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.experimental.UtilityClass; + +public class UtilityClassInAnonymousClass { + Object annonymous = new Object() { + @UtilityClass + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/ValueInAnonymousClass.java b/test/transform/resource/before/ValueInAnonymousClass.java new file mode 100644 index 00000000..c0bde2ab --- /dev/null +++ b/test/transform/resource/before/ValueInAnonymousClass.java @@ -0,0 +1,10 @@ +import lombok.Value; + +public class ValueInAnonymousClass { + Object annonymous = new Object() { + @Value + class Inner { + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/WithByInAnonymousClass.java b/test/transform/resource/before/WithByInAnonymousClass.java new file mode 100644 index 00000000..b366f168 --- /dev/null +++ b/test/transform/resource/before/WithByInAnonymousClass.java @@ -0,0 +1,12 @@ +import lombok.experimental.WithBy; + +public class WithByInAnonymousClass { + Object annonymous = new Object() { + @WithBy + class Inner { + private Inner(String string) { } + + private String string; + } + }; +} \ No newline at end of file diff --git a/test/transform/resource/before/WithInAnonymousClass.java b/test/transform/resource/before/WithInAnonymousClass.java new file mode 100644 index 00000000..daf1bce5 --- /dev/null +++ b/test/transform/resource/before/WithInAnonymousClass.java @@ -0,0 +1,12 @@ +import lombok.With; + +public class WithInAnonymousClass { + Object annonymous = new Object() { + @With + class Inner { + private Inner(String string) { } + + private String string; + } + }; +} \ No newline at end of file -- cgit