Search in sources :

Example 21 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference 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);
}
Also used : 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) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) SingleNameReference(org.eclipse.jdt.internal.compiler.ast.SingleNameReference) MessageSend(org.eclipse.jdt.internal.compiler.ast.MessageSend) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)

Example 22 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference 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);
}
Also used : LocalDeclaration(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) ConditionalExpression(org.eclipse.jdt.internal.compiler.ast.ConditionalExpression) EqualExpression(org.eclipse.jdt.internal.compiler.ast.EqualExpression) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) MessageSend(org.eclipse.jdt.internal.compiler.ast.MessageSend) ConditionalExpression(org.eclipse.jdt.internal.compiler.ast.ConditionalExpression) Expression(org.eclipse.jdt.internal.compiler.ast.Expression) EqualExpression(org.eclipse.jdt.internal.compiler.ast.EqualExpression) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) NullLiteral(org.eclipse.jdt.internal.compiler.ast.NullLiteral) QualifiedNameReference(org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference)

Example 23 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference 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);
}
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 24 with ThisReference

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

the class EclipseJavaUtilListSetSingularizer method generateMethods.

@Override
public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) {
    if (useGuavaInstead(builderType)) {
        guavaListSetSingularizer.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) 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 25 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference 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);
}
Also used : MessageSend(org.eclipse.jdt.internal.compiler.ast.MessageSend) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) 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) EqualExpression(org.eclipse.jdt.internal.compiler.ast.EqualExpression) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) NullLiteral(org.eclipse.jdt.internal.compiler.ast.NullLiteral)

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