List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding isSuperclassOf
public boolean isSuperclassOf(ReferenceBinding otherType)
From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java
License:Open Source License
/** * Answer true if the receiver type can be assigned to the argument type (right) *//* w w w .j av a2 s . c o m*/ private boolean isCompatibleWith0(TypeBinding otherType) { if (otherType == this) return true; if (otherType.id == TypeIds.T_JavaLangObject) return true; // equivalence may allow compatibility with array type through wildcard // bound if (isEquivalentTo(otherType)) return true; switch (otherType.kind()) { case Binding.WILDCARD_TYPE: case Binding.INTERSECTION_TYPE: return false; // should have passed equivalence check above if // wildcard case Binding.TYPE_PARAMETER: // check compatibility with capture of ? super X if (otherType.isCapture()) { CaptureBinding otherCapture = (CaptureBinding) otherType; TypeBinding otherLowerBound; if ((otherLowerBound = otherCapture.lowerBound) != null) { if (otherLowerBound.isArrayType()) return false; return isCompatibleWith(otherLowerBound); } } //$FALL-THROUGH$ case Binding.GENERIC_TYPE: case Binding.TYPE: case Binding.PARAMETERIZED_TYPE: case Binding.RAW_TYPE: switch (kind()) { case Binding.GENERIC_TYPE: case Binding.PARAMETERIZED_TYPE: case Binding.RAW_TYPE: if (erasure() == otherType.erasure()) return false; // should have passed equivalence check // above if same erasure } ReferenceBinding otherReferenceType = (ReferenceBinding) otherType; if (otherReferenceType.isInterface()) // could be annotation type return implementsInterface(otherReferenceType, true); if (isInterface()) // Explicit conversion from an interface // to a class is not allowed return false; return otherReferenceType.isSuperclassOf(this); default: return false; } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.Protections.java
License:Open Source License
/** * Visibility control for role fields/methods. The public case is already handled outside. *///from ww w.j a v a 2s . c o m public static boolean canBeSeenBy(IProtectable binding, TypeBinding receiverType, InvocationSite invocationSite, Scope scope) { // never legal for non-public features: if (RoleTypeBinding.isRoleWithExplicitAnchor(receiverType)) return false; // callin methods are not subject to visibility control: if ((binding.modifiers() & ExtraCompilerModifiers.AccCallin) != 0) return true; ReferenceBinding declaringClass = (ReferenceBinding) binding.getDeclaringClass().getRealClass().erasure(); ReferenceBinding invocationType = scope.enclosingSourceType(); // special privilege for tsuper calls: if (invocationSite instanceof TSuperMessageSend && invocationType.isRole()) { // check all tsupers, but not mixing with explicit supers if (invocationType.roleModel.hasTSuperRole(declaringClass)) return true; } if (binding.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 method is a static method accessed directly through a type // OR previous assertions are true for one of the enclosing type if (TypeBinding.equalsEquals(invocationType, declaringClass)) return true; // instead of package investigate the enclosing team. if (receiverType instanceof ReferenceBinding) { // strengthen all role types relative to the receiver type. ReferenceBinding receiver = (ReferenceBinding) receiverType; declaringClass = (ReferenceBinding) TeamModel.strengthenRoleType(receiver, declaringClass); if (invocationType.isRole()) invocationType = (ReferenceBinding) TeamModel.strengthenRoleType(receiver, invocationType); } // START orig code from FieldBinding: ReferenceBinding currentType = invocationType; int depth = 0; do { /*OT:*/ if (TeamModel.isTeamContainingRole(currentType, declaringClass)) /*OT:*/ return true; if (declaringClass.isSuperclassOf(currentType)) { 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 (binding.isStatic()) { if (depth > 0) invocationSite.setDepth(depth); return true; // see 1FMEPDL - return invocationSite.isTypeAccess(); } if (TypeBinding.equalsEquals(currentType, receiverType) || currentType.isSuperclassOf((ReferenceBinding) receiverType)) { if (depth > 0) invocationSite.setDepth(depth); return true; } } depth++; currentType = currentType.enclosingType(); } while (currentType != null); return false; } // END orig code // default and private can be accessed from any nested class: // only invocationType is allowed to be nested within declaringClass, // not vice versa: ReferenceBinding currentInvocationType = invocationType; while (currentInvocationType != null) { if (TypeBinding.equalsEquals(currentInvocationType, declaringClass)) return true; currentInvocationType = currentInvocationType.enclosingType(); } // no more hope for private if (binding.isPrivate()) return false; // default visibility (similar to FieldBinding.canBeSeenBy, whith less emphasis on packages): // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; // have access to all super features: // (implicit inheritance is already dealt with by copy inheritance ;-) ) if (invocationSite.isSuperAccess()) invocationType = invocationType.superclass(); ReferenceBinding currentType = (ReferenceBinding) (invocationType.isInterface() ? ((ReferenceBinding) receiverType).getRealType().erasure() : ((ReferenceBinding) receiverType).getRealClass().erasure()); PackageBinding declaringPackage = declaringClass.fPackage; do { if (TypeBinding.equalsEquals(invocationType, currentType)) return true; if (!currentType.isRole() // when leaving team contexts ... && declaringPackage != currentType.fPackage) // ... compare the packages instead. return false; } while ((currentType = currentType.superclass()) != null); return false; }