aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorJan Rieke <rieke@subshell.com>2018-09-24 16:46:00 +0200
committerJan Rieke <rieke@subshell.com>2018-09-24 16:46:00 +0200
commitb5648976b6501bdf755814d8d8a096c33f6997ec (patch)
treeaafe939cdc6fdda41719deb42f03c77934cb5209 /src/core/lombok/javac
parentfd4c9d4bff6e75b30a3ee247edafaabc6888a691 (diff)
parentaee4e76d864e01b5d453409e703ad54852fa57bb (diff)
downloadlombok-b5648976b6501bdf755814d8d8a096c33f6997ec.tar.gz
lombok-b5648976b6501bdf755814d8d8a096c33f6997ec.tar.bz2
lombok-b5648976b6501bdf755814d8d8a096c33f6997ec.zip
Merge remote-tracking branch 'upstream/master' into superToBuilder
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java11
-rw-r--r--src/core/lombok/javac/handlers/HandleConstructor.java14
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java7
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java7
-rw-r--r--src/core/lombok/javac/handlers/HandleSuperBuilder.java10
-rw-r--r--src/core/lombok/javac/handlers/HandleWither.java7
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java130
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java6
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java6
-rw-r--r--src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java11
10 files changed, 174 insertions, 35 deletions
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index 201b5048..bf260644 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -85,6 +85,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
}
public static class BuilderFieldData {
+ List<JCAnnotation> annotations;
JCExpression type;
Name rawName;
Name name;
@@ -148,9 +149,11 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
JCVariableDecl fd = (JCVariableDecl) fieldNode.get();
JavacNode isDefault = findAnnotation(Builder.Default.class, fieldNode, false);
boolean isFinal = (fd.mods.flags & Flags.FINAL) != 0 || (valuePresent && !hasAnnotation(NonFinal.class, fieldNode));
+
BuilderFieldData bfd = new BuilderFieldData();
bfd.rawName = fd.name;
bfd.name = removePrefixFromField(fieldNode);
+ bfd.annotations = findCopyableAnnotations(fieldNode);
bfd.type = fd.vartype;
bfd.singularData = getSingularData(fieldNode);
bfd.originalFieldNode = fieldNode;
@@ -326,9 +329,11 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
for (JavacNode param : fillParametersFrom.down()) {
if (param.getKind() != Kind.ARGUMENT) continue;
BuilderFieldData bfd = new BuilderFieldData();
+
JCVariableDecl raw = (JCVariableDecl) param.get();
bfd.name = raw.name;
bfd.rawName = raw.name;
+ bfd.annotations = findCopyableAnnotations(param);
bfd.type = raw.vartype;
bfd.singularData = getSingularData(param);
bfd.originalFieldNode = param;
@@ -678,13 +683,13 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
public void makeSetterMethodsForBuilder(JavacNode builderType, BuilderFieldData fieldNode, JavacNode source, boolean fluent, boolean chain) {
boolean deprecate = isFieldDeprecated(fieldNode.originalFieldNode);
if (fieldNode.singularData == null || fieldNode.singularData.getSingularizer() == null) {
- makeSimpleSetterMethodForBuilder(builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.nameOfSetFlag, source, fluent, chain);
+ makeSimpleSetterMethodForBuilder(builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.nameOfSetFlag, source, fluent, chain, fieldNode.annotations);
} else {
fieldNode.singularData.getSingularizer().generateMethods(fieldNode.singularData, deprecate, builderType, source.get(), fluent, chain);
}
}
- private void makeSimpleSetterMethodForBuilder(JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name nameOfSetFlag, JavacNode source, boolean fluent, boolean chain) {
+ private void makeSimpleSetterMethodForBuilder(JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name nameOfSetFlag, JavacNode source, boolean fluent, boolean chain, List<JCAnnotation> annosOnParam) {
Name fieldName = ((JCVariableDecl) fieldNode.get()).name;
for (JavacNode child : builderType.down()) {
@@ -698,7 +703,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
JavacTreeMaker maker = fieldNode.getTreeMaker();
- JCMethodDecl newMethod = HandleSetter.createSetter(Flags.PUBLIC, deprecate, fieldNode, maker, setterName, nameOfSetFlag, chain, source, List.<JCAnnotation>nil(), List.<JCAnnotation>nil());
+ JCMethodDecl newMethod = HandleSetter.createSetter(Flags.PUBLIC, deprecate, fieldNode, maker, setterName, nameOfSetFlag, chain, source, List.<JCAnnotation>nil(), annosOnParam);
injectMethod(builderType, newMethod);
}
diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java
index 76caaffe..3c434d40 100644
--- a/src/core/lombok/javac/handlers/HandleConstructor.java
+++ b/src/core/lombok/javac/handlers/HandleConstructor.java
@@ -127,7 +127,7 @@ public class HandleConstructor {
//Skip static fields.
if ((fieldFlags & Flags.STATIC) != 0) continue;
boolean isFinal = (fieldFlags & Flags.FINAL) != 0;
- boolean isNonNull = nullMarked && !findAnnotations(child, NON_NULL_PATTERN).isEmpty();
+ boolean isNonNull = nullMarked && hasNonNullAnnotations(child);
if ((isFinal || isNonNull) && fieldDecl.init == null) fields.append(child);
}
return fields.toList();
@@ -329,12 +329,11 @@ public class HandleConstructor {
JCVariableDecl field = (JCVariableDecl) fieldNode.get();
Name fieldName = removePrefixFromField(fieldNode);
Name rawName = field.name;
- List<JCAnnotation> nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN);
- List<JCAnnotation> nullables = findAnnotations(fieldNode, NULLABLE_PATTERN);
+ List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(fieldNode);
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
- JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables)), fieldName, field.vartype, null);
+ JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, copyableAnnotations), fieldName, field.vartype, null);
params.append(param);
- if (!nonNulls.isEmpty()) {
+ if (hasNonNullAnnotations(fieldNode)) {
JCStatement nullCheck = generateNullCheck(maker, fieldNode, param, source);
if (nullCheck != null) nullChecks.append(nullCheck);
}
@@ -471,10 +470,9 @@ public class HandleConstructor {
JCVariableDecl field = (JCVariableDecl) fieldNode.get();
Name fieldName = removePrefixFromField(fieldNode);
JCExpression pType = cloneType(maker, field.vartype, source, typeNode.getContext());
- List<JCAnnotation> nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN);
- List<JCAnnotation> nullables = findAnnotations(fieldNode, NULLABLE_PATTERN);
+ List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(fieldNode);
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
- JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables)), fieldName, pType, null);
+ JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, copyableAnnotations), fieldName, pType, null);
params.append(param);
args.append(maker.Ident(fieldName));
}
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index 4fc6155c..7a178f66 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -243,12 +243,9 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
List<JCExpression> throwsClauses = List.nil();
JCExpression annotationMethodDefaultValue = null;
- List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
- List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
-
+ List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(field);
List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field);
-
- List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables);
+ List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod).appendList(copyableAnnotations);
if (isFieldDeprecated(field)) {
annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
}
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index 0ddaa7d7..28f5318d 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -226,16 +226,15 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
JCAssign assign = treeMaker.Assign(fieldRef, treeMaker.Ident(fieldDecl.name));
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
- List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
- List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
+ List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(field);
Name methodName = field.toName(setterName);
- List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
+ List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(copyableAnnotations);
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
- if (nonNulls.isEmpty()) {
+ if (!hasNonNullAnnotations(field)) {
statements.append(treeMaker.Exec(assign));
} else {
JCStatement nullCheck = generateNullCheck(treeMaker, field, source);
diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
index a440c9be..c84988ea 100644
--- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
@@ -131,6 +131,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
BuilderFieldData bfd = new BuilderFieldData();
bfd.rawName = fd.name;
bfd.name = removePrefixFromField(fieldNode);
+ bfd.annotations = findCopyableAnnotations(fieldNode);
bfd.type = fd.vartype;
bfd.singularData = getSingularData(fieldNode);
bfd.originalFieldNode = fieldNode;
@@ -451,8 +452,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
statements.append(assign);
}
- List<JCAnnotation> nonNulls = findAnnotations(bfd.originalFieldNode, NON_NULL_PATTERN);
- if (!nonNulls.isEmpty()) {
+ if (hasNonNullAnnotations(bfd.originalFieldNode)) {
JCStatement nullCheck = generateNullCheck(maker, bfd.originalFieldNode, source);
if (nullCheck != null) statements.append(nullCheck);
}
@@ -797,13 +797,13 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
}};
if (fieldNode.singularData == null || fieldNode.singularData.getSingularizer() == null) {
- generateSimpleSetterMethodForBuilder(builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.nameOfSetFlag, source, true, returnTypeMaker.make(), returnStatementMaker.make());
+ generateSimpleSetterMethodForBuilder(builderType, deprecate, fieldNode.createdFields.get(0), fieldNode.nameOfSetFlag, source, true, returnTypeMaker.make(), returnStatementMaker.make(), fieldNode.annotations);
} else {
fieldNode.singularData.getSingularizer().generateMethods(fieldNode.singularData, deprecate, builderType, source.get(), true, returnTypeMaker, returnStatementMaker);
}
}
- private void generateSimpleSetterMethodForBuilder(JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name nameOfSetFlag, JavacNode source, boolean fluent, JCExpression returnType, JCStatement returnStatement) {
+ private void generateSimpleSetterMethodForBuilder(JavacNode builderType, boolean deprecate, JavacNode fieldNode, Name nameOfSetFlag, JavacNode source, boolean fluent, JCExpression returnType, JCStatement returnStatement, List<JCAnnotation> annosOnParam) {
Name fieldName = ((JCVariableDecl) fieldNode.get()).name;
for (JavacNode child : builderType.down()) {
@@ -817,7 +817,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
JavacTreeMaker maker = fieldNode.getTreeMaker();
- JCMethodDecl newMethod = HandleSetter.createSetter(Flags.PUBLIC, deprecate, fieldNode, maker, setterName, nameOfSetFlag, returnType, returnStatement, source, List.<JCAnnotation>nil(), List.<JCAnnotation>nil());
+ JCMethodDecl newMethod = HandleSetter.createSetter(Flags.PUBLIC, deprecate, fieldNode, maker, setterName, nameOfSetFlag, returnType, returnStatement, source, List.<JCAnnotation>nil(), annosOnParam);
injectMethod(builderType, newMethod);
}
diff --git a/src/core/lombok/javac/handlers/HandleWither.java b/src/core/lombok/javac/handlers/HandleWither.java
index 87f3c16a..33c4dec2 100644
--- a/src/core/lombok/javac/handlers/HandleWither.java
+++ b/src/core/lombok/javac/handlers/HandleWither.java
@@ -222,8 +222,7 @@ public class HandleWither extends JavacAnnotationHandler<Wither> {
JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
- List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
- List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
+ List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(field);
Name methodName = field.toName(witherName);
@@ -231,7 +230,7 @@ public class HandleWither extends JavacAnnotationHandler<Wither> {
JCBlock methodBody = null;
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
- List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
+ List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(copyableAnnotations);
JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
@@ -264,7 +263,7 @@ public class HandleWither extends JavacAnnotationHandler<Wither> {
JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
JCReturn returnStatement = maker.Return(conditional);
- if (nonNulls.isEmpty()) {
+ if (!hasNonNullAnnotations(field)) {
statements.append(returnStatement);
} else {
JCStatement nullCheck = generateNullCheck(maker, field, source);
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 92c642d4..e4e40095 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -27,6 +27,7 @@ import static lombok.javac.Javac.*;
import static lombok.javac.JavacAugments.JCTree_generatedNode;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -49,6 +50,7 @@ import lombok.core.LombokImmutableList;
import lombok.core.AnnotationValues.AnnotationValue;
import lombok.core.TypeResolver;
import lombok.core.configuration.NullCheckExceptionType;
+import lombok.core.configuration.TypeName;
import lombok.core.handlers.HandlerUtil;
import lombok.delombok.LombokOptionsFactory;
import lombok.experimental.Accessors;
@@ -1038,6 +1040,57 @@ public class JavacHandlerUtil {
return (field.mods.flags & Flags.ENUM) != 0;
}
+ static class JCAnnotatedTypeReflect {
+ private static Class<?> TYPE;
+ private static Constructor<?> CONSTRUCTOR;
+ private static Field ANNOTATIONS, UNDERLYING_TYPE;
+
+ private static void init(Class<?> in) {
+ if (TYPE != null) return;
+ if (!in.getName().equals("com.sun.tools.javac.tree.JCTree$JCAnnotatedType")) return;
+ try {
+ CONSTRUCTOR = in.getDeclaredConstructor(List.class, JCExpression.class);
+ CONSTRUCTOR.setAccessible(true);
+ ANNOTATIONS = in.getDeclaredField("annotations");
+ UNDERLYING_TYPE = in.getDeclaredField("underlyingType");
+ TYPE = in;
+ } catch (Exception ignore) {}
+ }
+
+ static boolean is(JCTree obj) {
+ if (obj == null) return false;
+ init(obj.getClass());
+ return obj.getClass() == TYPE;
+ }
+
+ @SuppressWarnings("unchecked")
+ static List<JCAnnotation> getAnnotations(JCTree obj) {
+ init(obj.getClass());
+ try {
+ return (List<JCAnnotation>) ANNOTATIONS.get(obj);
+ } catch (Exception e) {
+ return List.nil();
+ }
+ }
+
+ static JCExpression getUnderlyingType(JCTree obj) {
+ init(obj.getClass());
+ try {
+ return (JCExpression) UNDERLYING_TYPE.get(obj);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ static JCExpression create(List<JCAnnotation> annotations, JCExpression underlyingType) {
+ try {
+ return (JCExpression) CONSTRUCTOR.newInstance(annotations, underlyingType);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ }
+
// jdk9 support, types have changed, names stay the same
static class ClassSymbolMembersField {
private static final Field membersField;
@@ -1335,6 +1388,63 @@ public class JavacHandlerUtil {
return result.toList();
}
+ public static boolean hasNonNullAnnotations(JavacNode node) {
+ for (JavacNode child : node.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ JCAnnotation annotation = (JCAnnotation) child.get();
+ for (String nn : NONNULL_ANNOTATIONS) if (typeMatches(nn, node, annotation.annotationType)) return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list).
+ */
+ public static List<JCAnnotation> findCopyableAnnotations(JavacNode node) {
+ JCAnnotation anno = null;
+ String annoName = null;
+ for (JavacNode child : node.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ if (anno != null) {
+ annoName = "";
+ break;
+ }
+ JCAnnotation annotation = (JCAnnotation) child.get();
+ annoName = annotation.annotationType.toString();
+ anno = annotation;
+ }
+ }
+
+ if (annoName == null) return List.nil();
+
+ java.util.List<TypeName> configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS);
+
+ if (!annoName.isEmpty()) {
+ for (TypeName cn : configuredCopyable) if (typeMatches(cn.toString(), node, anno.annotationType)) return List.of(anno);
+ for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, anno.annotationType)) return List.of(anno);
+ }
+
+ ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
+ for (JavacNode child : node.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ JCAnnotation annotation = (JCAnnotation) child.get();
+ boolean match = false;
+ for (TypeName cn : configuredCopyable) if (typeMatches(cn.toString(), node, annotation.annotationType)) {
+ result.append(annotation);
+ match = true;
+ break;
+ }
+ if (!match) for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, annotation.annotationType)) {
+ result.append(annotation);
+ break;
+ }
+ }
+ }
+ return result.toList();
+ }
+
/**
* Generates a new statement that checks if the given variable is null, and if so, throws a configured exception with the
* variable name as message.
@@ -1512,6 +1622,16 @@ public class JavacHandlerUtil {
return out.toList();
}
+ public static List<JCAnnotation> getTypeUseAnnotations(JCExpression from) {
+ if (!JCAnnotatedTypeReflect.is(from)) return List.nil();
+ return JCAnnotatedTypeReflect.getAnnotations(from);
+ }
+
+ public static JCExpression removeTypeUseAnnotations(JCExpression from) {
+ if (!JCAnnotatedTypeReflect.is(from)) return from;
+ return JCAnnotatedTypeReflect.getUnderlyingType(from);
+ }
+
public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, Name typeName, List<JCTypeParameter> params) {
if (params.isEmpty()) {
return maker.Ident(typeName);
@@ -1592,7 +1712,7 @@ public class JavacHandlerUtil {
}
/**
- * Creates a full clone of a given javac AST type node. Every part is cloned (every identifier, every select, every wildcard, every type apply).
+ * Creates a full clone of a given javac AST type node. Every part is cloned (every identifier, every select, every wildcard, every type apply, every type_use annotation).
*
* If there's any node in the tree that we don't know how to clone, that part isn't cloned. However, we wouldn't know what could possibly show up that we
* can't currently clone; that's just a safeguard.
@@ -1654,6 +1774,12 @@ public class JavacHandlerUtil {
return maker.Wildcard(newKind, newInner);
}
+ if (JCAnnotatedTypeReflect.is(in)) {
+ JCExpression underlyingType = cloneType0(maker, JCAnnotatedTypeReflect.getUnderlyingType(in));
+ List<JCAnnotation> anns = copyAnnotations(JCAnnotatedTypeReflect.getAnnotations(in));
+ return JCAnnotatedTypeReflect.create(anns, underlyingType);
+ }
+
// This is somewhat unsafe, but it's better than outright throwing an exception here. Returning null will just cause an exception down the pipeline.
return (JCExpression) in;
}
@@ -1829,7 +1955,7 @@ public class JavacHandlerUtil {
public static boolean isDirectDescendantOfObject(JavacNode typeNode) {
if (!(typeNode.get() instanceof JCClassDecl)) throw new IllegalArgumentException("not a type node");
- JCTree extending = Javac.getExtendsClause((JCClassDecl)typeNode.get());
+ JCTree extending = Javac.getExtendsClause((JCClassDecl) typeNode.get());
if (extending == null) return true;
String p = extending.toString();
return p.equals("Object") || p.equals("java.lang.Object");
diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
index ffaf6674..74010d52 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java
@@ -39,6 +39,7 @@ import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
@@ -125,7 +126,10 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer {
ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
for (int i = 0; i < suffixes.size(); i++) {
JCExpression pt = cloneParamType(i, maker, data.getTypeArgs(), builderType, source);
- JCVariableDecl p = maker.VarDef(maker.Modifiers(paramFlags), names[i], pt, null);
+ List<JCAnnotation> typeUseAnns = getTypeUseAnnotations(pt);
+ pt = removeTypeUseAnnotations(pt);
+ JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns);
+ JCVariableDecl p = maker.VarDef(paramMods, names[i], pt, null);
params.append(p);
}
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
index 39e53ebb..26ff8ba6 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java
@@ -36,6 +36,7 @@ import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
@@ -124,7 +125,10 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString()));
JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
- JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getSingularName(), paramType, null);
+ List<JCAnnotation> typeUseAnns = getTypeUseAnnotations(paramType);
+ paramType = removeTypeUseAnnotations(paramType);
+ JCModifiers paramMods = typeUseAnns.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnns);
+ JCVariableDecl param = maker.VarDef(paramMods, data.getSingularName(), paramType, null);
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
injectMethod(builderType, method);
}
diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
index 34350f40..a009b88c 100644
--- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
+++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java
@@ -40,6 +40,7 @@ import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
@@ -165,8 +166,14 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer {
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("put", name.toString()));
JCExpression paramTypeKey = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
JCExpression paramTypeValue = cloneParamType(1, maker, data.getTypeArgs(), builderType, source);
- JCVariableDecl paramKey = maker.VarDef(maker.Modifiers(paramFlags), keyName, paramTypeKey, null);
- JCVariableDecl paramValue = maker.VarDef(maker.Modifiers(paramFlags), valueName, paramTypeValue, null);
+ List<JCAnnotation> typeUseAnnsKey = getTypeUseAnnotations(paramTypeKey);
+ List<JCAnnotation> typeUseAnnsValue = getTypeUseAnnotations(paramTypeValue);
+ paramTypeKey = removeTypeUseAnnotations(paramTypeKey);
+ paramTypeValue = removeTypeUseAnnotations(paramTypeValue);
+ JCModifiers paramModsKey = typeUseAnnsKey.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsKey);
+ JCModifiers paramModsValue = typeUseAnnsValue.isEmpty() ? maker.Modifiers(paramFlags) : maker.Modifiers(paramFlags, typeUseAnnsValue);
+ JCVariableDecl paramKey = maker.VarDef(paramModsKey, keyName, paramTypeKey, null);
+ JCVariableDecl paramValue = maker.VarDef(paramModsValue, valueName, paramTypeValue, null);
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(paramKey, paramValue), thrown, body, null);
injectMethod(builderType, method);
}