aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleUtilityClass.java16
-rw-r--r--src/core/lombok/javac/handlers/HandleUtilityClass.java22
-rw-r--r--src/utils/lombok/javac/TreeMirrorMaker.java14
3 files changed, 28 insertions, 24 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleUtilityClass.java b/src/core/lombok/eclipse/handlers/HandleUtilityClass.java
index 36a7dc9c..176ff2d8 100644
--- a/src/core/lombok/eclipse/handlers/HandleUtilityClass.java
+++ b/src/core/lombok/eclipse/handlers/HandleUtilityClass.java
@@ -83,8 +83,10 @@ public class HandleUtilityClass extends EclipseAnnotationHandler<UtilityClass> {
typeWalk = typeWalk.up();
switch (typeWalk.getKind()) {
case TYPE:
- if ((((TypeDeclaration) typeWalk.get()).modifiers & ClassFileConstants.AccStatic) != 0) continue;
+ if ((((TypeDeclaration) typeWalk.get()).modifiers & (ClassFileConstants.AccStatic | ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0) continue;
if (typeWalk.up().getKind() == Kind.COMPILATION_UNIT) return true;
+ errorNode.addError("@UtilityClass automatically makes the class static, however, this class cannot be made static.");
+ return false;
case COMPILATION_UNIT:
return true;
default:
@@ -101,7 +103,15 @@ public class HandleUtilityClass extends EclipseAnnotationHandler<UtilityClass> {
classDecl.modifiers |= ClassFileConstants.AccFinal;
- if (typeNode.up().getKind() != Kind.COMPILATION_UNIT) classDecl.modifiers |= ClassFileConstants.AccStatic;
+ boolean markStatic = true;
+
+ 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 (markStatic) classDecl.modifiers |= ClassFileConstants.AccStatic;
for (EclipseNode element : typeNode.down()) {
if (element.getKind() == Kind.FIELD) {
@@ -155,7 +165,7 @@ public class HandleUtilityClass extends EclipseAnnotationHandler<UtilityClass> {
AllocationExpression exception = new AllocationExpression();
setGeneratedBy(exception, source);
- long[] ps = new long[3];
+ long[] ps = new long[JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION.length];
Arrays.fill(ps, p);
exception.type = new QualifiedTypeReference(JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION, ps);
setGeneratedBy(exception.type, source);
diff --git a/src/core/lombok/javac/handlers/HandleUtilityClass.java b/src/core/lombok/javac/handlers/HandleUtilityClass.java
index 9a37653e..a4f8cb45 100644
--- a/src/core/lombok/javac/handlers/HandleUtilityClass.java
+++ b/src/core/lombok/javac/handlers/HandleUtilityClass.java
@@ -44,7 +44,6 @@ import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Name;
/**
@@ -79,8 +78,11 @@ public class HandleUtilityClass extends JavacAnnotationHandler<UtilityClass> {
typeWalk = typeWalk.up();
switch (typeWalk.getKind()) {
case TYPE:
- if ((((JCClassDecl) typeWalk.get()).mods.flags & Flags.STATIC) != 0) continue;
+ JCClassDecl typeDef = (JCClassDecl) typeWalk.get();
+ if ((typeDef.mods.flags & (Flags.STATIC | Flags.ANNOTATION | Flags.ENUM | Flags.INTERFACE)) != 0) continue;
if (typeWalk.up().getKind() == Kind.COMPILATION_UNIT) return true;
+ errorNode.addError("@UtilityClass automatically makes the class static, however, this class cannot be made static.");
+ return false;
case COMPILATION_UNIT:
return true;
default:
@@ -97,7 +99,15 @@ public class HandleUtilityClass extends JavacAnnotationHandler<UtilityClass> {
classDecl.mods.flags |= Flags.FINAL;
- if (typeNode.up().getKind() != Kind.COMPILATION_UNIT) classDecl.mods.flags |= Flags.STATIC;
+ boolean markStatic = true;
+
+ 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 (markStatic) classDecl.mods.flags |= Flags.STATIC;
for (JavacNode element : typeNode.down()) {
if (element.getKind() == Kind.FIELD) {
@@ -135,13 +145,11 @@ public class HandleUtilityClass extends JavacAnnotationHandler<UtilityClass> {
}
private List<JCStatement> createThrowStatement(JavacNode typeNode, JavacTreeMaker maker) {
- ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
- JCExpression exceptionType = genTypeRef(typeNode, "java.lang.UnsupportedOperationException");
+ JCExpression exceptionType = genJavaLangTypeRef(typeNode, "UnsupportedOperationException");
List<JCExpression> jceBlank = List.nil();
JCExpression message = maker.Literal("This is a utility class and cannot be instantiated");
JCExpression exceptionInstance = maker.NewClass(null, jceBlank, exceptionType, List.of(message), null);
JCStatement throwStatement = maker.Throw(exceptionInstance);
- statements.add(throwStatement);
- return statements.toList();
+ return List.of(throwStatement);
}
}
diff --git a/src/utils/lombok/javac/TreeMirrorMaker.java b/src/utils/lombok/javac/TreeMirrorMaker.java
index 093839d7..918a3242 100644
--- a/src/utils/lombok/javac/TreeMirrorMaker.java
+++ b/src/utils/lombok/javac/TreeMirrorMaker.java
@@ -29,13 +29,9 @@ import java.util.Map;
import static lombok.javac.Javac.*;
import lombok.javac.JavacTreeMaker.TypeTag;
-import com.sun.source.tree.ClassTree;
import com.sun.source.tree.LabeledStatementTree;
-import com.sun.source.tree.NewClassTree;
import com.sun.source.tree.VariableTree;
import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.JCClassDecl;
-import com.sun.tools.javac.tree.JCTree.JCNewClass;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.tree.TreeCopier;
import com.sun.tools.javac.util.Context;
@@ -123,14 +119,4 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
@Override public JCTree visitLabeledStatement(LabeledStatementTree node, Void p) {
return node.getStatement().accept(this, p);
}
-
- @Override public JCTree visitNewClass(NewClassTree node, Void p) {
- JCNewClass copy = (JCNewClass) super.visitNewClass(node, p);
- return copy;
- }
-
- @Override public JCTree visitClass(ClassTree node, Void p) {
- JCClassDecl copy = (JCClassDecl) super.visitClass(node, p);
- return copy;
- }
}