Search in sources :

Example 11 with ConflictsDialog

use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.

the class ChangeSignatureProcessor method preprocessUsages.

protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    for (ChangeSignatureUsageProcessor processor : ChangeSignatureUsageProcessor.EP_NAME.getExtensions()) {
        if (!processor.setupDefaultValues(myChangeInfo, refUsages, myProject))
            return false;
    }
    MultiMap<PsiElement, String> conflictDescriptions = new MultiMap<>();
    collectConflictsFromExtensions(refUsages, conflictDescriptions, myChangeInfo);
    final UsageInfo[] usagesIn = refUsages.get();
    RenameUtil.addConflictDescriptions(usagesIn, conflictDescriptions);
    Set<UsageInfo> usagesSet = new HashSet<>(Arrays.asList(usagesIn));
    RenameUtil.removeConflictUsages(usagesSet);
    if (!conflictDescriptions.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            if (ConflictsInTestsException.isTestIgnore())
                return true;
            throw new ConflictsInTestsException(conflictDescriptions.values());
        }
        if (myPrepareSuccessfulSwingThreadCallback != null) {
            ConflictsDialog dialog = prepareConflictsDialog(conflictDescriptions, usagesIn);
            if (!dialog.showAndGet()) {
                if (dialog.isShowConflicts())
                    prepareSuccessful();
                return false;
            }
        }
    }
    if (myChangeInfo.isReturnTypeChanged()) {
        askToRemoveCovariantOverriders(usagesSet);
    }
    refUsages.set(usagesSet.toArray(new UsageInfo[usagesSet.size()]));
    prepareSuccessful();
    return true;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(com.intellij.util.containers.HashSet)

Example 12 with ConflictsDialog

use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.

the class ExtractSuperClassUtil method showConflicts.

public static boolean showConflicts(DialogWrapper dialog, MultiMap<PsiElement, String> conflicts, final Project project) {
    if (!conflicts.isEmpty()) {
        fireConflictsEvent(conflicts, project);
        ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
        conflictsDialog.show();
        final boolean ok = conflictsDialog.isOK();
        if (!ok && conflictsDialog.isShowConflicts())
            dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
        return ok;
    }
    return true;
}
Also used : ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog)

Example 13 with ConflictsDialog

use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.

the class InheritanceToDelegationProcessor method preprocessUsages.

protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    final UsageInfo[] usagesIn = refUsages.get();
    ArrayList<UsageInfo> oldUsages = new ArrayList<>();
    Collections.addAll(oldUsages, usagesIn);
    final ObjectUpcastedUsageInfo[] objectUpcastedUsageInfos = objectUpcastedUsages(usagesIn);
    if (myPrepareSuccessfulSwingThreadCallback != null) {
        MultiMap<PsiElement, String> conflicts = new MultiMap<>();
        if (objectUpcastedUsageInfos.length > 0) {
            final String message = RefactoringBundle.message("instances.of.0.upcasted.to.1.were.found", RefactoringUIUtil.getDescription(myClass, true), CommonRefactoringUtil.htmlEmphasize(CommonClassNames.JAVA_LANG_OBJECT));
            conflicts.putValue(myClass, message);
        }
        analyzeConflicts(usagesIn, conflicts);
        if (!conflicts.isEmpty()) {
            ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, usagesIn);
            if (!conflictsDialog.showAndGet()) {
                if (conflictsDialog.isShowConflicts())
                    prepareSuccessful();
                return false;
            }
        }
        if (objectUpcastedUsageInfos.length > 0) {
            showObjectUpcastedUsageView(objectUpcastedUsageInfos);
            setPreviewUsages(true);
        }
    }
    ArrayList<UsageInfo> filteredUsages = filterUsages(oldUsages);
    refUsages.set(filteredUsages.toArray(new UsageInfo[filteredUsages.size()]));
    prepareSuccessful();
    return true;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) UsageInfo(com.intellij.usageView.UsageInfo)

Example 14 with ConflictsDialog

use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.

the class MoveClassesOrPackagesImpl method doRearrangePackage.

