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