aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2022-03-17 22:07:46 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2022-03-17 22:07:46 +0100
commit2eddba64f711091cb2dcf861559e9532947dff9d (patch)
tree50506b0877b0bdd0d15b919682b61757a23ead21 /src
parent3a4f0e08dbb82fdf93b04da2b0876563e96e13b7 (diff)
downloadlombok-2eddba64f711091cb2dcf861559e9532947dff9d.tar.gz
lombok-2eddba64f711091cb2dcf861559e9532947dff9d.tar.bz2
lombok-2eddba64f711091cb2dcf861559e9532947dff9d.zip
[fixes #2990] Treat records and enums as places where `static` is allowed.
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java10
-rw-r--r--src/core/lombok/javac/handlers/HandleLog.java2
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java10
3 files changed, 3 insertions, 19 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index c313cf51..93b0028d 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -2770,15 +2770,7 @@ public class EclipseHandlerUtil {
* Returns {@code true} if the provided node supports static methods and types (top level or static class)
*/
public static boolean isStaticAllowed(EclipseNode typeNode) {
- boolean staticAllowed = true;
-
- while (typeNode.getKind() != Kind.COMPILATION_UNIT) {
- if (!staticAllowed) return false;
-
- staticAllowed = typeNode.isStatic();
- typeNode = typeNode.up();
- }
- return true;
+ return typeNode.isStatic() || typeNode.up() == null || typeNode.up().getKind() == Kind.COMPILATION_UNIT || isRecord(typeNode);
}
public static AbstractVariableDeclaration[] getRecordComponents(TypeDeclaration typeDeclaration) {
diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java
index df3908dc..957f5581 100644
--- a/src/core/lombok/javac/handlers/HandleLog.java
+++ b/src/core/lombok/javac/handlers/HandleLog.java
@@ -80,7 +80,7 @@ public class HandleLog {
return;
}
- if (!typeNode.isEnumType() && useStatic && !isStaticAllowed(typeNode)) {
+ if (useStatic && !isStaticAllowed(typeNode)) {
annotationNode.addError(framework.getAnnotationAsString() + " is not supported on non-static nested classes.");
return;
}
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 53a518b4..b17e34d8 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -2096,15 +2096,7 @@ public class JavacHandlerUtil {
* Returns {@code true} if the provided node supports static methods and types (top level or static class)
*/
public static boolean isStaticAllowed(JavacNode typeNode) {
- boolean staticAllowed = true;
-
- while (typeNode.getKind() != Kind.COMPILATION_UNIT) {
- if (!staticAllowed) return false;
-
- staticAllowed = typeNode.isStatic();
- typeNode = typeNode.up();
- }
- return true;
+ return typeNode.isStatic() || typeNode.up() == null || typeNode.up().getKind() == Kind.COMPILATION_UNIT || isRecord(typeNode);
}
public static JavacNode upToTypeNode(JavacNode node) {