final char[][] tokens = qualifiedNameReference.tokens;
int indexOfFirstFieldBinding = qualifiedNameReference.indexOfFirstFieldBinding; // one-based
if (index < indexOfFirstFieldBinding) {
// an extra lookup is required
BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name);
Binding binding = null;
try {
if (internalScope == null) {
if (this.scope == null) return null;
binding = this.scope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index));
} else {
binding = internalScope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index));
}
} catch (AbortCompilation e) {
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
}
if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
} else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
// it is a type
return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
}
} else if (index == indexOfFirstFieldBinding) {
if (qualifiedNameReference.isTypeReference()) {
return this.getTypeBinding(qualifiedNameReference.resolvedType);
} else {
Binding binding = qualifiedNameReference.binding;
if (binding != null) {
if (binding.isValidBinding()) {
return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding);
} else if (binding instanceof ProblemFieldBinding) {
ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding;
switch(problemFieldBinding.problemId()) {
case ProblemReasons.NotVisible :
case ProblemReasons.NonStaticReferenceInStaticContext :
ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
if (declaringClass != null) {
FieldBinding exactBinding = declaringClass.getField(tokens[tokens.length - 1], true /*resolve*/);
if (exactBinding != null) {
if (exactBinding.type != null) {
IVariableBinding variableBinding = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
if (variableBinding != null) {
return variableBinding;
}
variableBinding = new VariableBinding(this, exactBinding);
this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding);
return variableBinding;
}
}
}
break;
}
}
}
}
} else {
/* This is the case for a name which is part of a qualified name that
* cannot be resolved. See PR 13063.
*/
if (qualifiedNameReference.otherBindings == null || (index - indexOfFirstFieldBinding - 1) < 0) {
return null;
} else {
return this.getVariableBinding(qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding - 1]);
}
}
} else if (node instanceof QualifiedTypeReference) {
QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) node;
if (qualifiedTypeReference.resolvedType == null) {
return null;
}
if (index == qualifiedTypeReference.tokens.length) {
if (!qualifiedTypeReference.resolvedType.isValidBinding() && qualifiedTypeReference instanceof JavadocQualifiedTypeReference) {
JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) node;
if (typeRef.packageBinding != null) {
return getPackageBinding(typeRef.packageBinding);
}
}
return this.getTypeBinding(qualifiedTypeReference.resolvedType.leafComponentType());
} else {
if (index >= 0) {
BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name);
Binding binding = null;
try {
if (internalScope == null) {
if (this.scope == null) return null;
binding = this.scope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
} else {
binding = internalScope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
}
} catch (AbortCompilation e) {
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
}
if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
} else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
// it is a type
return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
} else {
return null;
}
}
}
} else if (node instanceof ImportReference) {
ImportReference importReference = (ImportReference) node;
int importReferenceLength = importReference.tokens.length;
if (index >= 0) {
Binding binding = null;
if (this.scope == null) return null;
if (importReferenceLength == index) {
try {
binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), (importReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OnDemand) != 0, importReference.isStatic());
} catch (AbortCompilation e) {
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
}
} else {
try {
binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true, importReference.isStatic());
} catch (AbortCompilation e) {
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
}
}
if (binding != null) {
if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
} else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
// it is a type
return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
} else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) {
// it is a type
return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding)binding);
} else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) {
// it is a type
return getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding)binding);
} else {
return null;
}
}
}
} else if (node instanceof CompilationUnitDeclaration) {
CompilationUnitDeclaration compilationUnitDeclaration = (CompilationUnitDeclaration) node;
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
if (types == null || types.length == 0) {
return null;
}
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration type = types[0];
if (type != null) {
ITypeBinding typeBinding = this.getTypeBinding(type.binding);
if (typeBinding != null) {
return typeBinding.getPackage();
}
}
} else if (node instanceof AbstractMethodDeclaration) {
AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
IMethodBinding methodBinding = getMethodBinding(methodDeclaration.binding);
if (methodBinding != null) {
return methodBinding;
}
} else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
if (typeBinding != null) {
return typeBinding;
}
} if (node instanceof SingleNameReference) {
SingleNameReference singleNameReference = (SingleNameReference) node;
if (singleNameReference.isTypeReference()) {
return this.getTypeBinding(singleNameReference.resolvedType);
} else {
// this is a variable or a field
Binding binding = singleNameReference.binding;
if (binding != null) {
if (binding.isValidBinding()) {
return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding);
} else {
/*
* http://dev.eclipse.org/bugs/show_bug.cgi?id=24449
*/
if (binding instanceof ProblemFieldBinding) {
ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding;
switch(problemFieldBinding.problemId()) {
case ProblemReasons.NotVisible :
case ProblemReasons.NonStaticReferenceInStaticContext :
case ProblemReasons.NonStaticReferenceInConstructorInvocation :
ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
if (exactBinding != null) {
if (exactBinding.type != null) {
IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
if (variableBinding2 != null) {
return variableBinding2;
}
variableBinding2 = new VariableBinding(this, exactBinding);
this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding2);
return variableBinding2;
}
}
break;
}
}
}
}
}
} else if (node instanceof QualifiedSuperReference) {
QualifiedSuperReference qualifiedSuperReference = (QualifiedSuperReference) node;
return this.getTypeBinding(qualifiedSuperReference.qualification.resolvedType);
} else if (node instanceof LocalDeclaration) {
return this.getVariableBinding(((LocalDeclaration)node).binding);
} else if (node instanceof JavadocFieldReference) {
JavadocFieldReference fieldRef = (JavadocFieldReference) node;
if (fieldRef.methodBinding != null) {
return getMethodBinding(fieldRef.methodBinding);
}
return getVariableBinding(fieldRef.binding);
} else if (node instanceof FieldReference) {
return getVariableBinding(((FieldReference) node).binding);
} else if (node instanceof SingleTypeReference) {
if (node instanceof JavadocSingleTypeReference) {
JavadocSingleTypeReference typeRef = (JavadocSingleTypeReference) node;
if (typeRef.packageBinding != null) {
return getPackageBinding(typeRef.packageBinding);
}
}
SingleTypeReference singleTypeReference = (SingleTypeReference) node;
org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = singleTypeReference.resolvedType;
if (binding == null) {
return null;
}
return this.getTypeBinding(binding.leafComponentType());
} else if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
return this.getVariableBinding(fieldDeclaration.binding);
} else if (node instanceof MessageSend) {
MessageSend messageSend = (MessageSend) node;