From 0ab433b41a6d2afa446d7e46204531c1efa606e2 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Tue, 11 Feb 2020 12:25:53 +0100 Subject: SuperBuilder javac fix for nested generic types; fixes #2359 --- src/core/lombok/javac/handlers/HandleSuperBuilder.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/core/lombok/javac/handlers') diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index c9df4811..5f4f3c1d 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -53,6 +53,7 @@ import com.sun.tools.javac.tree.JCTree.JCTypeApply; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.tree.JCTree.JCWildcard; +import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; @@ -414,7 +415,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { allTypeParams.add(maker.TypeParameter(tdParent.toName(classGenericName), List.of(annotatedClass))); // 2. The return type for all setter methods, named "B", which extends this builder class. Name builderClassName = tdParent.toName(builderClass); - ListBuffer typeParamsForBuilder = getTypeParamExpressions(typeParams, maker); + ListBuffer typeParamsForBuilder = getTypeParamExpressions(typeParams, maker, source.getContext()); typeParamsForBuilder.add(maker.Ident(tdParent.toName(classGenericName))); typeParamsForBuilder.add(maker.Ident(tdParent.toName(builderGenericName))); JCTypeApply typeApply = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, tdParent, builderClassName, false, List.nil()), typeParamsForBuilder.toList()); @@ -424,7 +425,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { if (superclassBuilderClassExpression != null) { // If the annotated class extends another class, we want this builder to extend the builder of the superclass. // 1. Add the type parameters of the superclass. - typeParamsForBuilder = getTypeParamExpressions(superclassTypeParams, maker); + typeParamsForBuilder = getTypeParamExpressions(superclassTypeParams, maker, source.getContext()); // 2. Add the builder type params . typeParamsForBuilder.add(maker.Ident(tdParent.toName(classGenericName))); typeParamsForBuilder.add(maker.Ident(tdParent.toName(builderGenericName))); @@ -453,7 +454,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { // 2. The return type for all setter methods (named "B" in the abstract builder), which is this builder class. JCExpression builderImplClassExpression = namePlusTypeParamsToTypeReference(maker, tdParent, tdParent.toName(builderImplClass), false, typeParams); - ListBuffer typeParamsForBuilder = getTypeParamExpressions(typeParams, maker); + ListBuffer typeParamsForBuilder = getTypeParamExpressions(typeParams, maker, source.getContext()); typeParamsForBuilder.add(annotatedClass); typeParamsForBuilder.add(builderImplClassExpression); extending = maker.TypeApply(extending, typeParamsForBuilder.toList()); @@ -522,7 +523,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext()); Name builderClassname = typeNode.toName(builderClassName); // First add all generics that are present on the parent type. - ListBuffer typeParamsForBuilderParameter = getTypeParamExpressions(typeParams, maker); + ListBuffer typeParamsForBuilderParameter = getTypeParamExpressions(typeParams, maker, typeNode.getContext()); // Now add the . JCWildcard wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); typeParamsForBuilderParameter.add(wildcard); @@ -685,7 +686,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { // 2nd parameter: "FoobarBuilder b" (plus generics on the annotated type) // First add all generics that are present on the parent type. - ListBuffer typeParamsForBuilderParameter = getTypeParamExpressions(typeParams, maker); + ListBuffer typeParamsForBuilderParameter = getTypeParamExpressions(typeParams, maker, type.getContext()); // Now add the . JCWildcard wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); typeParamsForBuilderParameter.add(wildcard); @@ -1029,7 +1030,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { return null; } - private ListBuffer getTypeParamExpressions(List typeParams, JavacTreeMaker maker) { + private ListBuffer getTypeParamExpressions(List typeParams, JavacTreeMaker maker, Context context) { ListBuffer typeParamsForBuilderParameter = new ListBuffer(); for (JCTree typeParam : typeParams) { if (typeParam instanceof JCTypeParameter) { @@ -1038,6 +1039,8 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { typeParamsForBuilderParameter.add(maker.Ident(((JCIdent)typeParam).getName())); } else if (typeParam instanceof JCFieldAccess) { typeParamsForBuilderParameter.add(copySelect(maker, (JCFieldAccess) typeParam)); + } else if (typeParam instanceof JCTypeApply) { + typeParamsForBuilderParameter.add(cloneType(maker, (JCTypeApply)typeParam, typeParam, context)); } } return typeParamsForBuilderParameter; -- cgit