Search in sources :

Example 1 with VariableBinding

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

Example 2 with VariableBinding

use of org.eclipse.jdt.internal.compiler.lookup.VariableBinding in project spoon by INRIA.

the class JDTTreeBuilder method visit.

@Override
public boolean visit(SingleNameReference singleNameReference, BlockScope scope) {
    if (singleNameReference.binding instanceof FieldBinding) {
        context.enter(helper.createFieldAccess(singleNameReference), singleNameReference);
    } else if (singleNameReference.binding instanceof VariableBinding) {
        context.enter(helper.createVariableAccess(singleNameReference), singleNameReference);
    } else if (singleNameReference.binding instanceof TypeBinding) {
        context.enter(factory.Code().createTypeAccessWithoutCloningReference(references.getTypeReference((TypeBinding) singleNameReference.binding)), singleNameReference);
    } else if (singleNameReference.binding instanceof ProblemBinding) {
        if (context.stack.peek().element instanceof CtInvocation && Character.isUpperCase(CharOperation.charToString(singleNameReference.token).charAt(0))) {
            context.enter(helper.createTypeAccessNoClasspath(singleNameReference), singleNameReference);
        } else {
            context.enter(helper.createFieldAccessNoClasspath(singleNameReference), singleNameReference);
        }
    } else if (singleNameReference.binding == null) {
        CtExpression access = helper.createVariableAccessNoClasspath(singleNameReference);
        if (access == null) {
            access = helper.createTypeAccessNoClasspath(singleNameReference);
        }
        context.enter(access, singleNameReference);
    }
    return true;
}
Also used : CtInvocation(spoon.reflect.code.CtInvocation) CtExpression(spoon.reflect.code.CtExpression) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) FieldBinding(org.eclipse.jdt.internal.compiler.lookup.FieldBinding) VariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding) ProblemBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemBinding)

Example 3 with VariableBinding

use of org.eclipse.jdt.internal.compiler.lookup.VariableBinding in project spoon by INRIA.

the class JDTTreeBuilderHelper method createVariableAccess.

/**
 * Creates a variable or a field access from its qualified name.
 *
 * @param qualifiedNameReference
 * 		Used to build the variable access. See all sub methods of this class to understand its usage.
 * @return a variable access.
 */
<T> CtVariableAccess<T> createVariableAccess(QualifiedNameReference qualifiedNameReference) {
    long[] positions = qualifiedNameReference.sourcePositions;
    int sourceStart = qualifiedNameReference.sourceStart();
    int sourceEnd = qualifiedNameReference.sourceEnd();
    if (qualifiedNameReference.indexOfFirstFieldBinding < positions.length) {
        sourceEnd = (int) (positions[qualifiedNameReference.indexOfFirstFieldBinding] >>> 32) - 2;
    }
    CtVariableAccess<T> va;
    CtVariableReference<T> ref;
    boolean fromAssignment = isLhsAssignment(jdtTreeBuilder.getContextBuilder(), qualifiedNameReference);
    boolean isOtherBinding = qualifiedNameReference.otherBindings == null || qualifiedNameReference.otherBindings.length == 0;
    if (qualifiedNameReference.binding instanceof FieldBinding) {
        ref = jdtTreeBuilder.getReferencesBuilder().getVariableReference(qualifiedNameReference.fieldBinding());
        ref.setPosition(jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
        va = createFieldAccess(ref, createTargetFieldAccess(qualifiedNameReference, (CtFieldReference<Object>) ref), isOtherBinding && fromAssignment);
    } else {
        ref = jdtTreeBuilder.getReferencesBuilder().getVariableReference((VariableBinding) qualifiedNameReference.binding);
        ref.setPosition(jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
        va = createVariableAccess(ref, isOtherBinding && fromAssignment);
    }
    ref.setPosition(jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
    if (qualifiedNameReference.otherBindings != null) {
        // positions index;
        int i = 0;
        va.setPosition(ref.getPosition());
        sourceStart = (int) (positions[qualifiedNameReference.indexOfFirstFieldBinding - 1] >>> 32);
        for (FieldBinding b : qualifiedNameReference.otherBindings) {
            isOtherBinding = qualifiedNameReference.otherBindings.length == i + 1;
            CtFieldAccess<T> other = createFieldAccess(jdtTreeBuilder.getReferencesBuilder().<T>getVariableReference(b, qualifiedNameReference.tokens[i + 1]), va, isOtherBinding && fromAssignment);
            // set source position of fa
            if (i + qualifiedNameReference.indexOfFirstFieldBinding >= qualifiedNameReference.otherBindings.length) {
                sourceEnd = qualifiedNameReference.sourceEnd();
            } else {
                sourceEnd = (int) (positions[qualifiedNameReference.indexOfFirstFieldBinding + i + 1] >>> 32) - 2;
            }
            other.setPosition(jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
            va = other;
            i++;
        }
    } else if (!(qualifiedNameReference.binding instanceof FieldBinding) && qualifiedNameReference.tokens.length > 1) {
        sourceStart = (int) (positions[0] >>> 32);
        for (int i = 1; i < qualifiedNameReference.tokens.length; i++) {
            isOtherBinding = qualifiedNameReference.tokens.length == i + 1;
            CtFieldAccess<T> other = createFieldAccess(jdtTreeBuilder.getReferencesBuilder().<T>getVariableReference(null, qualifiedNameReference.tokens[i]), va, isOtherBinding && fromAssignment);
            // set source position of va;
            sourceEnd = (int) (positions[i]);
            va.setPosition(jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
            va = other;
        }
    }
    va.setPosition(jdtTreeBuilder.getPositionBuilder().buildPosition(qualifiedNameReference.sourceStart(), qualifiedNameReference.sourceEnd()));
    return va;
}
Also used : CtFieldAccess(spoon.reflect.code.CtFieldAccess) FieldBinding(org.eclipse.jdt.internal.compiler.lookup.FieldBinding) VariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding)

Aggregations

VariableBinding (org.eclipse.jdt.internal.compiler.lookup.VariableBinding)3 FieldBinding (org.eclipse.jdt.internal.compiler.lookup.FieldBinding)2 TypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeBinding)2 CompletionOnMemberAccess (org.eclipse.jdt.internal.codeassist.complete.CompletionOnMemberAccess)1 CompletionOnQualifiedNameReference (org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedNameReference)1 CompletionOnSingleNameReference (org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference)1 ASTNode (org.eclipse.jdt.internal.compiler.ast.ASTNode)1 FieldReference (org.eclipse.jdt.internal.compiler.ast.FieldReference)1 NameReference (org.eclipse.jdt.internal.compiler.ast.NameReference)1 SuperReference (org.eclipse.jdt.internal.compiler.ast.SuperReference)1 Binding (org.eclipse.jdt.internal.compiler.lookup.Binding)1 MethodBinding (org.eclipse.jdt.internal.compiler.lookup.MethodBinding)1 ProblemBinding (org.eclipse.jdt.internal.compiler.lookup.ProblemBinding)1 CtExpression (spoon.reflect.code.CtExpression)1 CtFieldAccess (spoon.reflect.code.CtFieldAccess)1 CtInvocation (spoon.reflect.code.CtInvocation)1