List of usage examples for org.eclipse.jdt.internal.compiler.lookup Scope getCurrentPackage
public final PackageBinding getCurrentPackage()
From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java
License:Open Source License
/** * Answer true if the receiver is visible to the type provided by the scope. *///from w w w . j a va2s . c o m public final boolean canBeSeenBy(Scope scope) { // GROOVY start if (scope.compilationUnitScope() != null && scope.compilationUnitScope().canSeeEverything()) { return true; } // GROOVY end if (isPublic()) return true; SourceTypeBinding invocationType = scope.enclosingSourceType(); if (invocationType == this) return true; if (invocationType == null) // static import call return !isPrivate() && scope.getCurrentPackage() == this.fPackage; if (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 invocationType is the invocationType or its subclass // OR the type is a static method accessed directly through a type // OR previous assertions are true for one of the enclosing type if (invocationType.fPackage == this.fPackage) return true; TypeBinding declaringClass = enclosingType(); // protected types always have an enclosing one if (declaringClass == null) return false; // could be null if incorrect top-level protected type declaringClass = declaringClass.erasure();// erasure cannot be null TypeBinding currentType = invocationType.erasure(); // int depth = 0; do { if (declaringClass == invocationType) return true; if (currentType.findSuperTypeOriginatingFrom(declaringClass) != null) return true; // depth++; currentType = currentType.enclosingType(); } while (currentType != null); return false; } if (isPrivate()) { // answer true if the receiver and the invocationType have a common enclosingType // already know they are not the identical type ReferenceBinding outerInvocationType = invocationType; ReferenceBinding temp = outerInvocationType.enclosingType(); while (temp != null) { outerInvocationType = temp; temp = temp.enclosingType(); } ReferenceBinding outerDeclaringClass = (ReferenceBinding) erasure(); temp = outerDeclaringClass.enclosingType(); while (temp != null) { outerDeclaringClass = temp; temp = temp.enclosingType(); } return outerInvocationType == outerDeclaringClass; } // isDefault() return invocationType.fPackage == this.fPackage; }