private static boolean typeNameExistsInEnclosingTypeChain(IType type, String typeName) {
   IType enclosing = type.getDeclaringType();
   while (enclosing != null) {
     if (enclosing.getElementName().equals(typeName)) return true;
     enclosing = enclosing.getDeclaringType();
   }
   return false;
 }
 /** Returns the type of the top-level declaring class used to find the source code */
 private IType getOuterMostEnclosingType() {
   IType type = getType();
   IType enclosingType = type.getDeclaringType();
   while (enclosingType != null) {
     type = enclosingType;
     enclosingType = type.getDeclaringType();
   }
   return type;
 }
    /** {@inheritDoc} */
    public Object[] getChildren(Object element) {
      // AspectJ Change begin
      if (element instanceof ICompilationUnit) {
        element = AJCompilationUnitManager.mapToAJCompilationUnit((ICompilationUnit) element);
      }
      // AspectJ Change end

      if (fShowOnlyMainType) {
        if (element instanceof ICompilationUnit) {
          element = getMainType((ICompilationUnit) element);
        } else if (element instanceof IClassFile) {
          element = getMainType((IClassFile) element);
        }

        if (element == null) return NO_CHILDREN;
      }

      if (fShowInheritedMembers && element instanceof IType) {
        IType type = (IType) element;
        if (type.getDeclaringType() == null) {
          ITypeHierarchy th = getSuperTypeHierarchy(type);
          if (th != null) {
            List children = new ArrayList();
            IType[] superClasses = th.getAllSupertypes(type);
            children.addAll(Arrays.asList(super.getChildren(type)));
            for (int i = 0, scLength = superClasses.length; i < scLength; i++)
              children.addAll(Arrays.asList(super.getChildren(superClasses[i])));
            return children.toArray();
          }
        }
      }
      return super.getChildren(element);
    }
 /**
  * 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;
 }
Exemple #5
0
 private RefactoringStatus checkEnclosingHierarchy() {
   IType current = fField.getDeclaringType();
   if (Checks.isTopLevel(current)) return null;
   RefactoringStatus result = new RefactoringStatus();
   while (current != null) {
     IField otherField = current.getField(getNewElementName());
     if (otherField.exists()) {
       String msg =
           Messages.format(
               RefactoringCoreMessages.RenameFieldRefactoring_hiding2,
               new String[] {
                 BasicElementLabels.getJavaElementName(getNewElementName()),
                 BasicElementLabels.getJavaElementName(current.getFullyQualifiedName('.')),
                 BasicElementLabels.getJavaElementName(otherField.getElementName())
               });
       result.addWarning(msg, JavaStatusContext.create(otherField));
     }
     current = current.getDeclaringType();
   }
   return result;
 }