From da004063e272e81b5f644d6baa20db594079c56d Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Thu, 31 Aug 2023 20:20:17 +0200 Subject: [PATCH] [fixes #3427] Remove javac support for getter on enum members --- src/core/lombok/eclipse/handlers/HandleGetter.java | 2 +- src/core/lombok/javac/handlers/HandleGetter.java | 2 +- .../resource/after-delombok/GetterEnumConstant.java | 3 +++ .../transform/resource/after-ecj/GetterEnumConstant.java | 9 +++++++++ test/transform/resource/before/GetterEnumConstant.java | 6 ++++++ .../messages-delombok/GetterEnumConstant.java.messages | 1 + .../messages-ecj/GetterEnumConstant.java.messages | 1 + 7 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/transform/resource/after-delombok/GetterEnumConstant.java create mode 100644 test/transform/resource/after-ecj/GetterEnumConstant.java create mode 100644 test/transform/resource/before/GetterEnumConstant.java create mode 100644 test/transform/resource/messages-delombok/GetterEnumConstant.java.messages create mode 100644 test/transform/resource/messages-ecj/GetterEnumConstant.java.messages diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 31236d21aa..2d8b112f47 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -168,7 +168,7 @@ public void createGetterForFields(AccessLevel level, Collection fie public void createGetterForField(AccessLevel level, EclipseNode fieldNode, EclipseNode errorNode, ASTNode source, boolean whineIfExists, boolean lazy, List onMethod) { - if (fieldNode.getKind() != Kind.FIELD) { + if (fieldNode.getKind() != Kind.FIELD || fieldNode.isEnumMember()) { errorNode.addError(GETTER_NODE_NOT_SUPPORTED_ERR); return; } diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index 3f7fbd2016..34fa5287e0 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -165,7 +165,7 @@ public void createGetterForFields(AccessLevel level, Collection field public void createGetterForField(AccessLevel level, JavacNode fieldNode, JavacNode source, boolean whineIfExists, boolean lazy, List onMethod) { - if (fieldNode.getKind() != Kind.FIELD) { + if (fieldNode.getKind() != Kind.FIELD || fieldNode.isEnumMember()) { source.addError(GETTER_NODE_NOT_SUPPORTED_ERR); return; } diff --git a/test/transform/resource/after-delombok/GetterEnumConstant.java b/test/transform/resource/after-delombok/GetterEnumConstant.java new file mode 100644 index 0000000000..b0213115a8 --- /dev/null +++ b/test/transform/resource/after-delombok/GetterEnumConstant.java @@ -0,0 +1,3 @@ +enum GetterEnumConstant { + ONE; +} diff --git a/test/transform/resource/after-ecj/GetterEnumConstant.java b/test/transform/resource/after-ecj/GetterEnumConstant.java new file mode 100644 index 0000000000..b8e7029d33 --- /dev/null +++ b/test/transform/resource/after-ecj/GetterEnumConstant.java @@ -0,0 +1,9 @@ +import lombok.Getter; +enum GetterEnumConstant { + @Getter ONE(), + () { + } + GetterEnumConstant() { + super(); + } +} diff --git a/test/transform/resource/before/GetterEnumConstant.java b/test/transform/resource/before/GetterEnumConstant.java new file mode 100644 index 0000000000..ba6b0ab0a2 --- /dev/null +++ b/test/transform/resource/before/GetterEnumConstant.java @@ -0,0 +1,6 @@ +import lombok.Getter; + +enum GetterEnumConstant { + @Getter + ONE; +} \ No newline at end of file diff --git a/test/transform/resource/messages-delombok/GetterEnumConstant.java.messages b/test/transform/resource/messages-delombok/GetterEnumConstant.java.messages new file mode 100644 index 0000000000..bec676928c --- /dev/null +++ b/test/transform/resource/messages-delombok/GetterEnumConstant.java.messages @@ -0,0 +1 @@ +4 @Getter is only supported on a class, an enum, or a field. diff --git a/test/transform/resource/messages-ecj/GetterEnumConstant.java.messages b/test/transform/resource/messages-ecj/GetterEnumConstant.java.messages new file mode 100644 index 0000000000..bec676928c --- /dev/null +++ b/test/transform/resource/messages-ecj/GetterEnumConstant.java.messages @@ -0,0 +1 @@ +4 @Getter is only supported on a class, an enum, or a field.