public static void doRearrangePackage(final Project project, final PsiDirectory[] directories) {
    if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(directories), true)) {
        return;
    }
    List<PsiDirectory> sourceRootDirectories = buildRearrangeTargetsList(project, directories);
    DirectoryChooser chooser = new DirectoryChooser(project);
    chooser.setTitle(RefactoringBundle.message("select.source.root.chooser.title"));
    chooser.fillList(sourceRootDirectories.toArray(new PsiDirectory[sourceRootDirectories.size()]), null, project, "");
    if (!chooser.showAndGet()) {
        return;
    }
    final PsiDirectory selectedTarget = chooser.getSelectedDirectory();
    if (selectedTarget == null)
        return;
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final Runnable analyzeConflicts = () -> ApplicationManager.getApplication().runReadAction(() -> RefactoringConflictsUtil.analyzeModuleConflicts(project, Arrays.asList(directories), UsageInfo.EMPTY_ARRAY, selectedTarget, conflicts));
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(analyzeConflicts, "Analyze Module Conflicts...", true, project)) {
        return;
    }
    if (!conflicts.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values());
        } else {
            final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
            if (!conflictsDialog.showAndGet()) {
                return;
            }
        }
    }
    final Ref<IncorrectOperationException> ex = Ref.create(null);
    final String commandDescription = RefactoringBundle.message("moving.directories.command");
    Runnable runnable = () -> ApplicationManager.getApplication().runWriteAction(() -> {
        LocalHistoryAction a = LocalHistory.getInstance().startAction(commandDescription);
        try {
            rearrangeDirectoriesToTarget(directories, selectedTarget);
        } catch (IncorrectOperationException e) {
            ex.set(e);
        } finally {
            a.finish();
        }
    });
    CommandProcessor.getInstance().executeCommand(project, runnable, commandDescription, null);
    if (ex.get() != null) {
        RefactoringUIUtil.processIncorrectOperation(project, ex.get());
    }
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) LocalHistoryAction(com.intellij.history.LocalHistoryAction) IncorrectOperationException(com.intellij.util.IncorrectOperationException) DirectoryChooser(com.intellij.ide.util.DirectoryChooser)

Example 15 with ConflictsDialog

use of com.intellij.refactoring.ui.ConflictsDialog in project intellij-community by JetBrains.

the class MakeMethodOrClassStaticProcessor method preprocessUsages.

protected final boolean preprocessUsages(@NotNull final Ref<UsageInfo[]> refUsages) {
    UsageInfo[] usagesIn = refUsages.get();
    if (myPrepareSuccessfulSwingThreadCallback != null) {
        MultiMap<PsiElement, String> conflicts = getConflictDescriptions(usagesIn);
        if (conflicts.size() > 0) {
            ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, refUsages.get());
            if (!conflictsDialog.showAndGet()) {
                if (conflictsDialog.isShowConflicts())
                    prepareSuccessful();
                return false;
            }
        }
        if (!mySettings.isChangeSignature()) {
            refUsages.set(filterInternalUsages(usagesIn));
        }
    }
    final Set<UsageInfo> toMakeStatic = new LinkedHashSet<>();
    refUsages.set(filterOverriding(usagesIn, toMakeStatic));
    if (!findAdditionalMembers(toMakeStatic))
        return false;
    prepareSuccessful();
    return true;
}
Also used : ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)21 MultiMap (com.intellij.util.containers.MultiMap)15 UsageInfo (com.intellij.usageView.UsageInfo)7 HashSet (com.intellij.util.containers.HashSet)5 PsiElement (com.intellij.psi.PsiElement)4 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)3 Project (com.intellij.openapi.project.Project)2 PsiClass (com.intellij.psi.PsiClass)2 PsiReference (com.intellij.psi.PsiReference)2 RefactoringEventData (com.intellij.refactoring.listeners.RefactoringEventData)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 NotNull (org.jetbrains.annotations.NotNull)2 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)2 LocalHistoryAction (com.intellij.history.LocalHistoryAction)1 DirectoryChooser (com.intellij.ide.util.DirectoryChooser)1 Language (com.intellij.lang.Language)1 InlineHandler (com.intellij.lang.refactoring.InlineHandler)1 Application (com.intellij.openapi.application.Application)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 Computable (com.intellij.openapi.util.Computable)1