Search in sources :

Example 21 with FieldReference

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

Example 22 with FieldReference

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

the class PatchExtensionMethodCompletionProposal method getFirstParameterType.

static TypeBinding getFirstParameterType(TypeDeclaration decl, CompletionProposalCollector completionProposalCollector) {
    TypeBinding firstParameterType = null;
    ASTNode node = getAssistNode(completionProposalCollector);
    if (node == null)
        return null;
    if (!(node instanceof CompletionOnQualifiedNameReference) && !(node instanceof CompletionOnSingleNameReference) && !(node instanceof CompletionOnMemberAccess))
        return null;
    // Never offer on 'super.<autocomplete>'.
    if (node instanceof FieldReference && ((FieldReference) node).receiver instanceof SuperReference)
        return null;
    if (node instanceof NameReference) {
        Binding binding = ((NameReference) node).binding;
        /*			if ((node instanceof SingleNameReference) && (((SingleNameReference) node).token.length == 0)) {
				firstParameterType = decl.binding;
			} else */
        if (binding instanceof VariableBinding) {
            firstParameterType = ((VariableBinding) binding).type;
        }
    } else if (node instanceof FieldReference) {
        firstParameterType = ((FieldReference) node).actualReceiverType;
    }
    return firstParameterType;
}
Also used : Binding(org.eclipse.jdt.internal.compiler.lookup.Binding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) VariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding) CompletionOnQualifiedNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedNameReference) NameReference(org.eclipse.jdt.internal.compiler.ast.NameReference) CompletionOnSingleNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference) CompletionOnMemberAccess(org.eclipse.jdt.internal.codeassist.complete.CompletionOnMemberAccess) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) ASTNode(org.eclipse.jdt.internal.compiler.ast.ASTNode) CompletionOnSingleNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference) CompletionOnQualifiedNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedNameReference) VariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding) SuperReference(org.eclipse.jdt.internal.compiler.ast.SuperReference)

Aggregations

FieldReference (org.eclipse.jdt.internal.compiler.ast.FieldReference)22 ThisReference (org.eclipse.jdt.internal.compiler.ast.ThisReference)21 MessageSend (org.eclipse.jdt.internal.compiler.ast.MessageSend)16 Statement (org.eclipse.jdt.internal.compiler.ast.Statement)16 IfStatement (org.eclipse.jdt.internal.compiler.ast.IfStatement)15 MethodDeclaration (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)13 ReturnStatement (org.eclipse.jdt.internal.compiler.ast.ReturnStatement)13 SingleNameReference (org.eclipse.jdt.internal.compiler.ast.SingleNameReference)13 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)12 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)12 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)12 ArrayList (java.util.ArrayList)11 Assignment (org.eclipse.jdt.internal.compiler.ast.Assignment)9 EqualExpression (org.eclipse.jdt.internal.compiler.ast.EqualExpression)9 AllocationExpression (org.eclipse.jdt.internal.compiler.ast.AllocationExpression)8 Argument (org.eclipse.jdt.internal.compiler.ast.Argument)7 NullLiteral (org.eclipse.jdt.internal.compiler.ast.NullLiteral)7 QualifiedNameReference (org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference)6 ConditionalExpression (org.eclipse.jdt.internal.compiler.ast.ConditionalExpression)5 LocalDeclaration (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)5