mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 22:17:41 +00:00
added j.u.List support for eclipse for @Singular @Builder.
This commit is contained in:
1 parent
a05360a8ea
commit
06f3629803
12 files changed
+492
-253
No files matched your search
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package lombok.eclipse.handlers.singulars;
|
||||
|
||||
import static lombok.eclipse.Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.core.handlers.HandlerUtil;
|
||||
import lombok.eclipse.EclipseNode;
|
||||
import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData;
|
||||
|
||||
import org.eclipse.jdt.internal.compiler.ast.Argument;
|
||||
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Expression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ReturnStatement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Statement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
|
||||
|
||||
abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingularizer {
|
||||
@Override public List<EclipseNode> generateFields(SingularData data, EclipseNode builderType) {
|
||||
TypeReference type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS);
|
||||
type = addTypeArgs(1, false, builderType, type, data.getTypeArgs());
|
||||
|
||||
FieldDeclaration buildField = new FieldDeclaration(data.getPluralName(), 0, -1);
|
||||
buildField.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
buildField.modifiers = ClassFileConstants.AccPrivate;
|
||||
buildField.declarationSourceEnd = -1;
|
||||
buildField.type = type;
|
||||
return Collections.singletonList(injectField(builderType, buildField));
|
||||
}
|
||||
|
||||
@Override public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) {
|
||||
TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
|
||||
Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
|
||||
generateSingularMethod(returnType, returnStatement, data, builderType, fluent);
|
||||
|
||||
returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
|
||||
returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
|
||||
generatePluralMethod(returnType, returnStatement, data, builderType, fluent);
|
||||
}
|
||||
|
||||
void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
|
||||
MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
|
||||
md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
md.modifiers = ClassFileConstants.AccPublic;
|
||||
|
||||
List<Statement> statements = new ArrayList<Statement>();
|
||||
statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));
|
||||
|
||||
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
|
||||
thisDotField.receiver = new ThisReference(0, 0);
|
||||
MessageSend thisDotFieldDotAdd = new MessageSend();
|
||||
thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(data.getSingularName(), 0L)};
|
||||
thisDotFieldDotAdd.receiver = thisDotField;
|
||||
thisDotFieldDotAdd.selector = "add".toCharArray();
|
||||
statements.add(thisDotFieldDotAdd);
|
||||
if (returnStatement != null) statements.add(returnStatement);
|
||||
|
||||
md.statements = statements.toArray(new Statement[statements.size()]);
|
||||
TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType);
|
||||
Argument param = new Argument(data.getSingularName(), 0, paramType, 0);
|
||||
md.arguments = new Argument[] {param};
|
||||
md.returnType = returnType;
|
||||
md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray();
|
||||
|
||||
injectMethod(builderType, md);
|
||||
}
|
||||
|
||||
void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
|
||||
MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
|
||||
md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
md.modifiers = ClassFileConstants.AccPublic;
|
||||
|
||||
List<Statement> statements = new ArrayList<Statement>();
|
||||
statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));
|
||||
|
||||
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
|
||||
thisDotField.receiver = new ThisReference(0, 0);
|
||||
MessageSend thisDotFieldDotAddAll = new MessageSend();
|
||||
thisDotFieldDotAddAll.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)};
|
||||
thisDotFieldDotAddAll.receiver = thisDotField;
|
||||
thisDotFieldDotAddAll.selector = "addAll".toCharArray();
|
||||
statements.add(thisDotFieldDotAddAll);
|
||||
if (returnStatement != null) statements.add(returnStatement);
|
||||
|
||||
md.statements = statements.toArray(new Statement[statements.size()]);
|
||||
|
||||
TypeReference paramType = new QualifiedTypeReference(TypeConstants.JAVA_UTIL_COLLECTION, NULL_POSS);
|
||||
paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs());
|
||||
Argument param = new Argument(data.getPluralName(), 0, paramType, 0);
|
||||
md.arguments = new Argument[] {param};
|
||||
md.returnType = returnType;
|
||||
md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray();
|
||||
|
||||
injectMethod(builderType, md);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package lombok.eclipse.handlers.singulars;
|
||||
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.makeIntLiteral;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.core.LombokImmutableList;
|
||||
import lombok.eclipse.EclipseNode;
|
||||
import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer;
|
||||
import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData;
|
||||
|
||||
import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Assignment;
|
||||
import org.eclipse.jdt.internal.compiler.ast.BreakStatement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Expression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
|
||||
import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Statement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.SwitchStatement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
|
||||
@ProviderFor(EclipseSingularizer.class)
|
||||
public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingularizer {
|
||||
@Override public LombokImmutableList<String> getSupportedTypes() {
|
||||
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.util.Iterable");
|
||||
}
|
||||
|
||||
@Override public void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName) {
|
||||
List<Statement> switchContents = new ArrayList<Statement>();
|
||||
|
||||
/* case 0: (empty) break; */ {
|
||||
switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'0'}, null), 0, 0));
|
||||
MessageSend invoke = new MessageSend();
|
||||
invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0);
|
||||
invoke.selector = "emptyList".toCharArray();
|
||||
switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0));
|
||||
switchContents.add(new BreakStatement(null, 0, 0));
|
||||
}
|
||||
|
||||
/* case 1: (singleton) break; */ {
|
||||
switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'1'}, null), 0, 0));
|
||||
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
|
||||
thisDotField.receiver = new ThisReference(0, 0);
|
||||
MessageSend thisDotFieldGet0 = new MessageSend();
|
||||
thisDotFieldGet0.receiver = thisDotField;
|
||||
thisDotFieldGet0.selector = new char[] {'g', 'e', 't'};
|
||||
thisDotFieldGet0.arguments = new Expression[] {makeIntLiteral(new char[] {'0'}, null)};
|
||||
|
||||
Expression[] args = new Expression[] {thisDotFieldGet0};
|
||||
MessageSend invoke = new MessageSend();
|
||||
invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0);
|
||||
invoke.selector = "singletonList".toCharArray();
|
||||
invoke.arguments = args;
|
||||
switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0));
|
||||
switchContents.add(new BreakStatement(null, 0, 0));
|
||||
}
|
||||
|
||||
/* default: Create with right size, then add all */ {
|
||||
switchContents.add(new CaseStatement(null, 0, 0));
|
||||
|
||||
/* pluralName = new j.u.ArrayList<Generics>(this.pluralName.size()); */ {
|
||||
Expression[] args = new Expression[] {getSize(builderType, data.getPluralName(), false)};
|
||||
TypeReference targetTypeExpr = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS);
|
||||
targetTypeExpr = addTypeArgs(1, false, builderType, targetTypeExpr, data.getTypeArgs());
|
||||
AllocationExpression constructorCall = new AllocationExpression();
|
||||
constructorCall.type = targetTypeExpr;
|
||||
constructorCall.arguments = args;
|
||||
switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0L), constructorCall, 0));
|
||||
}
|
||||
|
||||
/* pluralname.addAll(this.pluralname); */ {
|
||||
FieldReference thisDotPluralName = new FieldReference(data.getPluralName(), 0L);
|
||||
thisDotPluralName.receiver = new ThisReference(0, 0);
|
||||
MessageSend addAllInvoke = new MessageSend();
|
||||
addAllInvoke.receiver = new SingleNameReference(data.getPluralName(), 0L);
|
||||
addAllInvoke.selector = new char[] { 'a', 'd', 'd', 'A', 'l', 'l' };
|
||||
addAllInvoke.arguments = new Expression[] {thisDotPluralName};
|
||||
switchContents.add(addAllInvoke);
|
||||
}
|
||||
|
||||
/* pluralname = Collections.unmodifiableList(pluralname); */ {
|
||||
MessageSend unmodInvoke = new MessageSend();
|
||||
unmodInvoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0);
|
||||
unmodInvoke.selector = "unmodifiableList".toCharArray();
|
||||
unmodInvoke.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)};
|
||||
switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), unmodInvoke, 0));
|
||||
}
|
||||
}
|
||||
|
||||
SwitchStatement switchStat = new SwitchStatement();
|
||||
switchStat.statements = switchContents.toArray(new Statement[switchContents.size()]);
|
||||
switchStat.expression = getSize(builderType, data.getPluralName(), true);
|
||||
|
||||
TypeReference localShadowerType = new QualifiedTypeReference(JAVA_UTIL_LIST, NULL_POSS);
|
||||
localShadowerType = addTypeArgs(1, false, builderType, localShadowerType, data.getTypeArgs());
|
||||
LocalDeclaration varDefStat = new LocalDeclaration(data.getPluralName(), 0, 0);
|
||||
varDefStat.type = localShadowerType;
|
||||
statements.add(varDefStat);
|
||||
statements.add(switchStat);
|
||||
}
|
||||
}
|
||||
@@ -21,121 +21,22 @@
|
||||
*/
|
||||
package lombok.eclipse.handlers.singulars;
|
||||
|
||||
import static lombok.eclipse.Eclipse.*;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.core.LombokImmutableList;
|
||||
import lombok.core.handlers.HandlerUtil;
|
||||
import lombok.eclipse.EclipseNode;
|
||||
import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer;
|
||||
import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData;
|
||||
|
||||
import org.eclipse.jdt.internal.compiler.ast.Argument;
|
||||
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Expression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ReturnStatement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Statement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
@ProviderFor(EclipseSingularizer.class)
|
||||
public class EclipseJavaUtilSetSingularizer extends EclipseJavaUtilSingularizer {
|
||||
public class EclipseJavaUtilSetSingularizer extends EclipseJavaUtilListSetSingularizer {
|
||||
@Override public LombokImmutableList<String> getSupportedTypes() {
|
||||
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet");
|
||||
}
|
||||
|
||||
@Override public List<EclipseNode> generateFields(SingularData data, EclipseNode builderType) {
|
||||
TypeReference type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS);
|
||||
type = addTypeArgs(1, false, builderType, type, data.getTypeArgs());
|
||||
|
||||
FieldDeclaration buildField = new FieldDeclaration(data.getPluralName(), 0, -1);
|
||||
buildField.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
buildField.modifiers = ClassFileConstants.AccPrivate;
|
||||
buildField.declarationSourceEnd = -1;
|
||||
buildField.type = type;
|
||||
return Collections.singletonList(injectField(builderType, buildField));
|
||||
}
|
||||
|
||||
@Override public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) {
|
||||
TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
|
||||
Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
|
||||
generateSingularMethod(returnType, returnStatement, data, builderType, fluent);
|
||||
|
||||
returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
|
||||
returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
|
||||
generatePluralMethod(returnType, returnStatement, data, builderType, fluent);
|
||||
}
|
||||
|
||||
private void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
|
||||
MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
|
||||
md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
md.modifiers = ClassFileConstants.AccPublic;
|
||||
|
||||
List<Statement> statements = new ArrayList<Statement>();
|
||||
statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));
|
||||
|
||||
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
|
||||
thisDotField.receiver = new ThisReference(0, 0);
|
||||
MessageSend thisDotFieldDotAdd = new MessageSend();
|
||||
thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(data.getSingularName(), 0L)};
|
||||
thisDotFieldDotAdd.receiver = thisDotField;
|
||||
thisDotFieldDotAdd.selector = "add".toCharArray();
|
||||
statements.add(thisDotFieldDotAdd);
|
||||
if (returnStatement != null) statements.add(returnStatement);
|
||||
|
||||
md.statements = statements.toArray(new Statement[statements.size()]);
|
||||
TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType);
|
||||
Argument param = new Argument(data.getSingularName(), 0, paramType, 0);
|
||||
md.arguments = new Argument[] {param};
|
||||
md.returnType = returnType;
|
||||
md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray();
|
||||
|
||||
injectMethod(builderType, md);
|
||||
}
|
||||
|
||||
private void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
|
||||
MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
|
||||
md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
md.modifiers = ClassFileConstants.AccPublic;
|
||||
|
||||
List<Statement> statements = new ArrayList<Statement>();
|
||||
statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));
|
||||
|
||||
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
|
||||
thisDotField.receiver = new ThisReference(0, 0);
|
||||
MessageSend thisDotFieldDotAddAll = new MessageSend();
|
||||
thisDotFieldDotAddAll.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)};
|
||||
thisDotFieldDotAddAll.receiver = thisDotField;
|
||||
thisDotFieldDotAddAll.selector = "addAll".toCharArray();
|
||||
statements.add(thisDotFieldDotAddAll);
|
||||
if (returnStatement != null) statements.add(returnStatement);
|
||||
|
||||
md.statements = statements.toArray(new Statement[statements.size()]);
|
||||
|
||||
TypeReference paramType = new QualifiedTypeReference(TypeConstants.JAVA_UTIL_COLLECTION, NULL_POSS);
|
||||
paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs());
|
||||
Argument param = new Argument(data.getPluralName(), 0, paramType, 0);
|
||||
md.arguments = new Argument[] {param};
|
||||
md.returnType = returnType;
|
||||
md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray();
|
||||
|
||||
injectMethod(builderType, md);
|
||||
}
|
||||
|
||||
@Override public void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName) {
|
||||
if (data.getTargetFqn().equals("java.util.Set")) {
|
||||
statements.addAll(createJavaUtilSetMapInitialCapacitySwitchStatements(data, builderType, false, "emptySet", "singleton", "LinkedHashSet"));
|
||||
|
||||
@@ -66,6 +66,10 @@ abstract class EclipseJavaUtilSingularizer extends EclipseSingularizer {
|
||||
{'j', 'a', 'v', 'a'}, {'u', 't', 'i', 'l'}, {'A', 'r', 'r', 'a', 'y', 'L', 'i', 's', 't'}
|
||||
};
|
||||
|
||||
protected static final char[][] JAVA_UTIL_LIST = {
|
||||
{'j', 'a', 'v', 'a'}, {'u', 't', 'i', 'l'}, {'L', 'i', 's', 't'}
|
||||
};
|
||||
|
||||
protected static final char[][] JAVA_UTIL_MAP = {
|
||||
{'j', 'a', 'v', 'a'}, {'u', 't', 'i', 'l'}, {'M', 'a', 'p'}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package lombok.javac.handlers.singulars;
|
||||
|
||||
import static lombok.javac.Javac.*;
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import lombok.core.handlers.HandlerUtil;
|
||||
import lombok.javac.JavacNode;
|
||||
import lombok.javac.JavacTreeMaker;
|
||||
import lombok.javac.handlers.JavacHandlerUtil;
|
||||
import lombok.javac.handlers.JavacSingularsRecipes.SingularData;
|
||||
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCBlock;
|
||||
import com.sun.tools.javac.tree.JCTree.JCExpression;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCModifiers;
|
||||
import com.sun.tools.javac.tree.JCTree.JCStatement;
|
||||
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
|
||||
abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularizer {
|
||||
@Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) {
|
||||
JavacTreeMaker maker = builderType.getTreeMaker();
|
||||
JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList");
|
||||
type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source);
|
||||
|
||||
JCVariableDecl buildField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), data.getPluralName(), type, null);
|
||||
return Collections.singletonList(injectField(builderType, buildField));
|
||||
}
|
||||
|
||||
@Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
|
||||
JavacTreeMaker maker = builderType.getTreeMaker();
|
||||
Name thisName = builderType.toName("this");
|
||||
|
||||
JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
|
||||
JCStatement returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
|
||||
generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
|
||||
|
||||
returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
|
||||
returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
|
||||
generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
|
||||
}
|
||||
|
||||
void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
|
||||
List<JCTypeParameter> typeParams = List.nil();
|
||||
List<JCExpression> thrown = List.nil();
|
||||
|
||||
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
|
||||
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
|
||||
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
|
||||
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add");
|
||||
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getSingularName())));
|
||||
statements.append(maker.Exec(invokeAdd));
|
||||
if (returnStatement != null) statements.append(returnStatement);
|
||||
JCBlock body = maker.Block(0, statements.toList());
|
||||
Name name = data.getSingularName();
|
||||
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);
|
||||
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
|
||||
injectMethod(builderType, method);
|
||||
}
|
||||
|
||||
void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
|
||||
List<JCTypeParameter> typeParams = List.nil();
|
||||
List<JCExpression> thrown = List.nil();
|
||||
|
||||
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
|
||||
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
|
||||
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
|
||||
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll");
|
||||
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName())));
|
||||
statements.append(maker.Exec(invokeAdd));
|
||||
if (returnStatement != null) statements.append(returnStatement);
|
||||
JCBlock body = maker.Block(0, statements.toList());
|
||||
Name name = data.getPluralName();
|
||||
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
|
||||
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString()));
|
||||
JCExpression paramType = chainDots(builderType, "java", "util", "Collection");
|
||||
paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source);
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null);
|
||||
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
|
||||
injectMethod(builderType, method);
|
||||
}
|
||||
}
|
||||
@@ -24,100 +24,28 @@ package lombok.javac.handlers.singulars;
|
||||
import static lombok.javac.Javac.*;
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
import lombok.core.LombokImmutableList;
|
||||
import lombok.core.handlers.HandlerUtil;
|
||||
import lombok.javac.JavacNode;
|
||||
import lombok.javac.JavacTreeMaker;
|
||||
import lombok.javac.handlers.JavacHandlerUtil;
|
||||
import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer;
|
||||
import lombok.javac.handlers.JavacSingularsRecipes.SingularData;
|
||||
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCBlock;
|
||||
import com.sun.tools.javac.tree.JCTree.JCCase;
|
||||
import com.sun.tools.javac.tree.JCTree.JCExpression;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCModifiers;
|
||||
import com.sun.tools.javac.tree.JCTree.JCStatement;
|
||||
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
|
||||
@ProviderFor(JavacSingularizer.class)
|
||||
public class JavacJavaUtilListSingularizer extends JavacJavaUtilSingularizer {
|
||||
public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingularizer {
|
||||
@Override public LombokImmutableList<String> getSupportedTypes() {
|
||||
return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.util.Iterable");
|
||||
}
|
||||
|
||||
@Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) {
|
||||
JavacTreeMaker maker = builderType.getTreeMaker();
|
||||
JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList");
|
||||
type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source);
|
||||
|
||||
JCVariableDecl buildField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), data.getPluralName(), type, null);
|
||||
return Collections.singletonList(injectField(builderType, buildField));
|
||||
}
|
||||
|
||||
@Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
|
||||
JavacTreeMaker maker = builderType.getTreeMaker();
|
||||
JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
|
||||
JCStatement returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
|
||||
generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
|
||||
|
||||
returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
|
||||
returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
|
||||
generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
|
||||
}
|
||||
|
||||
private void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
|
||||
List<JCTypeParameter> typeParams = List.nil();
|
||||
List<JCExpression> thrown = List.nil();
|
||||
|
||||
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
|
||||
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
|
||||
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
|
||||
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add");
|
||||
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getSingularName())));
|
||||
statements.append(maker.Exec(invokeAdd));
|
||||
if (returnStatement != null) statements.append(returnStatement);
|
||||
JCBlock body = maker.Block(0, statements.toList());
|
||||
Name name = data.getSingularName();
|
||||
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);
|
||||
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
|
||||
injectMethod(builderType, method);
|
||||
}
|
||||
|
||||
private void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
|
||||
List<JCTypeParameter> typeParams = List.nil();
|
||||
List<JCExpression> thrown = List.nil();
|
||||
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
|
||||
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
|
||||
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
|
||||
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll");
|
||||
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName())));
|
||||
statements.append(maker.Exec(invokeAdd));
|
||||
if (returnStatement != null) statements.append(returnStatement);
|
||||
JCBlock body = maker.Block(0, statements.toList());
|
||||
Name name = data.getPluralName();
|
||||
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
|
||||
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString()));
|
||||
JCExpression paramType = chainDots(builderType, "java", "util", "Collection");
|
||||
paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source);
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null);
|
||||
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
|
||||
injectMethod(builderType, method);
|
||||
}
|
||||
|
||||
@Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) {
|
||||
JavacTreeMaker maker = builderType.getTreeMaker();
|
||||
List<JCExpression> jceBlank = List.nil();
|
||||
|
||||
@@ -21,103 +21,25 @@
|
||||
*/
|
||||
package lombok.javac.handlers.singulars;
|
||||
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
import lombok.core.LombokImmutableList;
|
||||
import lombok.core.handlers.HandlerUtil;
|
||||
import static lombok.javac.Javac.*;
|
||||
import lombok.javac.JavacNode;
|
||||
import lombok.javac.JavacTreeMaker;
|
||||
import lombok.javac.handlers.JavacHandlerUtil;
|
||||
import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer;
|
||||
import lombok.javac.handlers.JavacSingularsRecipes.SingularData;
|
||||
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCBlock;
|
||||
import com.sun.tools.javac.tree.JCTree.JCExpression;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCModifiers;
|
||||
import com.sun.tools.javac.tree.JCTree.JCStatement;
|
||||
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
|
||||
@ProviderFor(JavacSingularizer.class)
|
||||
public class JavacJavaUtilSetSingularizer extends JavacJavaUtilSingularizer {
|
||||
public class JavacJavaUtilSetSingularizer extends JavacJavaUtilListSetSingularizer {
|
||||
@Override public LombokImmutableList<String> getSupportedTypes() {
|
||||
return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet");
|
||||
}
|
||||
|
||||
@Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) {
|
||||
JavacTreeMaker maker = builderType.getTreeMaker();
|
||||
JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList");
|
||||
type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source);
|
||||
|
||||
JCVariableDecl buildField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), data.getPluralName(), type, null);
|
||||
return Collections.singletonList(injectField(builderType, buildField));
|
||||
}
|
||||
|
||||
@Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
|
||||
JavacTreeMaker maker = builderType.getTreeMaker();
|
||||
Name thisName = builderType.toName("this");
|
||||
|
||||
JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
|
||||
JCStatement returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
|
||||
generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
|
||||
|
||||
returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
|
||||
returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
|
||||
generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
|
||||
}
|
||||
|
||||
private void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
|
||||
List<JCTypeParameter> typeParams = List.nil();
|
||||
List<JCExpression> thrown = List.nil();
|
||||
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
|
||||
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
|
||||
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
|
||||
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add");
|
||||
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getSingularName())));
|
||||
statements.append(maker.Exec(invokeAdd));
|
||||
if (returnStatement != null) statements.append(returnStatement);
|
||||
JCBlock body = maker.Block(0, statements.toList());
|
||||
Name name = data.getSingularName();
|
||||
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);
|
||||
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
|
||||
injectMethod(builderType, method);
|
||||
}
|
||||
|
||||
private void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
|
||||
List<JCTypeParameter> typeParams = List.nil();
|
||||
List<JCExpression> thrown = List.nil();
|
||||
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
|
||||
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
|
||||
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
|
||||
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll");
|
||||
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName())));
|
||||
statements.append(maker.Exec(invokeAdd));
|
||||
if (returnStatement != null) statements.append(returnStatement);
|
||||
JCBlock body = maker.Block(0, statements.toList());
|
||||
Name name = data.getPluralName();
|
||||
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
|
||||
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString()));
|
||||
JCExpression paramType = chainDots(builderType, "java", "util", "Collection");
|
||||
paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source);
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null);
|
||||
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
|
||||
injectMethod(builderType, method);
|
||||
}
|
||||
|
||||
@Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) {
|
||||
JavacTreeMaker maker = builderType.getTreeMaker();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import java.util.Collection;
|
||||
class BuilderSingletonLists<T> {
|
||||
private List<T> children;
|
||||
private Collection<? extends Number> scarves;
|
||||
@SuppressWarnings("all")
|
||||
private List rawList;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
BuilderSingletonLists(final List<T> children, final Collection<? extends Number> scarves, final List rawList) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import java.util.SortedMap;
|
||||
class BuilderSingletonMaps<K, V> {
|
||||
private Map<K, V> women;
|
||||
private SortedMap<K, ? extends Number> men;
|
||||
@SuppressWarnings("all")
|
||||
private Map rawMap;
|
||||
private Map<String, V> stringMap;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
|
||||
@@ -3,6 +3,7 @@ import java.util.SortedSet;
|
||||
class BuilderSingletonSets<T> {
|
||||
private Set<T> dangerMice;
|
||||
private SortedSet<? extends Number> octopodes;
|
||||
@SuppressWarnings("all")
|
||||
private Set rawSet;
|
||||
private Set<String> stringSet;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
import lombok.Singular;
|
||||
@lombok.Builder class BuilderSingletonLists<T> {
|
||||
public static @java.lang.SuppressWarnings("all") class BuilderSingletonListsBuilder<T> {
|
||||
private java.util.ArrayList<T> children;
|
||||
private java.util.ArrayList<Number> scarves;
|
||||
private java.util.ArrayList<java.lang.Object> rawList;
|
||||
@java.lang.SuppressWarnings("all") BuilderSingletonListsBuilder() {
|
||||
super();
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderSingletonListsBuilder<T> child(T child) {
|
||||
if ((this.children == null))
|
||||
this.children = new java.util.ArrayList<T>();
|
||||
this.children.add(child);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderSingletonListsBuilder<T> children(java.util.Collection<? extends T> children) {
|
||||
if ((this.children == null))
|
||||
this.children = new java.util.ArrayList<T>();
|
||||
this.children.addAll(children);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderSingletonListsBuilder<T> scarf(Number scarf) {
|
||||
if ((this.scarves == null))
|
||||
this.scarves = new java.util.ArrayList<Number>();
|
||||
this.scarves.add(scarf);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderSingletonListsBuilder<T> scarves(java.util.Collection<? extends Number> scarves) {
|
||||
if ((this.scarves == null))
|
||||
this.scarves = new java.util.ArrayList<Number>();
|
||||
this.scarves.addAll(scarves);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderSingletonListsBuilder<T> rawList(java.lang.Object rawList) {
|
||||
if ((this.rawList == null))
|
||||
this.rawList = new java.util.ArrayList<java.lang.Object>();
|
||||
this.rawList.add(rawList);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderSingletonListsBuilder<T> rawList(java.util.Collection<?> rawList) {
|
||||
if ((this.rawList == null))
|
||||
this.rawList = new java.util.ArrayList<java.lang.Object>();
|
||||
this.rawList.addAll(rawList);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderSingletonLists<T> build() {
|
||||
java.util.List<T> children;
|
||||
switch (((this.children == null) ? 0 : this.children.size())) {
|
||||
case 0 :
|
||||
children = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1 :
|
||||
children = java.util.Collections.singletonList(this.children.get(0));
|
||||
break;
|
||||
default :
|
||||
children = new java.util.ArrayList<T>(this.children.size());
|
||||
children.addAll(this.children);
|
||||
children = java.util.Collections.unmodifiableList(children);
|
||||
}
|
||||
java.util.List<Number> scarves;
|
||||
switch (((this.scarves == null) ? 0 : this.scarves.size())) {
|
||||
case 0 :
|
||||
scarves = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1 :
|
||||
scarves = java.util.Collections.singletonList(this.scarves.get(0));
|
||||
break;
|
||||
default :
|
||||
scarves = new java.util.ArrayList<Number>(this.scarves.size());
|
||||
scarves.addAll(this.scarves);
|
||||
scarves = java.util.Collections.unmodifiableList(scarves);
|
||||
}
|
||||
java.util.List<java.lang.Object> rawList;
|
||||
switch (((this.rawList == null) ? 0 : this.rawList.size())) {
|
||||
case 0 :
|
||||
rawList = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1 :
|
||||
rawList = java.util.Collections.singletonList(this.rawList.get(0));
|
||||
break;
|
||||
default :
|
||||
rawList = new java.util.ArrayList<java.lang.Object>(this.rawList.size());
|
||||
rawList.addAll(this.rawList);
|
||||
rawList = java.util.Collections.unmodifiableList(rawList);
|
||||
}
|
||||
return new BuilderSingletonLists<T>(children, scarves, rawList);
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (((((("BuilderSingletonLists.BuilderSingletonListsBuilder(children=" + this.children) + ", scarves=") + this.scarves) + ", rawList=") + this.rawList) + ")");
|
||||
}
|
||||
}
|
||||
private @Singular List<T> children;
|
||||
private @Singular Collection<? extends Number> scarves;
|
||||
private @SuppressWarnings("all") @Singular("rawList") List rawList;
|
||||
@java.lang.SuppressWarnings("all") BuilderSingletonLists(final List<T> children, final Collection<? extends Number> scarves, final List rawList) {
|
||||
super();
|
||||
this.children = children;
|
||||
this.scarves = scarves;
|
||||
this.rawList = rawList;
|
||||
}
|
||||
public static @java.lang.SuppressWarnings("all") <T>BuilderSingletonListsBuilder<T> builder() {
|
||||
return new BuilderSingletonListsBuilder<T>();
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,5 @@ import lombok.Singular;
|
||||
class BuilderSingletonLists<T> {
|
||||
@Singular private List<T> children;
|
||||
@Singular private Collection<? extends Number> scarves;
|
||||
@Singular("rawList") private List rawList;
|
||||
@SuppressWarnings("all") @Singular("rawList") private List rawList;
|
||||
}
|
||||
Reference in new issue
Block a user