diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-03-15 06:59:31 +0100 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-03-15 06:59:31 +0100 |
commit | 94440a8bd73f176637a9890dc10df67d26615674 (patch) | |
tree | a4ead3a782238c141dda6a0b7d43433f7c3997f1 | |
parent | 3edac649118dff4a48d7218dc31a727f13537fea (diff) | |
download | lombok-94440a8bd73f176637a9890dc10df67d26615674.tar.gz lombok-94440a8bd73f176637a9890dc10df67d26615674.tar.bz2 lombok-94440a8bd73f176637a9890dc10df67d26615674.zip |
[UtilityClass] [issue #2384] Added a test to confirm no issue.
added some tests to confirm that lombok makes things static if needed.
5 files changed, 27 insertions, 4 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleUtilityClass.java b/src/core/lombok/eclipse/handlers/HandleUtilityClass.java index 959c1d20..ada09d0e 100644 --- a/src/core/lombok/eclipse/handlers/HandleUtilityClass.java +++ b/src/core/lombok/eclipse/handlers/HandleUtilityClass.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2020 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -113,7 +113,7 @@ public class HandleUtilityClass extends EclipseAnnotationHandler<UtilityClass> { if (typeNode.up().getKind() == Kind.COMPILATION_UNIT) markStatic = false; if (markStatic && typeNode.up().getKind() == Kind.TYPE) { TypeDeclaration typeDecl = (TypeDeclaration) typeNode.up().get(); - if ((typeDecl.modifiers & ClassFileConstants.AccInterface) != 0) markStatic = false; + if ((typeDecl.modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0) markStatic = false; } if (markStatic) classDecl.modifiers |= ClassFileConstants.AccStatic; diff --git a/src/core/lombok/javac/handlers/HandleUtilityClass.java b/src/core/lombok/javac/handlers/HandleUtilityClass.java index ee8081d6..95de4c47 100644 --- a/src/core/lombok/javac/handlers/HandleUtilityClass.java +++ b/src/core/lombok/javac/handlers/HandleUtilityClass.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2020 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -110,7 +110,7 @@ public class HandleUtilityClass extends JavacAnnotationHandler<UtilityClass> { if (typeNode.up().getKind() == Kind.COMPILATION_UNIT) markStatic = false; if (markStatic && typeNode.up().getKind() == Kind.TYPE) { JCClassDecl typeDecl = (JCClassDecl) typeNode.up().get(); - if ((typeDecl.mods.flags & Flags.INTERFACE) != 0) markStatic = false; + if ((typeDecl.mods.flags & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0) markStatic = false; } if (markStatic) classDecl.mods.flags |= Flags.STATIC; diff --git a/test/transform/resource/after-delombok/UtilityClassInner.java b/test/transform/resource/after-delombok/UtilityClassInner.java new file mode 100644 index 00000000..72f1656a --- /dev/null +++ b/test/transform/resource/after-delombok/UtilityClassInner.java @@ -0,0 +1,8 @@ +class UtilityClassInner { + static final class UtilClass { + @java.lang.SuppressWarnings("all") + private UtilClass() { + throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/UtilityClassInner.java b/test/transform/resource/after-ecj/UtilityClassInner.java new file mode 100644 index 00000000..eebc5d13 --- /dev/null +++ b/test/transform/resource/after-ecj/UtilityClassInner.java @@ -0,0 +1,11 @@ +class UtilityClassInner { + static final @lombok.experimental.UtilityClass class UtilClass { + private @java.lang.SuppressWarnings("all") UtilClass() { + super(); + throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } + } + UtilityClassInner() { + super(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/UtilityClassInner.java b/test/transform/resource/before/UtilityClassInner.java new file mode 100644 index 00000000..ccb0101b --- /dev/null +++ b/test/transform/resource/before/UtilityClassInner.java @@ -0,0 +1,4 @@ +class UtilityClassInner { + @lombok.experimental.UtilityClass + class UtilClass {} +}
\ No newline at end of file |