use of org.eclipse.jdt.internal.compiler.ast.MessageSend in project lombok by rzwitserloot.
the class EclipseGuavaSingularizer method generateSingularMethod.
void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
LombokImmutableList<String> suffixes = getArgumentSuffixes();
char[][] names = new char[suffixes.size()][];
for (int i = 0; i < suffixes.size(); i++) {
String s = suffixes.get(i);
char[] n = data.getSingularName();
names[i] = s.isEmpty() ? n : s.toCharArray();
}
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));
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
thisDotField.receiver = new ThisReference(0, 0);
MessageSend thisDotFieldDotAdd = new MessageSend();
thisDotFieldDotAdd.arguments = new Expression[suffixes.size()];
for (int i = 0; i < suffixes.size(); i++) {
thisDotFieldDotAdd.arguments[i] = new SingleNameReference(names[i], 0L);
}
thisDotFieldDotAdd.receiver = thisDotField;
thisDotFieldDotAdd.selector = getAddMethodName().toCharArray();
statements.add(thisDotFieldDotAdd);
if (returnStatement != null)
statements.add(returnStatement);
md.statements = statements.toArray(new Statement[statements.size()]);
md.arguments = new Argument[suffixes.size()];
for (int i = 0; i < suffixes.size(); i++) {
TypeReference tr = cloneParamType(i, data.getTypeArgs(), builderType);
md.arguments[i] = new Argument(names[i], 0, tr, 0);
}
md.returnType = returnType;
md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName(getAddMethodName(), new String(data.getSingularName())).toCharArray();
data.setGeneratedByRecursive(md);
injectMethod(builderType, md);
}
use of org.eclipse.jdt.internal.compiler.ast.MessageSend in project lombok by rzwitserloot.
the class EclipseGuavaSingularizer method appendBuildCode.
@Override
public void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName) {
TypeReference varType = new QualifiedTypeReference(fromQualifiedName(data.getTargetFqn()), NULL_POSS);
String simpleTypeName = getSimpleTargetTypeName(data);
int agrumentsCount = getTypeArgumentsCount();
varType = addTypeArgs(agrumentsCount, false, builderType, varType, data.getTypeArgs());
MessageSend emptyInvoke;
{
//ImmutableX.of()
emptyInvoke = new MessageSend();
emptyInvoke.selector = new char[] { 'o', 'f' };
emptyInvoke.receiver = new QualifiedNameReference(makeGuavaTypeName(simpleTypeName, false), NULL_POSS, 0, 0);
emptyInvoke.typeArguments = createTypeArgs(agrumentsCount, false, builderType, data.getTypeArgs());
}
MessageSend invokeBuild;
{
//this.pluralName.build();
invokeBuild = new MessageSend();
invokeBuild.selector = new char[] { 'b', 'u', 'i', 'l', 'd' };
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
thisDotField.receiver = new ThisReference(0, 0);
invokeBuild.receiver = thisDotField;
}
Expression isNull;
{
//this.pluralName == null
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
thisDotField.receiver = new ThisReference(0, 0);
isNull = new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL);
}
Expression init = new ConditionalExpression(isNull, emptyInvoke, invokeBuild);
LocalDeclaration varDefStat = new LocalDeclaration(data.getPluralName(), 0, 0);
varDefStat.type = varType;
varDefStat.initialization = init;
statements.add(varDefStat);
}
use of org.eclipse.jdt.internal.compiler.ast.MessageSend in project lombok by rzwitserloot.
the class EclipseGuavaSingularizer method generatePluralMethod.
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));
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 = (getAddMethodName() + "All").toCharArray();
statements.add(thisDotFieldDotAddAll);
if (returnStatement != null)
statements.add(returnStatement);
md.statements = statements.toArray(new Statement[statements.size()]);
TypeReference paramType;
paramType = new QualifiedTypeReference(fromQualifiedName(getAddAllTypeName()), NULL_POSS);
paramType = addTypeArgs(getTypeArgumentsCount(), 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(getAddMethodName() + "All", new String(data.getPluralName())).toCharArray();
data.setGeneratedByRecursive(md);
injectMethod(builderType, md);
}
use of org.eclipse.jdt.internal.compiler.ast.MessageSend in project lombok by rzwitserloot.
the class EclipseJavaUtilListSetSingularizer method generateClearMethod.
private void generateClearMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType) {
MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
md.modifiers = ClassFileConstants.AccPublic;
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
thisDotField.receiver = new ThisReference(0, 0);
FieldReference thisDotField2 = new FieldReference(data.getPluralName(), 0L);
thisDotField2.receiver = new ThisReference(0, 0);
md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
MessageSend clearMsg = new MessageSend();
clearMsg.receiver = thisDotField2;
clearMsg.selector = "clear".toCharArray();
Statement clearStatement = new IfStatement(new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.NOT_EQUAL), clearMsg, 0, 0);
md.statements = returnStatement != null ? new Statement[] { clearStatement, returnStatement } : new Statement[] { clearStatement };
md.returnType = returnType;
injectMethod(builderType, md);
}
use of org.eclipse.jdt.internal.compiler.ast.MessageSend in project lombok by rzwitserloot.
the class EclipseJavaUtilListSingularizer method appendBuildCode.
@Override
public void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName) {
if (useGuavaInstead(builderType)) {
guavaListSetSingularizer.appendBuildCode(data, builderType, statements, targetVariableName);
return;
}
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 by passing builder field to constructor. */
{
switchContents.add(new CaseStatement(null, 0, 0));
Expression argToUnmodifiable;
/* new j.u.ArrayList<Generics>(this.pluralName); */
{
FieldReference thisDotPluralName = new FieldReference(data.getPluralName(), 0L);
thisDotPluralName.receiver = new ThisReference(0, 0);
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 = new Expression[] { thisDotPluralName };
argToUnmodifiable = constructorCall;
}
/* pluralname = Collections.unmodifiableList(-newlist-); */
{
MessageSend unmodInvoke = new MessageSend();
unmodInvoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0);
unmodInvoke.selector = "unmodifiableList".toCharArray();
unmodInvoke.arguments = new Expression[] { argToUnmodifiable };
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(Eclipse.fromQualifiedName(data.getTargetFqn()), 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);
}
Aggregations