*/
public final boolean canBeSeenByForCodeSnippet(FieldBinding fieldBinding, TypeBinding receiverType, InvocationSite invocationSite, Scope scope) {
if (fieldBinding.isPublic()) return true;
ReferenceBinding invocationType = (ReferenceBinding) receiverType;
if (invocationType == fieldBinding.declaringClass) return true;
if (fieldBinding.isProtected()) {
// answer true if the invocationType is the declaringClass or they are in the same package
// OR the invocationType is a subclass of the declaringClass
// AND the receiverType is the invocationType or its subclass
// OR the field is a static field accessed directly through a type
if (invocationType == fieldBinding.declaringClass) return true;
if (invocationType.fPackage == fieldBinding.declaringClass.fPackage) return true;
if (fieldBinding.declaringClass.isSuperclassOf(invocationType)) {
if (invocationSite.isSuperAccess()) return true;
// receiverType can be an array binding in one case... see if you can change it
if (receiverType instanceof ArrayBinding)
return false;
if (invocationType.isSuperclassOf((ReferenceBinding) receiverType))
return true;
if (fieldBinding.isStatic())
return true; // see 1FMEPDL - return invocationSite.isTypeAccess();
}
return false;
}
if (fieldBinding.isPrivate()) {
// answer true if the receiverType is the declaringClass
// AND the invocationType and the declaringClass have a common enclosingType
if (receiverType != fieldBinding.declaringClass) return false;
if (invocationType != fieldBinding.declaringClass) {
ReferenceBinding outerInvocationType = invocationType;
ReferenceBinding temp = outerInvocationType.enclosingType();
while (temp != null) {
outerInvocationType = temp;
temp = temp.enclosingType();
}
ReferenceBinding outerDeclaringClass = fieldBinding.declaringClass;
temp = outerDeclaringClass.enclosingType();
while (temp != null) {
outerDeclaringClass = temp;
temp = temp.enclosingType();
}
if (outerInvocationType != outerDeclaringClass) return false;
}
return true;
}
// isDefault()
if (invocationType.fPackage != fieldBinding.declaringClass.fPackage) return false;
// receiverType can be an array binding in one case... see if you can change it
if (receiverType instanceof ArrayBinding)
return false;
ReferenceBinding type = (ReferenceBinding) receiverType;
PackageBinding declaringPackage = fieldBinding.declaringClass.fPackage;
TypeBinding originalDeclaringClass = fieldBinding.declaringClass .original();
do {
if (type.isCapture()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002
if (originalDeclaringClass == type.erasure().original()) return true;
} else {
if (originalDeclaringClass == type.original()) return true;
}
if (declaringPackage != type.fPackage) return false;
} while ((type = type.superclass()) != null);
return false;
}