Search in sources :

Example 6 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference in project lombok by rzwitserloot.

the class EclipseGuavaSingularizer method generateMethods.

@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);
    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateClearMethod(returnType, returnStatement, data, builderType);
}
Also used : ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference)

Example 7 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference in project lombok by rzwitserloot.

the class EclipseJavaUtilListSetSingularizer 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, 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();
    data.setGeneratedByRecursive(md);
    injectMethod(builderType, md);
}
Also used : MessageSend(org.eclipse.jdt.internal.compiler.ast.MessageSend) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) Argument(org.eclipse.jdt.internal.compiler.ast.Argument) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) SingleNameReference(org.eclipse.jdt.internal.compiler.ast.SingleNameReference)

Example 8 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference in project lombok by rzwitserloot.

the class EclipseJavaUtilListSetSingularizer method generateSingularMethod.

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();
    data.setGeneratedByRecursive(md);
    injectMethod(builderType, md);
}
Also used : MessageSend(org.eclipse.jdt.internal.compiler.ast.MessageSend) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) Argument(org.eclipse.jdt.internal.compiler.ast.Argument) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) SingleNameReference(org.eclipse.jdt.internal.compiler.ast.SingleNameReference)

Example 9 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference in project lombok by rzwitserloot.

the class EclipseJavaUtilMapSingularizer method generatePluralMethod.

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;
    String pN = new String(data.getPluralName());
    char[] keyFieldName = (pN + "$key").toCharArray();
    char[] valueFieldName = (pN + "$value").toCharArray();
    List<Statement> statements = new ArrayList<Statement>();
    statements.add(createConstructBuilderVarIfNeeded(data, builderType, true));
    char[] entryName = "$lombokEntry".toCharArray();
    TypeReference forEachType = new QualifiedTypeReference(JAVA_UTIL_MAP_ENTRY, NULL_POSS);
    forEachType = addTypeArgs(2, true, builderType, forEachType, data.getTypeArgs());
    MessageSend keyArg = new MessageSend();
    keyArg.receiver = new SingleNameReference(entryName, 0L);
    keyArg.selector = "getKey".toCharArray();
    MessageSend addKey = new MessageSend();
    FieldReference thisDotKeyField = new FieldReference(keyFieldName, 0L);
    thisDotKeyField.receiver = new ThisReference(0, 0);
    addKey.receiver = thisDotKeyField;
    addKey.selector = new char[] { 'a', 'd', 'd' };
    addKey.arguments = new Expression[] { keyArg };
    MessageSend valueArg = new MessageSend();
    valueArg.receiver = new SingleNameReference(entryName, 0L);
    valueArg.selector = "getValue".toCharArray();
    MessageSend addValue = new MessageSend();
    FieldReference thisDotValueField = new FieldReference(valueFieldName, 0L);
    thisDotValueField.receiver = new ThisReference(0, 0);
    addValue.receiver = thisDotValueField;
    addValue.selector = new char[] { 'a', 'd', 'd' };
    addValue.arguments = new Expression[] { valueArg };
    LocalDeclaration elementVariable = new LocalDeclaration(entryName, 0, 0);
    elementVariable.type = forEachType;
    ForeachStatement forEach = new ForeachStatement(elementVariable, 0);
    MessageSend invokeEntrySet = new MessageSend();
    invokeEntrySet.selector = new char[] { 'e', 'n', 't', 'r', 'y', 'S', 'e', 't' };
    invokeEntrySet.receiver = new SingleNameReference(data.getPluralName(), 0L);
    forEach.collection = invokeEntrySet;
    Block forEachContent = new Block(0);
    forEachContent.statements = new Statement[] { addKey, addValue };
    forEach.action = forEachContent;
    statements.add(forEach);
    if (returnStatement != null)
        statements.add(returnStatement);
    md.statements = statements.toArray(new Statement[statements.size()]);
    TypeReference paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS);
    paramType = addTypeArgs(2, 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("putAll", new String(data.getPluralName())).toCharArray();
    data.setGeneratedByRecursive(md);
    injectMethod(builderType, md);
}
Also used : LocalDeclaration(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) Argument(org.eclipse.jdt.internal.compiler.ast.Argument) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) ForeachStatement(org.eclipse.jdt.internal.compiler.ast.ForeachStatement) ArrayList(java.util.ArrayList) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) SingleNameReference(org.eclipse.jdt.internal.compiler.ast.SingleNameReference) MessageSend(org.eclipse.jdt.internal.compiler.ast.MessageSend) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) Block(org.eclipse.jdt.internal.compiler.ast.Block) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ForeachStatement(org.eclipse.jdt.internal.compiler.ast.ForeachStatement)

Example 10 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference in project lombok by rzwitserloot.

the class EclipseJavaUtilMapSingularizer method generateMethods.

@Override
public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) {
    if (useGuavaInstead(builderType)) {
        guavaMapSingularizer.generateMethods(data, builderType, fluent, chain);
        return;
    }
    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);
    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateClearMethod(returnType, returnStatement, data, builderType);
}
Also used : ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) ForeachStatement(org.eclipse.jdt.internal.compiler.ast.ForeachStatement) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference)

Aggregations

ThisReference (org.eclipse.jdt.internal.compiler.ast.ThisReference)29 Statement (org.eclipse.jdt.internal.compiler.ast.Statement)23 FieldReference (org.eclipse.jdt.internal.compiler.ast.FieldReference)21 IfStatement (org.eclipse.jdt.internal.compiler.ast.IfStatement)19 MessageSend (org.eclipse.jdt.internal.compiler.ast.MessageSend)19 ReturnStatement (org.eclipse.jdt.internal.compiler.ast.ReturnStatement)19 SingleNameReference (org.eclipse.jdt.internal.compiler.ast.SingleNameReference)18 MethodDeclaration (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)17 ArrayList (java.util.ArrayList)16 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)16 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)16 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)16 EqualExpression (org.eclipse.jdt.internal.compiler.ast.EqualExpression)11 AllocationExpression (org.eclipse.jdt.internal.compiler.ast.AllocationExpression)10 Argument (org.eclipse.jdt.internal.compiler.ast.Argument)10 Assignment (org.eclipse.jdt.internal.compiler.ast.Assignment)10 NullLiteral (org.eclipse.jdt.internal.compiler.ast.NullLiteral)8 QualifiedNameReference (org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference)8 EclipseNode (lombok.eclipse.EclipseNode)7 ConditionalExpression (org.eclipse.jdt.internal.compiler.ast.ConditionalExpression)7