diff options
7 files changed, 34 insertions, 20 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) { diff --git a/test/transform/resource/after-delombok/LoggerFloggerRecord.java b/test/transform/resource/after-delombok/LoggerFloggerRecord.java new file mode 100644 index 00000000..9cc0c9c0 --- /dev/null +++ b/test/transform/resource/after-delombok/LoggerFloggerRecord.java @@ -0,0 +1,6 @@ +class LoggerFloggerRecord { + record Inner(String x) { + @java.lang.SuppressWarnings("all") + private static final com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/LoggerFloggerRecord.java b/test/transform/resource/after-ecj/LoggerFloggerRecord.java new file mode 100644 index 00000000..86004b67 --- /dev/null +++ b/test/transform/resource/after-ecj/LoggerFloggerRecord.java @@ -0,0 +1,16 @@ +import lombok.extern.flogger.Flogger; +class LoggerFloggerRecord { + static @Flogger record Inner(String x) { + private static final com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass(); +/* Implicit */ private final String x; + <clinit>() { + } + public Inner(String x) { + super(); + .x = x; + } + } + LoggerFloggerRecord() { + super(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/LoggerFlogger.java b/test/transform/resource/before/LoggerFlogger.java index ff0249c7..4bdc20b0 100644 --- a/test/transform/resource/before/LoggerFlogger.java +++ b/test/transform/resource/before/LoggerFlogger.java @@ -25,4 +25,4 @@ class LoggerFloggerWithInnerEnum { enum Inner { CONSTANT; } -}
\ No newline at end of file +} diff --git a/test/transform/resource/before/LoggerFloggerRecord.java b/test/transform/resource/before/LoggerFloggerRecord.java new file mode 100644 index 00000000..908704d6 --- /dev/null +++ b/test/transform/resource/before/LoggerFloggerRecord.java @@ -0,0 +1,8 @@ +// version 14: + +import lombok.extern.flogger.Flogger; + +class LoggerFloggerRecord { + @Flogger + record Inner(String x) {} +} |