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;
}
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;
}
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;
}
Aggregations