aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java24
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleBuilder.java5
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java9
-rw-r--r--src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java14
-rw-r--r--src/core/lombok/eclipse/handlers/HandleLog.java5
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSuperBuilder.java4
-rw-r--r--src/core/lombok/eclipse/handlers/HandleToString.java4
-rw-r--r--src/core/lombok/eclipse/handlers/HandleVal.java20
-rw-r--r--src/core/lombok/javac/JavacAST.java2
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java5
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java2
-rw-r--r--src/core/lombok/javac/handlers/HandleFieldNameConstants.java14
-rw-r--r--src/core/lombok/javac/handlers/HandleLog.java5
-rw-r--r--src/core/lombok/javac/handlers/HandleNonNull.java1
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java1
-rw-r--r--src/core/lombok/javac/handlers/HandleSuperBuilder.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleToString.java7
-rw-r--r--src/core/lombok/javac/handlers/HandleVal.java6
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java30
19 files changed, 128 insertions, 34 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 5eea980c..a9f435fd 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -1042,7 +1042,7 @@ public class EclipseHandlerUtil {
res[count] = name;
n = parent;
- while (n != null && n.getKind() == Kind.TYPE && n.get() instanceof TypeDeclaration) {
+ while (count > 0) {
TypeDeclaration td = (TypeDeclaration) n.get();
res[--count] = td.name;
n = n.up();
@@ -2636,6 +2636,13 @@ public class EclipseHandlerUtil {
}
/**
+ * Returns {@code true} if the provided node is an actual class, an enum or a record and not some other type declaration (so, not an annotation definition or interface).
+ */
+ public static boolean isClassEnumOrRecord(EclipseNode typeNode) {
+ return isTypeAndDoesNotHaveFlags(typeNode, ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation);
+ }
+
+ /**
* Returns {@code true} if the provided node is a record declaration (so, not an annotation definition, interface, enum, or plain class).
*/
public static boolean isRecord(EclipseNode typeNode) {
@@ -2662,6 +2669,21 @@ public class EclipseHandlerUtil {
return (modifiers & flags) == 0;
}
+ /**
+ * 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;
+ }
+
public static AbstractVariableDeclaration[] getRecordComponents(TypeDeclaration typeDeclaration) {
if (typeDeclaration == null || (typeDeclaration.modifiers & AccRecord) == 0) return null;
try {
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index dab774f3..82d3bfcf 100755
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -293,6 +293,11 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
List<EclipseNode> nonFinalNonDefaultedFields = null;
+ if (!isStaticAllowed(upToTypeNode(parent))) {
+ annotationNode.addError("@Builder is not supported on non-static nested classes.");
+ return;
+ }
+
if (parent.get() instanceof TypeDeclaration) {
if (!isClass(parent) && !isRecord(parent)) {
annotationNode.addError(BUILDER_NODE_NOT_SUPPORTED_ERR);
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index 12a3c315..a5e8dfb5 100755
--- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -538,14 +538,15 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
if (addWildcards) genericsCount.add(arraySizeOf(((TypeDeclaration) type.get()).typeParameters));
boolean staticContext = (((TypeDeclaration) type.get()).modifiers & ClassFileConstants.AccStatic) != 0;
EclipseNode tNode = type.up();
- if (!staticContext && tNode.getKind() == Kind.TYPE && (((TypeDeclaration) tNode.get()).modifiers & ClassFileConstants.AccInterface) != 0) staticContext = true;
while (tNode != null && tNode.getKind() == Kind.TYPE) {
+ TypeDeclaration td = (TypeDeclaration) tNode.get();
+ if (td.name == null || td.name.length == 0) break;
list.add(tNode.getName());
- if (addWildcards) genericsCount.add(staticContext ? 0 : arraySizeOf(((TypeDeclaration) tNode.get()).typeParameters));
- if (!staticContext) staticContext = (((TypeDeclaration) tNode.get()).modifiers & Modifier.STATIC) != 0;
+ if (!staticContext && tNode.getKind() == Kind.TYPE && (td.modifiers & ClassFileConstants.AccInterface) != 0) staticContext = true;
+ if (addWildcards) genericsCount.add(staticContext ? 0 : arraySizeOf(td.typeParameters));
+ if (!staticContext) staticContext = (td.modifiers & Modifier.STATIC) != 0;
tNode = tNode.up();
- if (!staticContext && tNode.getKind() == Kind.TYPE && (((TypeDeclaration) tNode.get()).modifiers & ClassFileConstants.AccInterface) != 0) staticContext = true;
}
Collections.reverse(list);
if (addWildcards) Collections.reverse(genericsCount);
diff --git a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java
index cc1a5c3f..071dcdfb 100644
--- a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java
+++ b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java
@@ -60,14 +60,12 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
private static final IdentifierName FIELDS = IdentifierName.valueOf("Fields");
public void generateFieldNameConstantsForType(EclipseNode typeNode, EclipseNode errorNode, AccessLevel level, boolean asEnum, IdentifierName innerTypeName, boolean onlyExplicit, boolean uppercase) {
- TypeDeclaration typeDecl = null;
- if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get();
-
- int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
- boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0;
-
- if (typeDecl == null || notAClass) {
- errorNode.addError("@FieldNameConstants is only supported on a class or an enum.");
+ if (!isClassEnumOrRecord(typeNode)) {
+ errorNode.addError("@FieldNameConstants is only supported on a class, an enum or a record.");
+ return;
+ }
+ if (!isStaticAllowed(typeNode)) {
+ errorNode.addError("@FieldNameConstants is not supported on non-static nested classes.");
return;
}
diff --git a/src/core/lombok/eclipse/handlers/HandleLog.java b/src/core/lombok/eclipse/handlers/HandleLog.java
index 1cac2de7..db9104ef 100644
--- a/src/core/lombok/eclipse/handlers/HandleLog.java
+++ b/src/core/lombok/eclipse/handlers/HandleLog.java
@@ -88,6 +88,11 @@ public class HandleLog {
return;
}
+ if (useStatic && !isStaticAllowed(owner)) {
+ annotationNode.addError(framework.getAnnotationAsString() + " is not supported on non-static nested classes.");
+ return;
+ }
+
Object valueGuess = annotation.getValueGuess("topic");
Expression loggerTopic = (Expression) annotation.getActualExpression("topic");
diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
index 4d5d2448..5bc6c125 100644
--- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
@@ -184,6 +184,10 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
annotationNode.addError("@SuperBuilder is only supported on classes.");
return;
}
+ if (!isStaticAllowed(parent)) {
+ annotationNode.addError("@SuperBuilder is not supported on non-static nested classes.");
+ return;
+ }
job.parentType = parent;
TypeDeclaration td = (TypeDeclaration) parent.get();
diff --git a/src/core/lombok/eclipse/handlers/HandleToString.java b/src/core/lombok/eclipse/handlers/HandleToString.java
index 171402b3..05b0e069 100644
--- a/src/core/lombok/eclipse/handlers/HandleToString.java
+++ b/src/core/lombok/eclipse/handlers/HandleToString.java
@@ -315,7 +315,9 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> {
String typeName = getSingleTypeName(type);
EclipseNode upType = type.up();
while (upType.getKind() == Kind.TYPE) {
- typeName = getSingleTypeName(upType) + "." + typeName;
+ String upTypeName = getSingleTypeName(upType);
+ if (upTypeName.isEmpty()) break;
+ typeName = upTypeName + "." + typeName;
upType = upType.up();
}
return typeName;
diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java
index ac53e27e..0f70e66d 100644
--- a/src/core/lombok/eclipse/handlers/HandleVal.java
+++ b/src/core/lombok/eclipse/handlers/HandleVal.java
@@ -22,12 +22,14 @@
package lombok.eclipse.handlers;
import static lombok.core.handlers.HandlerUtil.handleFlagUsage;
-import static lombok.eclipse.handlers.EclipseHandlerUtil.typeMatches;
+import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
+
import lombok.ConfigurationKeys;
import lombok.val;
import lombok.var;
import lombok.core.HandlerPriority;
import lombok.eclipse.DeferUntilPostDiet;
+import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseASTAdapter;
import lombok.eclipse.EclipseASTVisitor;
import lombok.eclipse.EclipseNode;
@@ -39,10 +41,13 @@ import org.eclipse.jdt.internal.compiler.ast.ForStatement;
import org.eclipse.jdt.internal.compiler.ast.ForeachStatement;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
+import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
/*
- * This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}.
+ * Java 1-9: This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}.
+ * Java 10+: Lombok uses the native 'var' support and transforms 'val' to 'final var'.
*/
@Provides(EclipseASTVisitor.class)
@DeferUntilPostDiet
@@ -96,5 +101,16 @@ public class HandleVal extends EclipseASTAdapter {
localNode.addError("variable initializer is 'null'");
return;
}
+
+ // For Java >= 10 we use native support
+ if (localNode.getSourceVersion() >= 10) {
+ if (isVal) {
+ TypeReference originalType = local.type;
+ local.type = new SingleTypeReference("var".toCharArray(), Eclipse.pos(local.type));
+ local.modifiers |= ClassFileConstants.AccFinal;
+ local.annotations = addAnnotation(local.type, local.annotations, originalType.getTypeName());
+ }
+ return;
+ }
}
}
diff --git a/src/core/lombok/javac/JavacAST.java b/src/core/lombok/javac/JavacAST.java
index f58de60f..0919c7d4 100644
--- a/src/core/lombok/javac/JavacAST.java
+++ b/src/core/lombok/javac/JavacAST.java
@@ -228,7 +228,7 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
int underscoreIdx = nm.indexOf('_');
if (underscoreIdx > -1) return Integer.parseInt(nm.substring(underscoreIdx + 1));
// assume java9+
- return Integer.parseInt(nm);
+ return Integer.parseInt(nm.substring(3));
} catch (Exception ignore) {}
return 6;
}
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index c23dc14c..bb852b55 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -234,6 +234,11 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
ArrayList<JavacNode> nonFinalNonDefaultedFields = null;
+ if (!isStaticAllowed(upToTypeNode(parent))) {
+ annotationNode.addError("@Builder is not supported on non-static nested classes.");
+ return;
+ }
+
if (parent.get() instanceof JCClassDecl) {
if (!isClass(parent) && !isRecord(parent)) {
annotationNode.addError(BUILDER_NODE_NOT_SUPPORTED_ERR);
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index ffe882d8..dace3521 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -385,7 +385,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
boolean staticContext = (((JCClassDecl) type.get()).getModifiers().flags & Flags.STATIC) != 0;
JavacNode tNode = type.up();
- while (tNode != null && tNode.getKind() == Kind.TYPE) {
+ while (tNode != null && tNode.getKind() == Kind.TYPE && !tNode.getName().isEmpty()) {
list.add(tNode.getName());
if (addWildcards) genericsCount.add(staticContext ? 0 : ((JCClassDecl) tNode.get()).typarams.size());
if (!staticContext) staticContext = (((JCClassDecl) tNode.get()).getModifiers().flags & Flags.STATIC) != 0;
diff --git a/src/core/lombok/javac/handlers/HandleFieldNameConstants.java b/src/core/lombok/javac/handlers/HandleFieldNameConstants.java
index f3c879d5..1fc6beb1 100644
--- a/src/core/lombok/javac/handlers/HandleFieldNameConstants.java
+++ b/src/core/lombok/javac/handlers/HandleFieldNameConstants.java
@@ -57,14 +57,12 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameCo
private static final IdentifierName FIELDS = IdentifierName.valueOf("Fields");
public void generateFieldNameConstantsForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean asEnum, IdentifierName innerTypeName, boolean onlyExplicit, boolean uppercase) {
- JCClassDecl typeDecl = null;
- if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get();
-
- long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags;
- boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION)) != 0;
-
- if (typeDecl == null || notAClass) {
- errorNode.addError("@FieldNameConstants is only supported on a class or an enum.");
+ if (!isClassEnumOrRecord(typeNode)) {
+ errorNode.addError("@FieldNameConstants is only supported on a class, an enum or a record.");
+ return;
+ }
+ if (!isStaticAllowed(typeNode)) {
+ errorNode.addError("@FieldNameConstants is not supported on non-static nested classes.");
return;
}
diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java
index 40f7ff08..957f5581 100644
--- a/src/core/lombok/javac/handlers/HandleLog.java
+++ b/src/core/lombok/javac/handlers/HandleLog.java
@@ -80,6 +80,11 @@ public class HandleLog {
return;
}
+ if (useStatic && !isStaticAllowed(typeNode)) {
+ annotationNode.addError(framework.getAnnotationAsString() + " is not supported on non-static nested classes.");
+ return;
+ }
+
Object valueGuess = annotation.getValueGuess("topic");
JCExpression loggerTopic = (JCExpression) annotation.getActualExpression("topic");
diff --git a/src/core/lombok/javac/handlers/HandleNonNull.java b/src/core/lombok/javac/handlers/HandleNonNull.java
index fe66432a..271bedbb 100644
--- a/src/core/lombok/javac/handlers/HandleNonNull.java
+++ b/src/core/lombok/javac/handlers/HandleNonNull.java
@@ -99,7 +99,6 @@ public class HandleNonNull extends JavacAnnotationHandler<NonNull> {
return recursiveSetGeneratedBy(constr, source);
} else {
existingCtr.mods = mods;
- existingCtr.params = params.toList();
existingCtr.body = body;
existingCtr = recursiveSetGeneratedBy(existingCtr, source);
addSuppressWarningsAll(existingCtr.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(existingCtr)), typeNode.getContext());
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index a0634494..e5b2c062 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -43,7 +43,6 @@ import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCAssign;
import com.sun.tools.javac.tree.JCTree.JCBlock;
-import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCReturn;
diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
index 87b18576..50193f99 100644
--- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
@@ -163,6 +163,10 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
annotationNode.addError("@SuperBuilder is only supported on classes.");
return;
}
+ if (!isStaticAllowed(parent)) {
+ annotationNode.addError("@SuperBuilder is not supported on non-static nested classes.");
+ return;
+ }
job.parentType = parent;
JCClassDecl td = (JCClassDecl) parent.get();
diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java
index 3fc6a4e4..249993ee 100644
--- a/src/core/lombok/javac/handlers/HandleToString.java
+++ b/src/core/lombok/javac/handlers/HandleToString.java
@@ -44,7 +44,6 @@ import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree;
import com.sun.tools.javac.tree.JCTree.JCBlock;
-import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
@@ -252,10 +251,10 @@ public class HandleToString extends JavacAnnotationHandler<ToString> {
}
public static String getTypeName(JavacNode typeNode) {
- String typeName = ((JCClassDecl) typeNode.get()).name.toString();
+ String typeName = typeNode.getName();
JavacNode upType = typeNode.up();
- while (upType.getKind() == Kind.TYPE) {
- typeName = ((JCClassDecl) upType.get()).name.toString() + "." + typeName;
+ while (upType.getKind() == Kind.TYPE && !upType.getName().isEmpty()) {
+ typeName = upType.getName() + "." + typeName;
upType = upType.up();
}
return typeName;
diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java
index 0ed831ab..d4fb1027 100644
--- a/src/core/lombok/javac/handlers/HandleVal.java
+++ b/src/core/lombok/javac/handlers/HandleVal.java
@@ -115,6 +115,12 @@ public class HandleVal extends JavacASTAdapter {
local.mods.annotations = local.mods.annotations == null ? List.of(valAnnotation) : local.mods.annotations.append(valAnnotation);
}
+ if (localNode.getSourceVersion() >= 10) {
+ local.vartype = null;
+ localNode.getAst().setChanged();
+ return;
+ }
+
if (JavacResolution.platformHasTargetTyping()) {
local.vartype = localNode.getAst().getTreeMaker().Ident(localNode.getAst().toName("___Lombok_VAL_Attrib__"));
} else {
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 78c20d39..a41264e8 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -106,6 +106,7 @@ import lombok.javac.Javac;
import lombok.javac.JavacAugments;
import lombok.javac.JavacNode;
import lombok.javac.JavacTreeMaker;
+import lombok.javac.JavacTreeMaker.TypeTag;
import lombok.permit.Permit;
/**
@@ -1286,6 +1287,7 @@ public class JavacHandlerUtil {
static Type classEnter(JCTree tree, JavacNode parent) {
Enter enter = Enter.instance(parent.getContext());
Env<AttrContext> classEnv = enter.getEnv((TypeSymbol) parent.getElement());
+ if (classEnv == null) return null;
Type type = (Type) Permit.invokeSneaky(classEnter, enter, tree, classEnv);
if (type == null) return null;
type.complete();
@@ -1902,7 +1904,7 @@ public class JavacHandlerUtil {
public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, JavacNode parentType, Name typeName, boolean instance, List<JCTypeParameter> params, List<JCAnnotation> annotations) {
JCExpression r = null;
- if (parentType != null && parentType.getKind() == Kind.TYPE) {
+ if (parentType != null && parentType.getKind() == Kind.TYPE && !parentType.getName().isEmpty()) {
JCClassDecl td = (JCClassDecl) parentType.get();
boolean outerInstance = instance && ((td.mods.flags & Flags.STATIC) == 0);
List<JCTypeParameter> outerParams = instance ? td.typarams : List.<JCTypeParameter>nil();
@@ -1979,6 +1981,13 @@ public class JavacHandlerUtil {
}
/**
+ * Returns {@code true} if the provided node is an actual class, an enum or a record and not some other type declaration (so, not an annotation definition or interface).
+ */
+ public static boolean isClassEnumOrRecord(JavacNode typeNode) {
+ return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ANNOTATION);
+ }
+
+ /**
* Returns {@code true} if the provided node is a record declaration (so, not an annotation definition, interface, enum, or plain class).
*/
public static boolean isRecord(JavacNode typeNode) {
@@ -1994,6 +2003,21 @@ public class JavacHandlerUtil {
return (typeDeclflags & flags) == 0;
}
+ /**
+ * 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;
+ }
+
public static JavacNode upToTypeNode(JavacNode node) {
if (node == null) throw new NullPointerException("node");
while ((node != null) && !(node.get() instanceof JCClassDecl)) node = node.up();
@@ -2028,7 +2052,9 @@ public class JavacHandlerUtil {
private static JCExpression cloneType0(JavacTreeMaker maker, JCTree in) {
if (in == null) return null;
- if (in instanceof JCPrimitiveTypeTree) return (JCExpression) in;
+ if (in instanceof JCPrimitiveTypeTree) {
+ return maker.TypeIdent(TypeTag.typeTag(in));
+ }
if (in instanceof JCIdent) {
return maker.Ident(((JCIdent) in).name);