From da9cc7b6b27de2a233b1ed92333ff4e280f21f40 Mon Sep 17 00:00:00 2001 From: Lekanich Date: Sun, 27 Oct 2019 15:09:56 +0200 Subject: Issue2262. Added ability to process JCField as type parameter for HandleSuperBuilder. javac. --- .../lombok/javac/handlers/HandleSuperBuilder.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/core/lombok/javac/handlers/HandleSuperBuilder.java') diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index 0f809571..83dc23d1 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -26,6 +26,7 @@ import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; import java.util.ArrayList; +import java.util.Collections; import javax.lang.model.element.Modifier; @@ -1007,8 +1008,35 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { typeParamsForBuilderParameter.add(maker.Ident(((JCTypeParameter)typeParam).getName())); } else if (typeParam instanceof JCIdent) { typeParamsForBuilderParameter.add(maker.Ident(((JCIdent)typeParam).getName())); + } else if (typeParam instanceof JCFieldAccess) { + typeParamsForBuilderParameter.add(copySelect(maker, (JCFieldAccess) typeParam)); } } return typeParamsForBuilderParameter; } + + private JCExpression copySelect(JavacTreeMaker maker, JCFieldAccess typeParam) { + java.util.List chainNames = new ArrayList(); + JCExpression expression = typeParam; + while (expression != null) { + if (expression instanceof JCFieldAccess) { + chainNames.add(((JCFieldAccess) expression).getIdentifier()); + expression = ((JCFieldAccess) expression).getExpression(); + } else if (expression instanceof JCIdent) { + chainNames.add(((JCIdent) expression).getName()); + expression = null; + } + } + + Collections.reverse(chainNames); + JCExpression typeParameter = null; + for (Name name : chainNames) { + if (typeParameter == null) { + typeParameter = maker.Ident(name); + } else { + typeParameter = maker.Select(typeParameter, name); + } + } + return typeParameter; + } } -- cgit