Search in sources :

Example 6 with ConflictsDialog

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

the class BaseRefactoringProcessor method prepareConflictsDialog.

@NotNull
protected ConflictsDialog prepareConflictsDialog(@NotNull MultiMap<PsiElement, String> conflicts, @Nullable final UsageInfo[] usages) {
    final ConflictsDialog conflictsDialog = createConflictsDialog(conflicts, usages);
    conflictsDialog.setCommandName(getCommandName());
    return conflictsDialog;
}
Also used : ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ConflictsDialog

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

the class ExtractMethodObjectDialog method doOKAction.

@Override
protected void doOKAction() {
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    if (myCreateInnerClassRb.isSelected()) {
        final PsiClass innerClass = myTargetClass.findInnerClassByName(myInnerClassName.getText(), false);
        if (innerClass != null) {
            conflicts.putValue(innerClass, "Inner class " + myInnerClassName.getText() + " already defined in class " + myTargetClass.getName());
        }
    }
    if (conflicts.size() > 0) {
        final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
        if (!conflictsDialog.showAndGet()) {
            if (conflictsDialog.isShowConflicts())
                close(CANCEL_EXIT_CODE);
            return;
        }
    }
    final JCheckBox makeVarargsCb = myCreateInnerClassRb.isSelected() ? myCbMakeVarargs : myCbMakeVarargsAnonymous;
    if (makeVarargsCb != null && makeVarargsCb.isSelected()) {
        final VariableData data = myInputVariables[myInputVariables.length - 1];
        if (data.type instanceof PsiArrayType) {
            data.type = new PsiEllipsisType(((PsiArrayType) data.type).getComponentType());
        }
    }
    super.doOKAction();
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) VariableData(com.intellij.refactoring.util.VariableData)

Example 8 with ConflictsDialog

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

the class IntroduceVariableHandler method reportConflicts.

protected boolean reportConflicts(final MultiMap<PsiElement, String> conflicts, final Project project, IntroduceVariableSettings dialog) {
    ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
    conflictsDialog.show();
    final boolean ok = conflictsDialog.isOK();
    if (!ok && conflictsDialog.isShowConflicts()) {
        if (dialog instanceof DialogWrapper)
            ((DialogWrapper) dialog).close(DialogWrapper.CANCEL_EXIT_CODE);
    }
    return ok;
}
Also used : ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 9 with ConflictsDialog

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

the class JavaPullUpHandler method checkConflicts.

@Override
public boolean checkConflicts(final PullUpDialog dialog) {
    final List<MemberInfo> infos = dialog.getSelectedMemberInfos();
    final MemberInfo[] memberInfos = infos.toArray(new MemberInfo[infos.size()]);
    final PsiClass superClass = dialog.getSuperClass();
    if (superClass == null || !checkWritable(superClass, memberInfos))
        return false;
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> {
        final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
        final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
        if (targetDirectory != null && targetPackage != null) {
            conflicts.putAllValues(PullUpConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass, targetPackage, targetDirectory, dialog.getContainmentVerifier()));
        }
    }), RefactoringBundle.message("detecting.possible.conflicts"), true, myProject))
        return false;
    if (!conflicts.isEmpty()) {
        ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
        boolean ok = conflictsDialog.showAndGet();
        if (!ok && conflictsDialog.isShowConflicts())
            dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
        return ok;
    }
    return true;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog)

Example 10 with ConflictsDialog

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

the class ModifierIntention method processIntention.

@Override
protected final void processIntention(@NotNull PsiElement element) {
    final PsiMember member = (PsiMember) element.getParent();
    final PsiModifierList modifierList = member.getModifierList();
    if (modifierList == null) {
        return;
    }
    final MultiMap<PsiElement, String> conflicts = checkForConflicts(member);
    final Project project = member.getProject();
    final boolean conflictsDialogOK;
    if (conflicts.isEmpty()) {
        conflictsDialogOK = true;
    } else {
        final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts, () -> changeModifier(modifierList));
        conflictsDialogOK = conflictsDialog.showAndGet();
    }
    if (conflictsDialogOK) {
        changeModifier(modifierList);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog)

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