Search in sources :

Example 11 with IfStatement

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

the class EclipseJavaUtilSingularizer method createConstructBuilderVarIfNeeded.

protected Statement createConstructBuilderVarIfNeeded(SingularData data, EclipseNode builderType, boolean mapMode) {
    char[] v1Name, v2Name;
    if (mapMode) {
        String n = new String(data.getPluralName());
        v1Name = (n + "$key").toCharArray();
        v2Name = (n + "$value").toCharArray();
    } else {
        v1Name = data.getPluralName();
        v2Name = null;
    }
    FieldReference thisDotField = new FieldReference(v1Name, 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    Expression cond = new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL);
    thisDotField = new FieldReference(v1Name, 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    TypeReference v1Type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS);
    v1Type = addTypeArgs(1, false, builderType, v1Type, data.getTypeArgs());
    AllocationExpression constructArrayList = new AllocationExpression();
    constructArrayList.type = v1Type;
    Assignment initV1 = new Assignment(thisDotField, constructArrayList, 0);
    Statement thenPart;
    if (mapMode) {
        thisDotField = new FieldReference(v2Name, 0L);
        thisDotField.receiver = new ThisReference(0, 0);
        TypeReference v2Type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS);
        List<TypeReference> tArgs = data.getTypeArgs();
        if (tArgs != null && tArgs.size() > 1)
            tArgs = Collections.singletonList(tArgs.get(1));
        else
            tArgs = Collections.emptyList();
        v2Type = addTypeArgs(1, false, builderType, v2Type, tArgs);
        constructArrayList = new AllocationExpression();
        constructArrayList.type = v2Type;
        Assignment initV2 = new Assignment(thisDotField, constructArrayList, 0);
        Block b = new Block(0);
        b.statements = new Statement[] { initV1, initV2 };
        thenPart = b;
    } else {
        thenPart = initV1;
    }
    return new IfStatement(cond, thenPart, 0, 0);
}
Also used : FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) BreakStatement(org.eclipse.jdt.internal.compiler.ast.BreakStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) SwitchStatement(org.eclipse.jdt.internal.compiler.ast.SwitchStatement) ForStatement(org.eclipse.jdt.internal.compiler.ast.ForStatement) CaseStatement(org.eclipse.jdt.internal.compiler.ast.CaseStatement) EqualExpression(org.eclipse.jdt.internal.compiler.ast.EqualExpression) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) Assignment(org.eclipse.jdt.internal.compiler.ast.Assignment) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) ConditionalExpression(org.eclipse.jdt.internal.compiler.ast.ConditionalExpression) Expression(org.eclipse.jdt.internal.compiler.ast.Expression) AllocationExpression(org.eclipse.jdt.internal.compiler.ast.AllocationExpression) EqualExpression(org.eclipse.jdt.internal.compiler.ast.EqualExpression) PostfixExpression(org.eclipse.jdt.internal.compiler.ast.PostfixExpression) BinaryExpression(org.eclipse.jdt.internal.compiler.ast.BinaryExpression) AllocationExpression(org.eclipse.jdt.internal.compiler.ast.AllocationExpression) 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) NullLiteral(org.eclipse.jdt.internal.compiler.ast.NullLiteral)

Aggregations

IfStatement (org.eclipse.jdt.internal.compiler.ast.IfStatement)11 EqualExpression (org.eclipse.jdt.internal.compiler.ast.EqualExpression)10 MessageSend (org.eclipse.jdt.internal.compiler.ast.MessageSend)9 NullLiteral (org.eclipse.jdt.internal.compiler.ast.NullLiteral)9 Statement (org.eclipse.jdt.internal.compiler.ast.Statement)8 ThisReference (org.eclipse.jdt.internal.compiler.ast.ThisReference)7 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)6 FieldReference (org.eclipse.jdt.internal.compiler.ast.FieldReference)6 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)6 ReturnStatement (org.eclipse.jdt.internal.compiler.ast.ReturnStatement)6 SingleNameReference (org.eclipse.jdt.internal.compiler.ast.SingleNameReference)6 AllocationExpression (org.eclipse.jdt.internal.compiler.ast.AllocationExpression)5 Assignment (org.eclipse.jdt.internal.compiler.ast.Assignment)5 Block (org.eclipse.jdt.internal.compiler.ast.Block)5 ConditionalExpression (org.eclipse.jdt.internal.compiler.ast.ConditionalExpression)5 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)5 BinaryExpression (org.eclipse.jdt.internal.compiler.ast.BinaryExpression)4 LocalDeclaration (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)4 MethodDeclaration (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)4 ParameterizedQualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference)4