public boolean checkConflicts(final ExtractSuperclassDialog dialog) {
   final MemberInfo[] infos =
       ArrayUtil.toObjectArray(dialog.getSelectedMemberInfos(), MemberInfo.class);
   final PsiDirectory targetDirectory = dialog.getTargetDirectory();
   final PsiPackage targetPackage;
   if (targetDirectory != null) {
     targetPackage = JavaDirectoryService.getInstance().getPackage(targetDirectory);
   } else {
     targetPackage = null;
   }
   final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
   if (!ProgressManager.getInstance()
       .runProcessWithProgressSynchronously(
           new Runnable() {
             public void run() {
               final PsiClass superClass =
                   mySubclass.getExtendsListTypes().length > 0 ? mySubclass.getSuperClass() : null;
               conflicts.putAllValues(
                   PullUpConflictsUtil.checkConflicts(
                       infos,
                       mySubclass,
                       superClass,
                       targetPackage,
                       targetDirectory,
                       dialog.getContainmentVerifier(),
                       false));
             }
           },
           RefactoringBundle.message("detecting.possible.conflicts"),
           true,
           myProject)) return false;
   ExtractSuperClassUtil.checkSuperAccessible(targetDirectory, conflicts, mySubclass);
   return ExtractSuperClassUtil.showConflicts(dialog, conflicts, myProject);
 }
Example #2
0
 @Nullable
 protected String getContainerText(final PsiElement element, final String name) {
   final PsiDirectory parent = ((PsiFile) element).getParent();
   if (parent == null) return null;
   final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(parent);
   if (psiPackage == null) return null;
   return "(" + psiPackage.getQualifiedName() + ")";
 }
  protected void doOKAction() {
    final String path = FileUtil.toSystemIndependentName(myDestDirectoryField.getText());
    final Project project = myDirectory.getProject();
    PsiDirectory directory =
        ApplicationManager.getApplication()
            .runWriteAction(
                new Computable<PsiDirectory>() {
                  public PsiDirectory compute() {
                    try {
                      return DirectoryUtil.mkdirs(PsiManager.getInstance(project), path);
                    } catch (IncorrectOperationException e) {
                      LOG.error(e);
                      return null;
                    }
                  }
                });
    if (directory == null) {
      Messages.showErrorDialog(
          project,
          RefactoringBundle.message("cannot.find.or.create.destination.directory"),
          RefactoringBundle.message("cannot.move"));
      return;
    }

    super.doOKAction();
    final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
    if (aPackage == null) {
      Messages.showErrorDialog(
          project,
          RefactoringBundle.message("destination.directory.does.not.correspond.to.any.package"),
          RefactoringBundle.message("cannot.move"));
      return;
    }

    final JavaRefactoringSettings refactoringSettings = JavaRefactoringSettings.getInstance();
    final boolean searchInComments = isSearchInComments();
    final boolean searchForTextOccurences = isSearchInNonJavaFiles();
    refactoringSettings.MOVE_SEARCH_IN_COMMENTS = searchInComments;
    refactoringSettings.MOVE_SEARCH_FOR_TEXT = searchForTextOccurences;

    performRefactoring(project, directory, aPackage, searchInComments, searchForTextOccurences);
  }
 static PsiClass extractInterface(
     PsiDirectory targetDir,
     PsiClass aClass,
     String interfaceName,
     MemberInfo[] selectedMembers,
     DocCommentPolicy javaDocPolicy)
     throws IncorrectOperationException {
   PsiClass anInterface =
       JavaDirectoryService.getInstance().createInterface(targetDir, interfaceName);
   PsiJavaCodeReferenceElement ref =
       ExtractSuperClassUtil.createExtendingReference(anInterface, aClass, selectedMembers);
   final PsiReferenceList referenceList =
       aClass.isInterface() ? aClass.getExtendsList() : aClass.getImplementsList();
   assert referenceList != null;
   referenceList.add(ref);
   PullUpHelper pullUpHelper =
       new PullUpHelper(aClass, anInterface, selectedMembers, javaDocPolicy);
   pullUpHelper.moveMembersToBase();
   return anInterface;
 }
  @NotNull
  public static SearchScope getClassUseScope(@NotNull PsiClass aClass) {
    if (aClass instanceof PsiAnonymousClass) {
      return new LocalSearchScope(aClass);
    }
    final GlobalSearchScope maximalUseScope = ResolveScopeManager.getElementUseScope(aClass);
    PsiFile file = aClass.getContainingFile();
    if (PsiImplUtil.isInServerPage(file)) return maximalUseScope;
    final PsiClass containingClass = aClass.getContainingClass();
    if (aClass.hasModifierProperty(PsiModifier.PUBLIC)
        || aClass.hasModifierProperty(PsiModifier.PROTECTED)) {
      return containingClass == null ? maximalUseScope : containingClass.getUseScope();
    } else if (aClass.hasModifierProperty(PsiModifier.PRIVATE)
        || aClass instanceof PsiTypeParameter) {
      PsiClass topClass = PsiUtil.getTopLevelClass(aClass);
      return new LocalSearchScope(topClass == null ? aClass.getContainingFile() : topClass);
    } else {
      PsiPackage aPackage = null;
      if (file instanceof PsiJavaFile) {
        aPackage =
            JavaPsiFacade.getInstance(aClass.getProject())
                .findPackage(((PsiJavaFile) file).getPackageName());
      }

      if (aPackage == null) {
        PsiDirectory dir = file.getContainingDirectory();
        if (dir != null) {
          aPackage = JavaDirectoryService.getInstance().getPackage(dir);
        }
      }

      if (aPackage != null) {
        SearchScope scope = PackageScope.packageScope(aPackage, false);
        scope = scope.intersectWith(maximalUseScope);
        return scope;
      }

      return new LocalSearchScope(file);
    }
  }