/* * This method is different from Binding.isSuperType as type declarations are compared */ private static boolean isInSuperTypeHierarchy( ITypeBinding possibleSuperTypeDecl, ITypeBinding type) { if (type == possibleSuperTypeDecl) { return true; } ITypeBinding superClass = type.getSuperclass(); if (superClass != null) { if (isInSuperTypeHierarchy(possibleSuperTypeDecl, superClass.getTypeDeclaration())) { return true; } } if (possibleSuperTypeDecl.isInterface()) { ITypeBinding[] superInterfaces = type.getInterfaces(); for (int i = 0; i < superInterfaces.length; i++) { if (isInSuperTypeHierarchy( possibleSuperTypeDecl, superInterfaces[i].getTypeDeclaration())) { return true; } } } return false; }
/** * Evaluates if the declaration is visible in a certain context. * * @param binding The binding of the declaration to examine * @param context The context to test in * @return Returns */ public static boolean isVisible(IBinding binding, ITypeBinding context) { if (binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) { return true; // all local variables found are visible } ITypeBinding declaring = getDeclaringType(binding); if (declaring == null) { return false; } declaring = declaring.getTypeDeclaration(); int modifiers = binding.getModifiers(); if (Modifier.isPublic(modifiers) || declaring.isInterface()) { return true; } else if (Modifier.isProtected(modifiers) || !Modifier.isPrivate(modifiers)) { if (declaring.getPackage() == context.getPackage()) { return true; } return isTypeInScope(declaring, context, Modifier.isProtected(modifiers)); } // private visibility return isTypeInScope(declaring, context, false); }