コード例 #1
0
 @NotNull
 public static PsiElement[] findSuperElements(@NotNull PsiElement element) {
   if (element instanceof PsiClass) {
     PsiClass aClass = (PsiClass) element;
     List<PsiClass> allSupers = new ArrayList<>(Arrays.asList(aClass.getSupers()));
     for (Iterator<PsiClass> iterator = allSupers.iterator(); iterator.hasNext(); ) {
       PsiClass superClass = iterator.next();
       if (CommonClassNames.JAVA_LANG_OBJECT.equals(superClass.getQualifiedName()))
         iterator.remove();
     }
     return allSupers.toArray(new PsiClass[allSupers.size()]);
   }
   if (element instanceof PsiMethod) {
     PsiMethod method = (PsiMethod) element;
     if (method.isConstructor()) {
       PsiMethod constructorInSuper = PsiSuperMethodUtil.findConstructorInSuper(method);
       if (constructorInSuper != null) {
         return new PsiMethod[] {constructorInSuper};
       }
     } else {
       PsiMethod[] superMethods = method.findSuperMethods(false);
       if (superMethods.length == 0) {
         PsiMethod superMethod = getSiblingInheritedViaSubClass(method);
         if (superMethod != null) {
           superMethods = new PsiMethod[] {superMethod};
         }
       }
       return superMethods;
     }
   }
   return PsiElement.EMPTY_ARRAY;
 }
コード例 #2
0
 private void processInterface(PsiClass inheritor, PsiClass anInterface) {
   for (Iterator<PsiMethod> methodIterator = myRemainingMethods.iterator();
       methodIterator.hasNext(); ) {
     PsiMethod method = methodIterator.next();
     SiblingInfo info = findSibling(inheritor, anInterface, method);
     if (info != null) {
       myResult.put(method, info);
       methodIterator.remove();
     }
   }
 }
    private void addInaccessibilityDescriptions(
        Set<UsageInfo> usages, MultiMap<PsiElement, String> conflictDescriptions)
        throws IncorrectOperationException {
      PsiMethod method = myChangeInfo.getMethod();
      PsiModifierList modifierList = (PsiModifierList) method.getModifierList().copy();
      VisibilityUtil.setVisibility(modifierList, myChangeInfo.getNewVisibility());

      for (Iterator<UsageInfo> iterator = usages.iterator(); iterator.hasNext(); ) {
        UsageInfo usageInfo = iterator.next();
        PsiElement element = usageInfo.getElement();
        if (element != null) {
          if (element instanceof PsiQualifiedReference) {
            PsiClass accessObjectClass = null;
            PsiElement qualifier = ((PsiQualifiedReference) element).getQualifier();
            if (qualifier instanceof PsiExpression) {
              accessObjectClass =
                  (PsiClass) PsiUtil.getAccessObjectClass((PsiExpression) qualifier).getElement();
            }

            if (!JavaPsiFacade.getInstance(element.getProject())
                .getResolveHelper()
                .isAccessible(method, modifierList, element, accessObjectClass, null)) {
              String message =
                  RefactoringBundle.message(
                      "0.with.1.visibility.is.not.accessible.from.2",
                      RefactoringUIUtil.getDescription(method, true),
                      myChangeInfo.getNewVisibility(),
                      RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
              conflictDescriptions.putValue(method, message);
              if (!needToChangeCalls()) {
                iterator.remove();
              }
            }
          }
        }
      }
    }