/** * Returns if the given {@link IJavaElement} is externally visible <br> * <br> * Changes to the logic here must also be made in the {@link TagValidator} to ensure the * visibility is computed equally. * * @see TagValidator * @param element * @return <code>true</code> if the given element is visible <code>false</code> otherwise * @throws JavaModelException if a model lookup fails */ boolean isVisible(IJavaElement element) throws JavaModelException { if (element != null) { switch (element.getElementType()) { case IJavaElement.FIELD: case IJavaElement.METHOD: { IMember member = (IMember) element; int flags = member.getFlags(); IType type = member.getDeclaringType(); if (Flags.isPublic(flags) || Flags.isProtected(flags) || (type != null && type.isInterface())) { return isVisible(type); } break; } case IJavaElement.TYPE: { IType type = (IType) element; int flags = type.getFlags(); if (type.isLocal() && !type.isAnonymous() || Flags.isPrivate(flags)) { return false; } if (type.isMember()) { if ((Flags.isPublic(flags) && Flags.isStatic(flags)) || Flags.isPublic(flags) || Flags.isProtected(flags) || type.isInterface()) { return isVisible(type.getDeclaringType()); } } else { return Flags.isPublic(flags) || type.isInterface(); } break; } default: { break; } } } return false; }
protected static final boolean isStatic(IMember member) throws JavaModelException { return Flags.isStatic(member.getFlags()); }