IMPORTANT NOTE: This method is written under the assumption that compoundName is longer than length 1.
*/
public Binding getBinding(char[][] compoundName, int mask, InvocationSite invocationSite, ReferenceBinding receiverType) {
Binding binding = getBinding(compoundName[0], mask | Binding.TYPE | Binding.PACKAGE, invocationSite, true /*resolve*/);
invocationSite.setFieldIndex(1);
if (!binding.isValidBinding() || binding instanceof VariableBinding)
return binding;
int length = compoundName.length;
int currentIndex = 1;
foundType: if (binding instanceof PackageBinding) {
PackageBinding packageBinding = (PackageBinding) binding;
while (currentIndex < length) {
binding = packageBinding.getTypeOrPackage(compoundName[currentIndex++]);
invocationSite.setFieldIndex(currentIndex);
if (binding == null) {
if (currentIndex == length) // must be a type if its the last name, otherwise we have no idea if its a package or type
return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null, ProblemReasons.NotFound);
else
return new ProblemBinding(CharOperation.subarray(compoundName, 0, currentIndex), ProblemReasons.NotFound);
}
if (binding instanceof ReferenceBinding) {
if (!binding.isValidBinding())
return new ProblemReferenceBinding(
CharOperation.subarray(compoundName, 0, currentIndex),
((ReferenceBinding)binding).closestMatch(),
binding.problemId());
if (!this.canBeSeenByForCodeSnippet((ReferenceBinding) binding, receiverType))
return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), (ReferenceBinding) binding, ProblemReasons.NotVisible);
break foundType;
}
packageBinding = (PackageBinding) binding;
}
// It is illegal to request a PACKAGE from this method.
return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null, ProblemReasons.NotFound);
}
// know binding is now a ReferenceBinding
while (currentIndex < length) {
ReferenceBinding typeBinding = (ReferenceBinding) binding;
char[] nextName = compoundName[currentIndex++];
invocationSite.setFieldIndex(currentIndex);
if ((binding = findFieldForCodeSnippet(typeBinding, nextName, invocationSite)) != null) {
if (!binding.isValidBinding()) {
return new ProblemFieldBinding(
(FieldBinding)binding,
((FieldBinding)binding).declaringClass,
CharOperation.concatWith(CharOperation.subarray(compoundName, 0, currentIndex), '.'),
binding.problemId());
}
break; // binding is now a field
}
if ((binding = findMemberType(nextName, typeBinding)) == null)
return new ProblemBinding(CharOperation.subarray(compoundName, 0, currentIndex), typeBinding, ProblemReasons.NotFound);
if (!binding.isValidBinding())
return new ProblemReferenceBinding(
CharOperation.subarray(compoundName, 0, currentIndex),
((ReferenceBinding)binding).closestMatch(),
binding.problemId());
}
if ((mask & Binding.FIELD) != 0 && (binding instanceof FieldBinding)) { // was looking for a field and found a field
FieldBinding field = (FieldBinding) binding;
if (!field.isStatic()) {