diff options
Diffstat (limited to 'src')
7 files changed, 27 insertions, 54 deletions
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 83a44cca..1038f116 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -788,7 +788,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { name = type.toString(); String targetFqn = JavacSingularsRecipes.get().toQualified(name); - JavacSingularizer singularizer = JavacSingularsRecipes.get().getSingularizer(targetFqn); + JavacSingularizer singularizer = JavacSingularsRecipes.get().getSingularizer(targetFqn, node); if (singularizer == null) { node.addError("Lombok does not know how to create the singular-form builder methods for type '" + name + "'; they won't be generated."); return null; diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index 72437814..7ef6b658 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -919,7 +919,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { name = type.toString(); String targetFqn = JavacSingularsRecipes.get().toQualified(name); - JavacSingularizer singularizer = JavacSingularsRecipes.get().getSingularizer(targetFqn); + JavacSingularizer singularizer = JavacSingularsRecipes.get().getSingularizer(targetFqn, node); if (singularizer == null) { node.addError("Lombok does not know how to create the singular-form builder methods for type '" + name + "'; they won't be generated."); return null; diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 2f6e97dc..28f8c69c 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -101,8 +101,8 @@ public class JavacSingularsRecipes { return singularizableTypes.toQualified(typeReference); } - public JavacSingularizer getSingularizer(String fqn) { - return singularizers.get(fqn); + public JavacSingularizer getSingularizer(String fqn, JavacNode node) { + return singularizers.get(fqn).getGuavaInsteadIfNeeded(node); } public static final class SingularData { @@ -154,6 +154,10 @@ public class JavacSingularsRecipes { public static abstract class JavacSingularizer { public abstract LombokImmutableList<String> getSupportedTypes(); + + protected JavacSingularizer getGuavaInsteadIfNeeded(JavacNode node) { + return this; + } protected JCModifiers makeMods(JavacTreeMaker maker, JavacNode node, boolean deprecate) { if (deprecate) return maker.Modifiers(Flags.PUBLIC, List.<JCAnnotation>of(maker.Annotation(genJavaLangTypeRef(node, "Deprecated"), List.<JCExpression>nil()))); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 6fe457f0..856a2295 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -30,6 +30,7 @@ import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil; import lombok.javac.handlers.JavacSingularsRecipes.ExpressionMaker; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; import lombok.javac.handlers.JavacSingularsRecipes.SingularData; import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker; @@ -43,27 +44,24 @@ import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularizer { - @Override public java.util.List<Name> listFieldsToBeGenerated(SingularData data, JavacNode builderType) { - if (useGuavaInstead(builderType)) { - return guavaListSetSingularizer.listFieldsToBeGenerated(data, builderType); + + @Override + protected JavacSingularizer getGuavaInsteadIfNeeded(JavacNode node) { + if (useGuavaInstead(node)) { + return guavaListSetSingularizer; } - + return this; + } + + @Override public java.util.List<Name> listFieldsToBeGenerated(SingularData data, JavacNode builderType) { return super.listFieldsToBeGenerated(data, builderType); } @Override public java.util.List<Name> listMethodsToBeGenerated(SingularData data, JavacNode builderType) { - if (useGuavaInstead(builderType)) { - return guavaListSetSingularizer.listMethodsToBeGenerated(data, builderType); - } - return super.listMethodsToBeGenerated(data, builderType); } @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) { - if (useGuavaInstead(builderType)) { - return guavaListSetSingularizer.generateFields(data, builderType, source); - } - JavacTreeMaker maker = builderType.getTreeMaker(); JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList"); type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source); @@ -73,11 +71,6 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize } @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker) { - if (useGuavaInstead(builderType)) { - guavaListSetSingularizer.generateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); - return; - } - doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java index b1375151..e5c5a170 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java @@ -47,11 +47,6 @@ public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingulari } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { - if (useGuavaInstead(builderType)) { - guavaListSetSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName, builderVariable); - return; - } - JavacTreeMaker maker = builderType.getTreeMaker(); List<JCExpression> jceBlank = List.nil(); ListBuffer<JCCase> cases = new ListBuffer<JCCase>(); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index f087a00f..c2c1f233 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -52,29 +52,25 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { @Override public LombokImmutableList<String> getSupportedTypes() { return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap"); } - - @Override public java.util.List<Name> listFieldsToBeGenerated(SingularData data, JavacNode builderType) { - if (useGuavaInstead(builderType)) { - return guavaMapSingularizer.listFieldsToBeGenerated(data, builderType); + + @Override + protected JavacSingularizer getGuavaInsteadIfNeeded(JavacNode node) { + if (useGuavaInstead(node)) { + return guavaMapSingularizer; } - + return this; + } + + @Override public java.util.List<Name> listFieldsToBeGenerated(SingularData data, JavacNode builderType) { String p = data.getPluralName().toString(); return Arrays.asList(builderType.toName(p + "$key"), builderType.toName(p + "$value")); } @Override public java.util.List<Name> listMethodsToBeGenerated(SingularData data, JavacNode builderType) { - if (useGuavaInstead(builderType)) { - return guavaMapSingularizer.listMethodsToBeGenerated(data, builderType); - } - return super.listMethodsToBeGenerated(data, builderType); } @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) { - if (useGuavaInstead(builderType)) { - return guavaMapSingularizer.generateFields(data, builderType, source); - } - JavacTreeMaker maker = builderType.getTreeMaker(); JCVariableDecl buildKeyField; { @@ -99,11 +95,6 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override public void generateMethods(SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker) { - if (useGuavaInstead(builderType)) { - guavaMapSingularizer.generateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); - return; - } - doGenerateMethods(data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker); } @@ -176,11 +167,6 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { - if (useGuavaInstead(builderType)) { - guavaMapSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName, builderVariable); - return; - } - JavacTreeMaker maker = builderType.getTreeMaker(); if (data.getTargetFqn().equals("java.util.Map")) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java index 71a36c0e..22d74896 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java @@ -41,11 +41,6 @@ public class JavacJavaUtilSetSingularizer extends JavacJavaUtilListSetSingulariz } @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { - if (useGuavaInstead(builderType)) { - guavaListSetSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName, builderVariable); - return; - } - JavacTreeMaker maker = builderType.getTreeMaker(); if (data.getTargetFqn().equals("java.util.Set")) { |