aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java9
-rw-r--r--src/core/lombok/javac/handlers/JavacSingularsRecipes.java26
2 files changed, 28 insertions, 7 deletions
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index da40692e..f199f161 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -180,7 +180,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
bfd.builderFieldName = bfd.name;
bfd.annotations = findCopyableAnnotations(fieldNode);
bfd.type = fd.vartype;
- bfd.singularData = getSingularData(fieldNode);
+ bfd.singularData = getSingularData(fieldNode, builderInstance.setterPrefix());
bfd.originalFieldNode = fieldNode;
if (bfd.singularData != null && isDefault != null) {
@@ -369,7 +369,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
bfd.rawName = raw.name;
bfd.annotations = findCopyableAnnotations(param);
bfd.type = raw.vartype;
- bfd.singularData = getSingularData(param);
+ bfd.singularData = getSingularData(param, builderInstance.setterPrefix());
bfd.originalFieldNode = param;
addObtainVia(bfd, param);
builderFields.add(bfd);
@@ -876,8 +876,9 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
* or parameter), or null if there's no {@code @Singular} annotation on it.
*
* @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation.
+ * @param setterPrefix
*/
- private SingularData getSingularData(JavacNode node) {
+ private SingularData getSingularData(JavacNode node, final String setterPrefix) {
for (JavacNode child : node.down()) {
if (!annotationTypeMatches(Singular.class, child)) continue;
Name pluralName = node.getKind() == Kind.FIELD ? removePrefixFromField(node) : ((JCVariableDecl) node.get()).name;
@@ -919,7 +920,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
return null;
}
- return new SingularData(child, singularName, pluralName, typeArgs, targetFqn, singularizer);
+ return new SingularData(child, singularName, pluralName, typeArgs, targetFqn, singularizer, setterPrefix);
}
return null;
diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
index 341d44df..f693af83 100644
--- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
+++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java
@@ -117,6 +117,7 @@ public class JavacSingularsRecipes {
private final List<JCExpression> typeArgs;
private final String targetFqn;
private final JavacSingularizer singularizer;
+ private final String setterPrefix;
public SingularData(JavacNode annotation, Name singularName, Name pluralName, List<JCExpression> typeArgs, String targetFqn, JavacSingularizer singularizer) {
this.annotation = annotation;
@@ -125,6 +126,17 @@ public class JavacSingularsRecipes {
this.typeArgs = typeArgs;
this.targetFqn = targetFqn;
this.singularizer = singularizer;
+ this.setterPrefix = null;
+ }
+
+ public SingularData(JavacNode annotation, Name singularName, Name pluralName, List<JCExpression> typeArgs, String targetFqn, JavacSingularizer singularizer, String setterPrefix) {
+ this.annotation = annotation;
+ this.singularName = singularName;
+ this.pluralName = pluralName;
+ this.typeArgs = typeArgs;
+ this.targetFqn = targetFqn;
+ this.singularizer = singularizer;
+ this.setterPrefix = setterPrefix;
}
public JavacNode getAnnotation() {
@@ -138,6 +150,8 @@ public class JavacSingularsRecipes {
public Name getPluralName() {
return pluralName;
}
+
+ public String getSetterPrefix() { return setterPrefix; }
public List<JCExpression> getTypeArgs() {
return typeArgs;
@@ -279,8 +293,12 @@ public class JavacSingularsRecipes {
ListBuffer<JCStatement> statements = generateSingularMethodStatements(maker, data, builderType, source);
List<JCVariableDecl> params = generateSingularMethodParameters(maker, data, builderType, source);
Name name = data.getSingularName();
- if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(), name.toString()));
-
+ Name prefixedSingularName = data.getSetterPrefix().length() == 0 ? name :
+ builderType.toName(HandlerUtil.buildAccessorName(data.getSetterPrefix(), name.toString()));
+
+ name = fluent ? prefixedSingularName : builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName(),
+ name.toString()));
+
statements.prepend(createConstructBuilderVarIfNeeded(maker, data, builderType, source));
finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, params, access);
}
@@ -307,7 +325,9 @@ public class JavacSingularsRecipes {
private void generatePluralMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, AccessLevel access) {
ListBuffer<JCStatement> statements = generatePluralMethodStatements(maker, data, builderType, source);
Name name = data.getPluralName();
- if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName(getAddMethodName() + "All", name.toString()));
+ Name prefixedSingularName = builderType.toName(data.getSetterPrefix());
+ name = fluent ? prefixedSingularName : builderType.toName(HandlerUtil.buildAccessorName(
+ getAddMethodName() + "All", name.toString()));
JCExpression paramType = getPluralMethodParamType(builderType);
paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source);
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());