Search in sources :

Example 6 with ConditionalExpression

use of org.eclipse.jdt.internal.compiler.ast.ConditionalExpression 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)

Aggregations

ConditionalExpression (org.eclipse.jdt.internal.compiler.ast.ConditionalExpression)6 EqualExpression (org.eclipse.jdt.internal.compiler.ast.EqualExpression)6 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)6 LocalDeclaration (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)5 MessageSend (org.eclipse.jdt.internal.compiler.ast.MessageSend)5 NullLiteral (org.eclipse.jdt.internal.compiler.ast.NullLiteral)5 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)5 SingleNameReference (org.eclipse.jdt.internal.compiler.ast.SingleNameReference)5 Statement (org.eclipse.jdt.internal.compiler.ast.Statement)5 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)5 BinaryExpression (org.eclipse.jdt.internal.compiler.ast.BinaryExpression)4 IfStatement (org.eclipse.jdt.internal.compiler.ast.IfStatement)4 ReturnStatement (org.eclipse.jdt.internal.compiler.ast.ReturnStatement)4 ThisReference (org.eclipse.jdt.internal.compiler.ast.ThisReference)4 ArrayList (java.util.ArrayList)3 EclipseNode (lombok.eclipse.EclipseNode)3 AllocationExpression (org.eclipse.jdt.internal.compiler.ast.AllocationExpression)3 CastExpression (org.eclipse.jdt.internal.compiler.ast.CastExpression)3 MethodDeclaration (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)3 ParameterizedQualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference)3