Search in sources :

Example 1 with ProblemBinding

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

the class JDTTreeBuilderHelper method createFieldAccessNoClasspath.

/**
 * In no classpath mode, when we build a field access, we have a binding typed by ProblemBinding.
 * We try to get all information we can get from this binding.
 *
 * @param qualifiedNameReference
 * 		Used to get the problem binding of the field access and the name of the declaring type.
 * @return a field access.
 */
<T> CtFieldAccess<T> createFieldAccessNoClasspath(QualifiedNameReference qualifiedNameReference) {
    boolean fromAssignment = isLhsAssignment(jdtTreeBuilder.getContextBuilder(), qualifiedNameReference);
    CtFieldAccess<T> fieldAccess = createFieldAccess(jdtTreeBuilder.getReferencesBuilder().<T>getVariableReference((ProblemBinding) qualifiedNameReference.binding), null, fromAssignment);
    // In no classpath mode and with qualified name, the type given by JDT is wrong...
    final char[][] declaringClass = CharOperation.subarray(qualifiedNameReference.tokens, 0, qualifiedNameReference.tokens.length - 1);
    final MissingTypeBinding declaringType = jdtTreeBuilder.getContextBuilder().compilationunitdeclaration.scope.environment.createMissingType(null, declaringClass);
    final CtTypeReference<T> declaringRef = jdtTreeBuilder.getReferencesBuilder().getTypeReference(declaringType);
    fieldAccess.getVariable().setDeclaringType(declaringRef);
    fieldAccess.getVariable().setStatic(true);
    fieldAccess.setTarget(jdtTreeBuilder.getFactory().Code().createTypeAccess(declaringRef));
    // In no classpath mode and with qualified name, the binding don't have a good name.
    fieldAccess.getVariable().setSimpleName(createQualifiedTypeName(CharOperation.subarray(qualifiedNameReference.tokens, qualifiedNameReference.tokens.length - 1, qualifiedNameReference.tokens.length)));
    return fieldAccess;
}
Also used : MissingTypeBinding(org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding) ProblemBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemBinding)

Example 2 with ProblemBinding

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

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

the class JDTTreeBuilderHelper method createFieldAccessNoClasspath.

/**
 * In no classpath mode, when we build a field access, we have a binding typed by ProblemBinding.
 * This binding doesn't contain all information but we can get some of them.
 *
 * @param singleNameReference
 * 		Used to get the problem binding of the field access and the name of the declaring type.
 * @return a field access.
 */
<T> CtFieldAccess<T> createFieldAccessNoClasspath(SingleNameReference singleNameReference) {
    CtFieldAccess<T> va;
    if (isLhsAssignment(jdtTreeBuilder.getContextBuilder(), singleNameReference)) {
        va = jdtTreeBuilder.getFactory().Core().createFieldWrite();
    } else {
        va = jdtTreeBuilder.getFactory().Core().createFieldRead();
    }
    va.setVariable(jdtTreeBuilder.getReferencesBuilder().<T>getVariableReference((ProblemBinding) singleNameReference.binding));
    final CtReference declaring = jdtTreeBuilder.getReferencesBuilder().getDeclaringReferenceFromImports(singleNameReference.token);
    if (declaring instanceof CtTypeReference && va.getVariable() != null) {
        final CtTypeReference<Object> declaringRef = (CtTypeReference<Object>) declaring;
        va.setTarget(jdtTreeBuilder.getFactory().Code().createTypeAccess(declaringRef));
        va.getVariable().setDeclaringType(declaringRef);
        va.getVariable().setStatic(true);
    }
    return va;
}
Also used : CtReference(spoon.reflect.reference.CtReference) CtTypeReference(spoon.reflect.reference.CtTypeReference) ProblemBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemBinding)

Aggregations

ProblemBinding (org.eclipse.jdt.internal.compiler.lookup.ProblemBinding)3 FieldBinding (org.eclipse.jdt.internal.compiler.lookup.FieldBinding)1 MissingTypeBinding (org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding)1 TypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeBinding)1 VariableBinding (org.eclipse.jdt.internal.compiler.lookup.VariableBinding)1 CtExpression (spoon.reflect.code.CtExpression)1 CtInvocation (spoon.reflect.code.CtInvocation)1 CtReference (spoon.reflect.reference.CtReference)1 CtTypeReference (spoon.reflect.reference.CtTypeReference)1