show refactoring conflicts in usage view
authorAnna Kozlova <Anna.Kozlova@jetbrains.com>
Wed, 16 Sep 2009 17:42:50 +0000 (21:42 +0400)
committerAnna Kozlova <Anna.Kozlova@jetbrains.com>
Wed, 16 Sep 2009 17:42:50 +0000 (21:42 +0400)
56 files changed:
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java
java/java-impl/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodProcessor.java
java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsProcessor.java
java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java
java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractMethodObjectDialog.java
java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperclassHandler.java
java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java
java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java
java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java
java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassProcessor.java
java/java-impl/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java
java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterMethodUsagesProcessor.java
java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterProcessor.java
java/java-impl/src/com/intellij/refactoring/introduceParameter/JavaIntroduceParameterMethodUsagesProcessor.java
java/java-impl/src/com/intellij/refactoring/introduceVariable/InputValidator.java
java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java
java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableHandler.java
java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java
java/java-impl/src/com/intellij/refactoring/makeStatic/MakeClassStaticProcessor.java
java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodOrClassStaticProcessor.java
java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHandler.java
java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpConflictsUtil.java
java/java-impl/src/com/intellij/refactoring/memberPushDown/PushDownConflicts.java
java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/AutocreatingSingleSourceRootMoveDestination.java
java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassToInnerProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MultipleRootsMoveDestination.java
java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/PackageLocalsUsageCollector.java
java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/SingleSourceRootMoveDestination.java
java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveMembersProcessor.java
java/java-impl/src/com/intellij/refactoring/removemiddleman/RemoveMiddlemanProcessor.java
java/java-impl/src/com/intellij/refactoring/rename/RenameJavaClassProcessor.java
java/java-impl/src/com/intellij/refactoring/rename/RenameJavaMethodProcessor.java
java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java
java/java-impl/src/com/intellij/refactoring/rename/RenamePsiPackageProcessor.java
java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderProcessor.java
java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryProcessor.java
java/java-impl/src/com/intellij/refactoring/util/ConflictsUtil.java
java/java-impl/src/com/intellij/refactoring/util/FixableUsagesRefactoringProcessor.java
java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java
java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueProcessor.java
java/java-tests/testSrc/com/intellij/refactoring/MoveClassToInnerTest.java
java/java-tests/testSrc/com/intellij/refactoring/PushDownTest.java
java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassMultifileTest.java
java/java-tests/testSrc/com/intellij/refactoring/inline/InlineToAnonymousClassTest.java
java/openapi/src/com/intellij/refactoring/MoveDestination.java
platform/lang-api/src/com/intellij/lang/refactoring/InlineHandler.java
platform/lang-api/src/com/intellij/refactoring/ui/ConflictsDialog.java [deleted file]
platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java
platform/lang-impl/src/com/intellij/refactoring/inline/GenericInlineHandler.java
platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java
platform/lang-impl/src/com/intellij/refactoring/rename/RenamePsiElementProcessor.java
platform/lang-impl/src/com/intellij/refactoring/rename/RenameUtil.java
platform/lang-impl/src/com/intellij/refactoring/ui/ConflictsDialog.java [new file with mode: 0644]

index 4c78e4e54af92642a70b575507f4c4b7bf06cdb0..880dd0812573366ba8c1b301047c62560322d2bd 100644 (file)
@@ -301,7 +301,7 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
     myChangeInfo.updateMethod((PsiMethod) elements[0]);
   }
 
-  private void addMethodConflicts(Collection<String> conflicts) {
+  private void addMethodConflicts(Map<PsiElement, String> conflicts) {
     String newMethodName = myChangeInfo.newName;
 
     try {
@@ -338,10 +338,10 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
 
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
-    Set<String> conflictDescriptions = new HashSet<String>();
+    Map<PsiElement, String> conflictDescriptions = new HashMap<PsiElement, String>();
     UsageInfo[] usagesIn = refUsages.get();
     addMethodConflicts(conflictDescriptions);
-    conflictDescriptions.addAll(RenameUtil.getConflictDescriptions(usagesIn));
+    conflictDescriptions.putAll(RenameUtil.getConflictDescriptions(usagesIn));
     Set<UsageInfo> usagesSet = new HashSet<UsageInfo>(Arrays.asList(usagesIn));
     RenameUtil.removeConflictUsages(usagesSet);
     if (myChangeInfo.isVisibilityChanged) {
@@ -356,7 +356,10 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
     if (myPrepareSuccessfulSwingThreadCallback != null && !conflictDescriptions.isEmpty()) {
       ConflictsDialog dialog = new ConflictsDialog(myProject, conflictDescriptions);
       dialog.show();
-      if (!dialog.isOK()) return false;
+      if (!dialog.isOK()){
+        if (dialog.isShowConflicts()) prepareSuccessful();
+        return false;
+      }
     }
 
     if (myChangeInfo.isReturnTypeChanged) {
@@ -368,7 +371,7 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
     return true;
   }
 
-  private void addInaccessibilityDescriptions(Set<UsageInfo> usages, Set<String> conflictDescriptions) throws IncorrectOperationException {
+  private void addInaccessibilityDescriptions(Set<UsageInfo> usages, Map<PsiElement, String> conflictDescriptions) throws IncorrectOperationException {
     PsiMethod method = myChangeInfo.getMethod();
     PsiModifierList modifierList = (PsiModifierList)method.getModifierList().copy();
     RefactoringUtil.setVisibility(modifierList, myNewVisibility);
@@ -391,7 +394,7 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
                                         RefactoringUIUtil.getDescription(method, true),
                                         myNewVisibility,
                                         RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
-            conflictDescriptions.add(message);
+            conflictDescriptions.put(method, message);
             if (!needToChangeCalls()) {
               iterator.remove();
             }
index e533e213366cd8f81deec1ff1d4174e08615573f..f3009ecd0e533e6b04803c0d02510699646b316d 100644 (file)
@@ -117,20 +117,20 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     UsageInfo[] usagesIn = refUsages.get();
-    ArrayList<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     final Set<PsiMember> methods = Collections.singleton((PsiMember)myMethod);
     if (!myTargetClass.isInterface()) {
       final String original = VisibilityUtil.getVisibilityModifier(myMethod.getModifierList());
-      conflicts.addAll(
-        Arrays.asList(MoveMembersProcessor.analyzeAccessibilityConflicts(methods, myTargetClass, new LinkedHashSet<String>(), original)));
+      conflicts.putAll(
+        MoveMembersProcessor.analyzeAccessibilityConflicts(methods, myTargetClass, new LinkedHashMap<PsiElement, String>(), original));
     }
     else {
       for (final UsageInfo usage : usagesIn) {
         if (usage instanceof ImplementingClassUsageInfo) {
-          conflicts.addAll(Arrays.asList(MoveMembersProcessor.analyzeAccessibilityConflicts(methods,
+          conflicts.putAll(MoveMembersProcessor.analyzeAccessibilityConflicts(methods,
                                                                                             ((ImplementingClassUsageInfo)usage).getPsiClass(),
-                                                                                            new LinkedHashSet<String>(),
-                                                                                            PsiModifier.PUBLIC)));
+                                                                                            new LinkedHashMap<PsiElement, String>(),
+                                                                                            PsiModifier.PUBLIC));
         }
       }
     }
@@ -147,7 +147,7 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
             String message = RefactoringBundle.message("0.contains.call.with.null.argument.for.parameter.1",
                                                        RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(methodCall), true),
                                                        CommonRefactoringUtil.htmlEmphasize(myTargetParameter.getName()));
-            conflicts.add(message);
+            conflicts.put(methodCall, message);
           }
         }
       }
@@ -163,7 +163,7 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
     return showConflicts(conflicts);
   }
 
-  private void addInaccessibilityConflicts(final UsageInfo[] usages, final ArrayList<String> conflicts) throws IncorrectOperationException {
+  private void addInaccessibilityConflicts(final UsageInfo[] usages, final Map<PsiElement, String> conflicts) throws IncorrectOperationException {
     final PsiModifierList copy = (PsiModifierList)myMethod.getModifierList().copy();
     if (myNewVisibility != null) {
       if (myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY)) {
@@ -191,7 +191,7 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
           String message = RefactoringBundle.message("0.with.1.visibility.is.not.accesible.from.2",
                                                      RefactoringUIUtil.getDescription(myMethod, true), newVisibility,
                                                      RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(call), true));
-          conflicts.add(message);
+          conflicts.put(myMethod, message);
         }
       }
     }
index c2484046f5722cdf0ff0061a581b12869f64af94..f37a4a6214347b0095de5e8603ccd6f1d9f29e8d 100644 (file)
@@ -70,7 +70,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
   }
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
-    ArrayList<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
 
     if (myDialog != null) {
       checkExistingMethods(myDialog.getGetterPrototypes(), conflicts, true);
@@ -79,7 +79,10 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
       if(conflicts.size() > 0) {
         ConflictsDialog dialog = new ConflictsDialog(myProject, conflicts);
         dialog.show();
-        if(!dialog.isOK()) return false;
+        if(!dialog.isOK()){
+          if (dialog.isShowConflicts()) prepareSuccessful();
+          return false;
+        }
       }
     }
 
@@ -87,7 +90,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
     return true;
   }
 
-  private void checkExistingMethods(PsiMethod[] prototypes, ArrayList<String> conflicts, boolean isGetter) {
+  private void checkExistingMethods(PsiMethod[] prototypes, Map<PsiElement, String> conflicts, boolean isGetter) {
     if(prototypes == null) return;
     for (PsiMethod prototype : prototypes) {
       final PsiType prototypeReturnType = prototype.getReturnType();
@@ -105,7 +108,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
                                                 CommonRefactoringUtil.htmlEmphasize(prototype.getName())) :
                            RefactoringBundle.message("encapsulate.fields.setter.exists", CommonRefactoringUtil.htmlEmphasize(descr),
                                                 CommonRefactoringUtil.htmlEmphasize(prototype.getName()));
-          conflicts.add(message);
+          conflicts.put(existing, message);
         }
       }
     }
index 78c7f89e30ba9fcb287eae71073ecdd61e60d40d..2d2533f7cb1e9b8857d74909c12b8d915b4e1d1c 100644 (file)
@@ -13,12 +13,11 @@ import com.intellij.refactoring.ui.ConflictsDialog;
 import com.intellij.refactoring.ui.VisibilityPanel;
 import com.intellij.refactoring.util.ConflictsUtil;
 import com.intellij.refactoring.util.ParameterTablePanel;
-import com.intellij.util.VisibilityUtil;
 import com.intellij.ui.EditorTextField;
 import com.intellij.ui.IdeBorderFactory;
 import com.intellij.ui.NonFocusableCheckBox;
 import com.intellij.util.IncorrectOperationException;
-import com.intellij.util.containers.HashSet;
+import com.intellij.util.VisibilityUtil;
 import org.jetbrains.annotations.NonNls;
 
 import javax.swing.*;
@@ -27,8 +26,8 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
-import java.util.Collection;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
 
 
 public class ExtractMethodDialog extends AbstractExtractDialog {
@@ -148,12 +147,15 @@ public class ExtractMethodDialog extends AbstractExtractDialog {
   }
 
   protected void doOKAction() {
-    Set<String> conflicts = new HashSet<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     checkMethodConflicts(conflicts);
     if (!conflicts.isEmpty()) {
       final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
       conflictsDialog.show();
-      if (!conflictsDialog.isOK()) return;
+      if (!conflictsDialog.isOK()){
+        if (conflictsDialog.isShowConflicts()) close(CANCEL_EXIT_CODE);
+        return;
+      }
     }
 
     if (myCbMakeVarargs != null && myCbMakeVarargs.isSelected()) {
@@ -394,7 +396,7 @@ public class ExtractMethodDialog extends AbstractExtractDialog {
     return buffer;
   }
 
-  protected void checkMethodConflicts(Collection<String> conflicts) {
+  protected void checkMethodConflicts(Map<PsiElement, String> conflicts) {
     PsiMethod prototype;
     try {
       PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory();
index 693166293909b88117ec34a88fcec2426cf1a049..46c784a2597ca80c864dc3cc843bbeca54d65678 100644 (file)
@@ -12,10 +12,9 @@ import com.intellij.refactoring.extractMethod.AbstractExtractDialog;
 import com.intellij.refactoring.extractMethod.InputVariables;
 import com.intellij.refactoring.ui.ConflictsDialog;
 import com.intellij.refactoring.util.ParameterTablePanel;
-import com.intellij.util.VisibilityUtil;
 import com.intellij.ui.EditorTextField;
 import com.intellij.util.Function;
-import com.intellij.util.containers.HashSet;
+import com.intellij.util.VisibilityUtil;
 import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NonNls;
 
@@ -24,7 +23,8 @@ import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.Enumeration;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
 
 
 public class ExtractMethodObjectDialog extends AbstractExtractDialog {
@@ -132,16 +132,20 @@ public class ExtractMethodObjectDialog extends AbstractExtractDialog {
   }
 
   protected void doOKAction() {
-    Set<String> conflicts = new HashSet<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     if (myCreateInnerClassRb.isSelected()) {
-      if (myTargetClass.findInnerClassByName(myInnerClassName.getText(), false) != null) {
-        conflicts.add("Inner class " + myInnerClassName.getText() + " already defined in class " + myTargetClass.getName());
+      final PsiClass innerClass = myTargetClass.findInnerClassByName(myInnerClassName.getText(), false);
+      if (innerClass != null) {
+        conflicts.put(innerClass, "Inner class " + myInnerClassName.getText() + " already defined in class " + myTargetClass.getName());
       }
     }
     if (conflicts.size() > 0) {
       final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
       conflictsDialog.show();
-      if (!conflictsDialog.isOK()) return;
+      if (!conflictsDialog.isOK()){
+        if (conflictsDialog.isShowConflicts()) close(CANCEL_EXIT_CODE);
+        return;
+      }
     }
 
     final JCheckBox makeVarargsCb = myCreateInnerClassRb.isSelected() ? myCbMakeVarargs : myCbMakeVarargsAnonymous;
index 442c9431a9f4b3df63f12ff0ca6ded8693a241f0..547d32d6752d0712776727d6b843ec11d55a9524 100644 (file)
@@ -14,6 +14,7 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.ScrollType;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.psi.*;
 import com.intellij.refactoring.HelpID;
 import com.intellij.refactoring.RefactoringActionHandler;
@@ -30,6 +31,7 @@ import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.List;
+import java.util.LinkedHashMap;
 
 public class ExtractSuperclassHandler implements RefactoringActionHandler, ExtractSuperclassDialog.Callback, ElementsHandler {
   private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.extractSuperclass.ExtractSuperclassHandler");
@@ -115,12 +117,14 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
     else {
       targetPackage = null;
     }
-    String[] conflicts =
+    LinkedHashMap<PsiElement,String> conflicts =
       PullUpConflictsUtil.checkConflicts(infos, mySubclass, null, targetPackage, targetDirectory, dialog.getContainmentVerifier());
-    if (conflicts.length > 0) {
+    if (!conflicts.isEmpty()) {
       ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
       conflictsDialog.show();
-      return conflictsDialog.isOK();
+      final boolean ok = conflictsDialog.isOK();
+      if (!ok && conflictsDialog.isShowConflicts()) dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
+      return ok;
     }
     return true;
   }
index b1bb673ac0404a541e17d17ac2ff73e1e1d27371..aceefe6cbf84e67412dca00ee51973493a966ddd 100644 (file)
@@ -97,18 +97,18 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
 
   @Override
   protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
-    final List<String> conflicts = new ArrayList<String>();
+    final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     final Project project = sourceClass.getProject();
     final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
     final PsiClass existingClass =
       JavaPsiFacade.getInstance(project).findClass(StringUtil.getQualifiedName(newPackageName, newClassName), scope);
     if (existingClass != null) {
-      conflicts.add(RefactorJBundle.message("cannot.perform.the.refactoring") +
+      conflicts.put(existingClass, RefactorJBundle.message("cannot.perform.the.refactoring") +
                     RefactorJBundle.message("there.already.exists.a.class.with.the.chosen.name"));
     }
 
     if (!myGenerateAccessors) {
-      conflicts.addAll(calculateInitializersConflicts());
+      conflicts.putAll(calculateInitializersConflicts());
       final NecessaryAccessorsVisitor visitor = new NecessaryAccessorsVisitor();
       for (PsiField field : fields) {
         field.accept(visitor);
@@ -122,35 +122,35 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
 
       final Set<PsiField> fieldsNeedingGetter = visitor.getFieldsNeedingGetter();
       for (PsiField field : fieldsNeedingGetter) {
-        conflicts.add("Field \'" + field.getName() + "\' needs getter");
+        conflicts.put(field, "Field \'" + field.getName() + "\' needs getter");
       }
       final Set<PsiField> fieldsNeedingSetter = visitor.getFieldsNeedingSetter();
       for (PsiField field : fieldsNeedingSetter) {
-        conflicts.add("Field \'" + field.getName() + "\' needs getter");
+        conflicts.put(field, "Field \'" + field.getName() + "\' needs getter");
       }
     }
     return showConflicts(conflicts);
   }
 
   @Override
-  protected boolean showConflicts(final List<String> conflicts) {
+  protected boolean showConflicts(final Map<PsiElement, String> conflicts) {
     if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
-      throw new RuntimeException(StringUtil.join(conflicts, "\n"));
+      throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
     }
     return super.showConflicts(conflicts);
   }
 
-  private List<String> calculateInitializersConflicts() {
-    final List<String> out = new ArrayList<String>();
+  private Map<PsiElement, String> calculateInitializersConflicts() {
+    final Map<PsiElement, String> out = new HashMap<PsiElement, String>();
     final PsiClassInitializer[] initializers = sourceClass.getInitializers();
     for (PsiClassInitializer initializer : initializers) {
       if (initializerDependsOnMoved(initializer)) {
-        out.add("Class initializer requires moved members");
+        out.put(initializer, "Class initializer requires moved members");
       }
     }
     for (PsiMethod constructor : sourceClass.getConstructors()) {
       if (initializerDependsOnMoved(constructor.getBody())) {
-        out.add("Constructor requires moved members");
+        out.put(constructor, "Constructor requires moved members");
       }
     }
     return out;
index ee36cb4d36c9d52933f5ef6c8a49391b09764c7b..6d23c89a8d5595ccd4c584dd2e70e3a2bd196516 100644 (file)
@@ -19,8 +19,9 @@ import com.intellij.usageView.UsageViewUtil;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 
 /**
  * @author ven
@@ -169,7 +170,7 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor {
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     UsageInfo[] usagesIn = refUsages.get();
-    ArrayList<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
 
     ReferencedElementsCollector collector = new ReferencedElementsCollector();
     PsiExpression initializer = myField.getInitializer();
@@ -183,14 +184,14 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor {
       if (element instanceof PsiExpression && isAccessedForWriting((PsiExpression)element)) {
         String message = RefactoringBundle.message("0.is.used.for.writing.in.1", RefactoringUIUtil.getDescription(myField, true),
                                                    RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
-        conflicts.add(message);
+        conflicts.put(element, message);
       }
 
       for (PsiMember member : referencedWithVisibility) {
         if (!resolveHelper.isAccessible(member, element, null)) {
           String message = RefactoringBundle.message("0.will.not.be.accessible.from.1.after.inlining", RefactoringUIUtil.getDescription(member, true),
                                                      RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
-          conflicts.add(message);
+          conflicts.put(member, message);
         }
       }
     }
index 861557edeaf5ac265fb05f82216b8af87648cd65..24ba4b1b2f1207244e0a3fbd6a321d0eb7deee73 100644 (file)
@@ -105,7 +105,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     UsageInfo[] usagesIn = refUsages.get();
-    ArrayList<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
 
     if (!myInlineThisOnly) {
       final PsiMethod[] superMethods = myMethod.findSuperMethods();
@@ -113,7 +113,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
         final String message = method.hasModifierProperty(PsiModifier.ABSTRACT) ? RefactoringBundle
           .message("inlined.method.implements.method.from.0", method.getContainingClass().getQualifiedName()) : RefactoringBundle
           .message("inlined.method.overrides.method.from.0", method.getContainingClass().getQualifiedName());
-        conflicts.add(message);
+        conflicts.put(method, message);
       }
     }
 
@@ -123,6 +123,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
       ConflictsDialog dialog = new ConflictsDialog(myProject, conflicts);
       dialog.show();
       if (!dialog.isOK()) {
+        if (dialog.isShowConflicts()) prepareSuccessful();
         return false;
       }
     }
@@ -138,7 +139,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
   public static void addInaccessibleMemberConflicts(final PsiElement element,
                                                     final UsageInfo[] usages,
                                                     final ReferencedElementsCollector collector,
-                                                    final ArrayList<String> conflicts) {
+                                                    final Map<PsiElement, String> conflicts) {
     element.accept(collector);
     final Map<PsiMember, Set<PsiMember>> containersToReferenced = getInaccessible(collector.myReferencedMembers, usages);
 
@@ -150,7 +151,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
         final String containerDescription = RefactoringUIUtil.getDescription(container, true);
         String message = RefactoringBundle.message("0.that.is.used.in.inlined.method.is.not.accessible.from.call.site.s.in.1",
                                                    referencedDescription, containerDescription);
-        conflicts.add(CommonRefactoringUtil.capitalize(message));
+        conflicts.put(container, CommonRefactoringUtil.capitalize(message));
       }
     }
   }
index 1530657b409de239d4823fc4aa3d0d50bc7d011c..8b11d25edd0bc80b26f9c0324765a60a992db622 100644 (file)
@@ -124,15 +124,15 @@ public class InlineToAnonymousClassProcessor extends BaseRefactoringProcessor {
       CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("inline.to.anonymous.refactoring"), s, null, myClass.getProject());
       return false;
     }
-    ArrayList<String> conflicts = getConflicts(usages);
+    Map<PsiElement, String> conflicts = getConflicts(usages);
     if (!conflicts.isEmpty()) {
       return showConflicts(conflicts);
     }
     return super.preprocessUsages(refUsages);
   }
 
-  public ArrayList<String> getConflicts(final UsageInfo[] usages) {
-    ArrayList<String> result = new ArrayList<String>();
+  public Map<PsiElement, String> getConflicts(final UsageInfo[] usages) {
+    Map<PsiElement, String> result = new LinkedHashMap<PsiElement, String>();
     ReferencedElementsCollector collector = new ReferencedElementsCollector() {
       protected void checkAddMember(@NotNull final PsiMember member) {
         if (PsiTreeUtil.isAncestor(myClass, member, false)) {
index 23d5a66e8484f92a08ba79a25c2a8bd13b357314..0f942cc2962dd8cb7f00355288aaa0d31e0d36df 100644 (file)
@@ -29,7 +29,6 @@ import com.intellij.util.Processor;
 import com.intellij.util.containers.HashMap;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -131,7 +130,7 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori
 
   @Override
   protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
-    final List<String> conflicts = new ArrayList<String>();
+    final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     final PushDownConflicts pushDownConflicts = new PushDownConflicts(mySuperClass, myMemberInfos);
     for (PsiClass targetClass : myTargetClasses) {
       for (MemberInfo info : myMemberInfos) {
@@ -140,14 +139,14 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori
       }
     }
     checkConflicts(refUsages, conflicts);
-    conflicts.addAll(pushDownConflicts.getConflicts());
+    conflicts.putAll(pushDownConflicts.getConflicts());
     return showConflicts(conflicts);
   }
 
   @Override
-  protected boolean showConflicts(final List<String> conflicts) {
+  protected boolean showConflicts(final Map<PsiElement, String> conflicts) {
     if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
-      throw new RuntimeException(StringUtil.join(conflicts, "\n"));
+      throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
     }
     return super.showConflicts(conflicts);
   }
index 956752e6037c424c48a9cc8129b9d057fb72a0dd..77c498c046199b88392a0f5faf4067f7d6600dcb 100644 (file)
@@ -1,10 +1,11 @@
 package com.intellij.refactoring.introduceParameter;
 
 import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.psi.PsiElement;
 import com.intellij.usageView.UsageInfo;
 import com.intellij.util.IncorrectOperationException;
 
-import java.util.List;
+import java.util.Map;
 
 /**
  * @author Maxim.Medvedev
@@ -16,7 +17,7 @@ public interface IntroduceParameterMethodUsagesProcessor {
 
   boolean isMethodUsage(UsageInfo usage);
 
-  List<String> findConflicts(IntroduceParameterData data, UsageInfo[] usages);
+  Map<PsiElement, String> findConflicts(IntroduceParameterData data, UsageInfo[] usages);
 
   boolean processChangeMethodUsage(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException;
 
index a58f431545929e6a2d299dbdba6873108de61841..b3d40ee65f34651831fb957a140655ead7c63ba2 100644 (file)
@@ -11,6 +11,7 @@ package com.intellij.refactoring.introduceParameter;
 import com.intellij.codeInsight.ChangeContextUtil;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.Ref;
 import com.intellij.psi.*;
 import com.intellij.psi.search.GlobalSearchScope;
@@ -38,6 +39,8 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Set;
 
 public class IntroduceParameterProcessor extends BaseRefactoringProcessor implements IntroduceParameterData {
@@ -190,12 +193,13 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     UsageInfo[] usagesIn = refUsages.get();
-    ArrayList<String> conflicts = new ArrayList<String> ();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
 
     AnySameNameVariables anySameNameVariables = new AnySameNameVariables();
     myMethodToReplaceIn.accept(anySameNameVariables);
-    if (anySameNameVariables.getConflict() != null) {
-      conflicts.add(anySameNameVariables.getConflict());
+    final Pair<PsiElement, String> conflictPair = anySameNameVariables.getConflict();
+    if (conflictPair != null) {
+      conflicts.put(conflictPair.first, conflictPair.second);
     }
 
     if (!myGenerateDelegate) {
@@ -209,7 +213,7 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
         for (UsageInfo usageInfo : usagesIn) {
           if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
             if (!PsiTreeUtil.isAncestor(myMethodToReplaceIn.getContainingClass(), usageInfo.getElement(), false)) {
-              conflicts.add(RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class",
+              conflicts.put(myParameterInitializer, RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class",
                                                       CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
               break;
             }
@@ -219,13 +223,13 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
     }
 
     for (IntroduceParameterMethodUsagesProcessor processor : IntroduceParameterMethodUsagesProcessor.EP_NAME.getExtensions()) {
-      conflicts.addAll(processor.findConflicts(this, refUsages.get()));
+      conflicts.putAll(processor.findConflicts(this, refUsages.get()));
     }
 
     return showConflicts(conflicts);
   }
 
-  private void detectAccessibilityConflicts(final UsageInfo[] usageArray, ArrayList<String> conflicts) {
+  private void detectAccessibilityConflicts(final UsageInfo[] usageArray, Map<PsiElement, String> conflicts) {
     if (myParameterInitializer != null) {
       final ReferencedElementsCollector collector = new ReferencedElementsCollector();
       myParameterInitializer.accept(collector);
@@ -242,7 +246,7 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
                     "0.is.not.accesible.from.1.value.for.introduced.parameter.in.that.method.call.will.be.incorrect",
                     RefactoringUIUtil.getDescription(element, true),
                     RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(place), true));
-                conflicts.add(message);
+                conflicts.put(element, message);
               }
             }
           }
@@ -274,9 +278,9 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
   }
 
   public class AnySameNameVariables extends JavaRecursiveElementWalkingVisitor {
-    private String conflict = null;
+    private Pair<PsiElement, String> conflict = null;
 
-    public String getConflict() {
+    public Pair<PsiElement, String> getConflict() {
       return conflict;
     }
 
@@ -286,7 +290,7 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
         String descr = RefactoringBundle.message("there.is.already.a.0.it.will.conflict.with.an.introduced.parameter",
                                                  RefactoringUIUtil.getDescription(variable, true));
 
-        conflict = CommonRefactoringUtil.capitalize(descr);
+        conflict = Pair.<PsiElement, String>create(variable, CommonRefactoringUtil.capitalize(descr));
       }
     }
 
index c68d53ec7ae41ad9e9a865ad4280daf2c46cd91f..f05d975add2333af1832e1a2f0ce27aeea819f8d 100644 (file)
@@ -12,17 +12,17 @@ import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.psi.util.PsiUtil;
 import com.intellij.refactoring.util.FieldConflictsResolver;
 import com.intellij.refactoring.util.RefactoringUtil;
-import com.intellij.util.VisibilityUtil;
-import com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo;
 import com.intellij.refactoring.util.javadoc.MethodJavaDocHelper;
+import com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo;
 import com.intellij.usageView.UsageInfo;
 import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.VisibilityUtil;
 import gnu.trove.TIntArrayList;
 import gnu.trove.TIntProcedure;
 import org.jetbrains.annotations.Nullable;
 
 import java.util.Collections;
-import java.util.List;
+import java.util.Map;
 
 /**
  * @author Maxim.Medvedev
@@ -123,8 +123,8 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
   }
 
 
-  public List<String> findConflicts(IntroduceParameterData data, UsageInfo[] usages) {
-    return Collections.emptyList();
+  public Map<PsiElement, String> findConflicts(IntroduceParameterData data, UsageInfo[] usages) {
+    return Collections.emptyMap();
   }
 
   public boolean processChangeMethodSignature(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
index ef28de9ef72f1bd074733932107c4468083d25c9..c2c0493ebbb75cd3cdab9118d2d4ac1d085e772d 100644 (file)
@@ -11,7 +11,8 @@ import com.intellij.refactoring.util.RefactoringUIUtil;
 import com.intellij.refactoring.util.occurences.ExpressionOccurenceManager;
 import com.intellij.util.containers.HashSet;
 
-import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 public class InputValidator implements IntroduceVariableBase.Validator {
   private final Project myProject;
@@ -31,7 +32,7 @@ public class InputValidator implements IntroduceVariableBase.Validator {
     }
     final PsiElement scope = anchor.getParent();
     if(scope == null) return true;
-    final ArrayList<String> conflicts = new ArrayList<String>();
+    final Map<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
     final HashSet<PsiVariable> reportedVariables = new HashSet<PsiVariable>();
     JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor visitor = new JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor() {
       public void visitCollidingElement(PsiVariable collidingVariable) {
@@ -39,7 +40,7 @@ public class InputValidator implements IntroduceVariableBase.Validator {
         if (!reportedVariables.contains(collidingVariable)) {
           reportedVariables.add(collidingVariable);
           String message = RefactoringBundle.message("introduced.variable.will.conflict.with.0", RefactoringUIUtil.getDescription(collidingVariable, true));
-          conflicts.add(message);
+          conflicts.put(collidingVariable, message);
         }
       }
     };
@@ -54,7 +55,7 @@ public class InputValidator implements IntroduceVariableBase.Validator {
     }
 
     if (conflicts.size() > 0) {
-      return myIntroduceVariableBase.reportConflicts(conflicts, myProject);
+      return myIntroduceVariableBase.reportConflicts(conflicts, myProject, settings);
     } else {
       return true;
     }
index 21cfac30c29ea0262d82402f4a70b10f582b80c1..1310ce93c42a01e35129810c7c26aa375719251f 100644 (file)
@@ -49,6 +49,7 @@ import javax.swing.event.ListSelectionListener;
 import java.awt.*;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 public abstract class IntroduceVariableBase extends IntroduceHandlerBase implements RefactoringActionHandler {
   private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.introduceVariable.IntroduceVariableBase");
@@ -681,10 +682,10 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
     boolean isOK(IntroduceVariableSettings dialog);
   }
 
-  protected abstract boolean reportConflicts(ArrayList<String> conflicts, final Project project);
+  protected abstract boolean reportConflicts(Map<PsiElement, String> conflicts, final Project project, IntroduceVariableSettings dialog);
 
 
-  public static void checkInLoopCondition(PsiExpression occurence, List<String> conflicts) {
+  public static void checkInLoopCondition(PsiExpression occurence, Map<PsiElement, String> conflicts) {
     final PsiElement loopForLoopCondition = RefactoringUtil.getLoopForLoopCondition(occurence);
     if (loopForLoopCondition == null) return;
     final List<PsiVariable> referencedVariables = RefactoringUtil.collectReferencedVariables(occurence);
@@ -698,9 +699,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
     if (!modifiedInBody.isEmpty()) {
       for (PsiVariable variable : modifiedInBody) {
         final String message = RefactoringBundle.message("is.modified.in.loop.body", RefactoringUIUtil.getDescription(variable, false));
-        conflicts.add(CommonRefactoringUtil.capitalize(message));
+        conflicts.put(variable, CommonRefactoringUtil.capitalize(message));
       }
-      conflicts.add(RefactoringBundle.message("introducing.variable.may.break.code.logic"));
+      conflicts.put(occurence, RefactoringBundle.message("introducing.variable.may.break.code.logic"));
     }
   }
 
index 6261371050331f5e7fd0c1ddde7fd4bd696da387..44a1e27086c402704a4ec83b22c05341c3535705 100644 (file)
@@ -8,6 +8,7 @@ import com.intellij.openapi.editor.markup.RangeHighlighter;
 import com.intellij.openapi.editor.markup.TextAttributes;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.wm.WindowManager;
+import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiExpression;
 import com.intellij.psi.PsiType;
@@ -18,6 +19,7 @@ import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
 import com.intellij.refactoring.util.CommonRefactoringUtil;
 
 import java.util.ArrayList;
+import java.util.Map;
 
 public class IntroduceVariableHandler extends IntroduceVariableBase {
 
@@ -70,9 +72,13 @@ public class IntroduceVariableHandler extends IntroduceVariableBase {
     WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
   }
 
-  protected boolean reportConflicts(final ArrayList<String> conflicts, final Project project) {
+  protected boolean reportConflicts(final Map<PsiElement, String> conflicts, final Project project, IntroduceVariableSettings dialog) {
     ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
     conflictsDialog.show();
-    return conflictsDialog.isOK();
+    final boolean ok = conflictsDialog.isOK();
+    if (!ok && conflictsDialog.isShowConflicts()) {
+      if (dialog instanceof DialogWrapper) ((DialogWrapper)dialog).close(DialogWrapper.CANCEL_EXIT_CODE);
+    }
+    return ok;
   }
 }
index 8e713e303d09b215f994683d55957c2ccd9113ed..06db53e5536001911431ace4e346a538f1e1cfc1 100644 (file)
@@ -102,32 +102,33 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
 
   @Override
   protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
-    ArrayList<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     if (myUseExistingClass) {
       if (existingClass == null) {
-        conflicts.add(RefactorJBundle.message("cannot.perform.the.refactoring") + "Could not find the selected class");
+        conflicts.put(null, RefactorJBundle.message("cannot.perform.the.refactoring") + "Could not find the selected class");
       }
       final String incompatibilityMessage = "Selected class is not compatible with chosen parameters";
       if (!myExistingClassCompatible) {
         conflicts
-          .add(RefactorJBundle.message("cannot.perform.the.refactoring") + incompatibilityMessage);
+          .put(existingClass, RefactorJBundle.message("cannot.perform.the.refactoring") + incompatibilityMessage);
 
       }
       if (!paramsNeedingSetters.isEmpty()) {
-        conflicts.add(RefactorJBundle.message("cannot.perform.the.refactoring") + incompatibilityMessage);
+        conflicts.put(existingClass, RefactorJBundle.message("cannot.perform.the.refactoring") + incompatibilityMessage);
       }
     }
     else if (existingClass != null) {
-      conflicts.add(RefactorJBundle.message("cannot.perform.the.refactoring") +
+      conflicts.put(existingClass,
+                    RefactorJBundle.message("cannot.perform.the.refactoring") +
                     RefactorJBundle.message("there.already.exists.a.class.with.the.chosen.name"));
     }
     return showConflicts(conflicts);
   }
 
   @Override
-  protected boolean showConflicts(final List<String> conflicts) {
+  protected boolean showConflicts(final Map<PsiElement, String> conflicts) {
     if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
-      throw new RuntimeException(StringUtil.join(conflicts, "\n"));
+      throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
     }
     return super.showConflicts(conflicts);
   }
index 8cd207fbd3cb941615238d2d5803d35efe7e5774..94a72ae8b510fd490de46e8481553b44c53648c2 100644 (file)
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NonNls;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author ven
@@ -294,8 +295,8 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor<P
     }
   }
 
-  protected List<String> getConflictDescriptions(final UsageInfo[] usages) {
-    final List<String> conflicts = super.getConflictDescriptions(usages);
+  protected Map<PsiElement,String> getConflictDescriptions(final UsageInfo[] usages) {
+    final Map<PsiElement, String> conflicts = super.getConflictDescriptions(usages);
 
     //Check fields already exist
     if (mySettings.isMakeClassParameter()) {
@@ -304,7 +305,7 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor<P
       if (existing != null) {
         String message = RefactoringBundle.message("there.is.already.a.0.in.1", RefactoringUIUtil.getDescription(existing, false),
                                               RefactoringUIUtil.getDescription(myMember, false));
-              conflicts.add(message);
+              conflicts.put(existing, message);
       }
     }
 
@@ -317,7 +318,7 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor<P
         if (existing != null) {
           String message = RefactoringBundle.message("there.is.already.a.0.in.1", RefactoringUIUtil.getDescription(existing, false),
                                                 RefactoringUIUtil.getDescription(myMember, false));
-          conflicts.add(message);
+          conflicts.put(existing, message);
         }
       }
     }
index c91a98a1f83107e73447048e864a61ffd7b2765a..e9ab1d28ad2b8ee77d063e69ce51678202f7e8e7 100644 (file)
@@ -23,18 +23,15 @@ import com.intellij.refactoring.RefactoringBundle;
 import com.intellij.refactoring.ui.ConflictsDialog;
 import com.intellij.refactoring.util.CommonRefactoringUtil;
 import com.intellij.refactoring.util.ConflictsUtil;
-import com.intellij.refactoring.util.RefactoringUtil;
 import com.intellij.refactoring.util.RefactoringUIUtil;
+import com.intellij.refactoring.util.RefactoringUtil;
 import com.intellij.usageView.UsageInfo;
 import com.intellij.usageView.UsageViewDescriptor;
 import com.intellij.usageView.UsageViewUtil;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
+import java.util.*;
 
 public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParameterListOwner> extends BaseRefactoringProcessor {
   private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.makeMethodStatic.MakeMethodStaticProcessor");
@@ -57,11 +54,12 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
   protected final boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     UsageInfo[] usagesIn = refUsages.get();
     if (myPrepareSuccessfulSwingThreadCallback != null) {
-      List<String> conflicts = getConflictDescriptions(usagesIn);
+      Map<PsiElement, String> conflicts = getConflictDescriptions(usagesIn);
       if (conflicts.size() > 0) {
         ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
         conflictsDialog.show();
         if (!conflictsDialog.isOK()) {
+          if (conflictsDialog.isShowConflicts()) prepareSuccessful();
           return false;
         }
       }
@@ -95,8 +93,8 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
     return result.toArray(new UsageInfo[result.size()]);
   }
 
-  protected List<String> getConflictDescriptions(UsageInfo[] usages) {
-    ArrayList<String> conflicts = new ArrayList<String>();
+  protected Map<PsiElement, String> getConflictDescriptions(UsageInfo[] usages) {
+    Map<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
     HashSet<PsiElement> processed = new HashSet<PsiElement>();
     String typeString = StringUtil.capitalize(UsageViewUtil.getType(myMember));
     for (UsageInfo usageInfo : usages) {
@@ -117,12 +115,12 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
             if (mySettings.getNameForField(field) == null) {
               String message = RefactoringBundle.message("0.uses.non.static.1.which.is.not.passed.as.a.parameter", typeString,
                                                          RefactoringUIUtil.getDescription(field, true));
-              conflicts.add(message);
+              conflicts.put(field, message);
             }
           }
           else {
             String message = RefactoringBundle.message("0.uses.1.which.needs.class.instance", typeString, RefactoringUIUtil.getDescription(referencedElement, true));
-            conflicts.add(message);
+            conflicts.put(referencedElement, message);
           }
         }
       }
@@ -131,7 +129,7 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
         final PsiMethod overridingMethod = ((PsiMethod)usageInfo.getElement());
         String message = RefactoringBundle.message("method.0.is.overridden.by.1", RefactoringUIUtil.getDescription(myMember, false),
                                                    RefactoringUIUtil.getDescription(overridingMethod, true));
-        conflicts.add(message);
+        conflicts.put(overridingMethod, message);
       }
       else {
         PsiElement element = usageInfo.getElement();
@@ -149,32 +147,31 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
 
         if (inaccessible.isEmpty()) continue;
 
-        conflicts.add(createInaccessibleFieldsConflictDescription(inaccessible, container));
+        final Map<PsiElement, String> inaccessibleConflicts = createInaccessibleFieldsConflictDescription(inaccessible, container);
+        conflicts.putAll(inaccessibleConflicts);
       }
     }
     return conflicts;
   }
 
-  private static String createInaccessibleFieldsConflictDescription(ArrayList<PsiField> inaccessible, PsiElement container) {
+  private static Map<PsiElement, String> createInaccessibleFieldsConflictDescription(ArrayList<PsiField> inaccessible, PsiElement container) {
     if (inaccessible.size() == 1) {
       final PsiField field = inaccessible.get(0);
-      return RefactoringBundle.message("field.0.is.not.accessible",
+      return Collections.<PsiElement, String>singletonMap(field, RefactoringBundle.message("field.0.is.not.accessible",
                                        CommonRefactoringUtil.htmlEmphasize(field.getName()),
-                                       RefactoringUIUtil.getDescription(container, true));
+                                       RefactoringUIUtil.getDescription(container, true)));
     } else {
-      StringBuffer fieldsBuffer = new StringBuffer();
+      Map<PsiElement, String> result = new HashMap<PsiElement, String>();
       for (int j = 0; j < inaccessible.size(); j++) {
         PsiField field = inaccessible.get(j);
+        result.put(field, RefactoringBundle.message("field.0.is.not.accessible",
+                                       CommonRefactoringUtil.htmlEmphasize(field.getName()),
+                                       RefactoringUIUtil.getDescription(container, true)));
+
 
-        if (j > 0) {
-          fieldsBuffer.append(", ");
-        }
-        fieldsBuffer.append(CommonRefactoringUtil.htmlEmphasize(field.getName()));
       }
 
-      return RefactoringBundle.message("fields.0.are.not.accessible",
-                                       fieldsBuffer.toString(),
-                                       RefactoringUIUtil.getDescription(container, true));
+      return result;
     }
   }
 
index d5cdc429d54aba8a78c9c6177a0c90a521a7664d..4f44eae2de7cc321bf733d7bd6c4bc2ec60b9312 100644 (file)
@@ -18,6 +18,7 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.ScrollType;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.psi.*;
 import com.intellij.refactoring.HelpID;
 import com.intellij.refactoring.RefactoringActionHandler;
@@ -36,6 +37,7 @@ import org.jetbrains.annotations.NotNull;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.LinkedHashMap;
 
 public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog.Callback, ElementsHandler {
   private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.memberPullUp.JavaPullUpHandler");
@@ -170,11 +172,13 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
     final MemberInfo[] infos = dialog.getSelectedMemberInfos();
     PsiClass superClass = dialog.getSuperClass();
     if (!checkWritable(superClass, infos)) return false;
-    String[] conflicts = PullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, null, null, dialog.getContainmentVerifier());
-    if (conflicts.length > 0) {
+    LinkedHashMap<PsiElement,String> conflicts = PullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, null, null, dialog.getContainmentVerifier());
+    if (!conflicts.isEmpty()) {
       ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
       conflictsDialog.show();
-      return conflictsDialog.isOK();
+      final boolean ok = conflictsDialog.isOK();
+      if (!ok && conflictsDialog.isShowConflicts()) dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
+      return ok;
     }
     return true;
   }
index d5ced0943fd9a88ccfae5e76470eb9d476298345..209b30395658ec077c7b744f62822b9d65b8df98 100644 (file)
@@ -14,19 +14,21 @@ import com.intellij.psi.util.MethodSignatureUtil;
 import com.intellij.psi.util.PsiUtil;
 import com.intellij.psi.util.TypeConversionUtil;
 import com.intellij.refactoring.RefactoringBundle;
-import com.intellij.refactoring.util.*;
+import com.intellij.refactoring.util.CommonRefactoringUtil;
+import com.intellij.refactoring.util.RefactoringHierarchyUtil;
+import com.intellij.refactoring.util.RefactoringUIUtil;
+import com.intellij.refactoring.util.RefactoringUtil;
 import com.intellij.refactoring.util.classMembers.ClassMemberReferencesVisitor;
 import com.intellij.refactoring.util.classMembers.InterfaceContainmentVerifier;
 import com.intellij.refactoring.util.classMembers.MemberInfo;
 import com.intellij.usageView.UsageInfo;
-import com.intellij.util.ArrayUtil;
 
 import java.util.*;
 
 public class PullUpConflictsUtil {
   private PullUpConflictsUtil() {}
 
-  public static String[] checkConflicts(final MemberInfo[] infos,
+  public static LinkedHashMap<PsiElement, String> checkConflicts(final MemberInfo[] infos,
                                         PsiClass subclass,
                                         PsiClass superClass,
                                         PsiPackage targetPackage,
@@ -58,11 +60,11 @@ public class PullUpConflictsUtil {
         movedMembers.add(member);
       }
     }
-    final LinkedHashSet<String> conflictsList = new LinkedHashSet<String>();
+    final LinkedHashMap<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
     if (superClass != null) {
-      checkSuperclassMembers(superClass, infos, conflictsList);
+      checkSuperclassMembers(superClass, infos, conflicts);
       if (isInterfaceTarget) {
-        checkInterfaceTarget(infos, conflictsList);
+        checkInterfaceTarget(infos, conflicts);
       }
     }
     // check if moved methods use other members in the classes between Subclass and Superclass
@@ -71,7 +73,7 @@ public class PullUpConflictsUtil {
       if (member instanceof PsiMethod || member instanceof PsiClass) {
         ConflictingUsagesOfSubClassMembers visitor =
           new ConflictingUsagesOfSubClassMembers(member, movedMembers, abstractMethods, subclass, superClass,
-                                                 superClass != null ? null : targetPackage, conflictsList,
+                                                 superClass != null ? null : targetPackage, conflicts,
                                                  interfaceContainmentVerifier);
         member.accept(visitor);
       }
@@ -83,11 +85,11 @@ public class PullUpConflictsUtil {
       checkModuleConflictsList.add(method.getTypeParameterList());
     }
     RefactoringUtil.analyzeModuleConflicts(subclass.getProject(), checkModuleConflictsList,
-                                           new UsageInfo[0], targetRepresentativeElement, conflictsList);
-    return ArrayUtil.toStringArray(conflictsList);
+                                           new UsageInfo[0], targetRepresentativeElement, conflicts);
+    return conflicts;
   }
 
-  private static void checkInterfaceTarget(MemberInfo[] infos, LinkedHashSet<String> conflictsList) {
+  private static void checkInterfaceTarget(MemberInfo[] infos, LinkedHashMap<PsiElement, String> conflictsList) {
     for (MemberInfo info : infos) {
       PsiElement member = info.getMember();
 
@@ -98,21 +100,21 @@ public class PullUpConflictsUtil {
           String message =
             RefactoringBundle.message("0.is.not.static.it.cannot.be.moved.to.the.interface", RefactoringUIUtil.getDescription(member, false));
           message = CommonRefactoringUtil.capitalize(message);
-          conflictsList.add(message);
+          conflictsList.put(member, message);
         }
       }
 
       if (member instanceof PsiField && ((PsiField)member).getInitializer() == null) {
         String message = RefactoringBundle.message("0.is.not.initialized.in.declaration.such.fields.are.not.allowed.in.interfaces",
                                                    RefactoringUIUtil.getDescription(member, false));
-        conflictsList.add(CommonRefactoringUtil.capitalize(message));
+        conflictsList.put(member, CommonRefactoringUtil.capitalize(message));
       }
     }
   }
 
   private static void checkSuperclassMembers(PsiClass superClass,
                                              MemberInfo[] infos,
-                                             LinkedHashSet<String> conflictsList) {
+                                             LinkedHashMap<PsiElement, String> conflictsList) {
     for (MemberInfo info : infos) {
       PsiMember member = info.getMember();
       boolean isConflict = false;
@@ -133,7 +135,7 @@ public class PullUpConflictsUtil {
                                                    RefactoringUIUtil.getDescription(superClass, false),
                                                    RefactoringUIUtil.getDescription(member, false));
         message = CommonRefactoringUtil.capitalize(message);
-        conflictsList.add(message);
+        conflictsList.put(superClass, message);
       }
     }
 
@@ -146,13 +148,13 @@ public class PullUpConflictsUtil {
     private final PsiClass mySubclass;
     private final PsiClass mySuperClass;
     private final PsiPackage myTargetPackage;
-    private final Set<String> myConflictsList;
+    private final LinkedHashMap<PsiElement, String> myConflictsList;
     private final InterfaceContainmentVerifier myInterfaceContainmentVerifier;
 
     ConflictingUsagesOfSubClassMembers(PsiElement scope,
                                        Set<PsiElement> movedMembers, Set<PsiMethod> abstractMethods,
                                        PsiClass subclass, PsiClass superClass,
-                                       PsiPackage targetPackage, Set<String> conflictsList,
+                                       PsiPackage targetPackage, LinkedHashMap<PsiElement, String> conflictsList,
                                        InterfaceContainmentVerifier interfaceContainmentVerifier) {
       super(subclass);
       myScope = scope;
@@ -186,7 +188,7 @@ public class PullUpConflictsUtil {
                                                        RefactoringUIUtil.getDescription(myScope, false),
                                                        RefactoringUIUtil.getDescription(classMember, true));
             message = CommonRefactoringUtil.capitalize(message);
-            myConflictsList.add(message);
+            myConflictsList.put(classMember, message);
 
           }
           return;
@@ -197,7 +199,7 @@ public class PullUpConflictsUtil {
                                                        RefactoringUIUtil.getDescription(myScope, false),
                                                        RefactoringUIUtil.getDescription(classMember, true));
             message = CommonRefactoringUtil.capitalize(message);
-            myConflictsList.add(message);
+            myConflictsList.put(classMember, message);
           }
         }
       }
index 25d6dd13ad3842f5b8f6e5fb82f79b7b0d7e5d17..6c6edd706eec228fba28bd0c0f8405fed09b1fc1 100644 (file)
@@ -9,15 +9,13 @@ import com.intellij.refactoring.util.RefactoringUIUtil;
 import com.intellij.refactoring.util.classMembers.ClassMemberReferencesVisitor;
 import com.intellij.refactoring.util.classMembers.MemberInfo;
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.*;
 
 public class PushDownConflicts {
   private final PsiClass myClass;
   private final Set<PsiMember> myMovedMembers;
   private final Set<PsiMember> myAbstractMembers;
-  private final ArrayList<String> myConflicts;
+  private final Map<PsiElement, String> myConflicts;
 
 
   public PushDownConflicts(PsiClass aClass, MemberInfo[] memberInfos) {
@@ -35,14 +33,14 @@ public class PushDownConflicts {
       }
     }
 
-    myConflicts = new ArrayList<String>();
+    myConflicts = new HashMap<PsiElement, String>();
   }
 
   public boolean isAnyConflicts() {
     return !myConflicts.isEmpty();
   }
 
-  public ArrayList<String> getConflicts() {
+  public Map<PsiElement, String> getConflicts() {
     return myConflicts;
   }
 
@@ -71,7 +69,7 @@ public class PushDownConflicts {
             if (qualifierType instanceof PsiClassType) {
               final PsiClass aClass = ((PsiClassType)qualifierType).resolve();
               if (!InheritanceUtil.isInheritorOrSelf(aClass, targetClass, true)) {
-                myConflicts.add(RefactoringBundle.message("pushed.members.will.not.be.visible.from.certain.call.sites"));
+                myConflicts.put(aClass, RefactoringBundle.message("pushed.members.will.not.be.visible.from.certain.call.sites"));
                 break Members;
               }
             }
@@ -84,9 +82,10 @@ public class PushDownConflicts {
   public void checkMemberPlacementInTargetClassConflict(final PsiClass targetClass, final PsiMember movedMember) {
     if (movedMember instanceof PsiField) {
       String name = movedMember.getName();
-      if (targetClass.findFieldByName(name, false) != null) {
+      final PsiField field = targetClass.findFieldByName(name, false);
+      if (field != null) {
         String message = RefactoringBundle.message("0.already.contains.field.1", RefactoringUIUtil.getDescription(targetClass, false), CommonRefactoringUtil.htmlEmphasize(name));
-        myConflicts.add(CommonRefactoringUtil.capitalize(message));
+        myConflicts.put(field, CommonRefactoringUtil.capitalize(message));
       }
     }
     else if (movedMember instanceof PsiMethod) {
@@ -94,10 +93,11 @@ public class PushDownConflicts {
       assert modifierList != null;
       if (!modifierList.hasModifierProperty(PsiModifier.ABSTRACT)) {
         PsiMethod method = (PsiMethod)movedMember;
-        if (targetClass.findMethodBySignature(method, false) != null) {
+        final PsiMethod overrider = targetClass.findMethodBySignature(method, false);
+        if (overrider != null) {
           String message = RefactoringBundle.message("0.is.already.overridden.in.1",
                                                      RefactoringUIUtil.getDescription(method, true), RefactoringUIUtil.getDescription(targetClass, false));
-          myConflicts.add(CommonRefactoringUtil.capitalize(message));
+          myConflicts.put(overrider, CommonRefactoringUtil.capitalize(message));
         }
       }
     }
@@ -111,7 +111,7 @@ public class PushDownConflicts {
         if (name.equals(innerClass.getName())) {
           String message = RefactoringBundle.message("0.already.contains.inner.class.named.1", RefactoringUIUtil.getDescription(targetClass, false),
                                                 CommonRefactoringUtil.htmlEmphasize(name));
-          myConflicts.add(message);
+          myConflicts.put(innerClass, message);
         }
       }
     }
@@ -130,7 +130,7 @@ public class PushDownConflicts {
         String message = RefactoringBundle.message("0.uses.1.which.is.pushed.down", RefactoringUIUtil.getDescription(mySource, false),
                                               RefactoringUIUtil.getDescription(classMember, false));
         message = CommonRefactoringUtil.capitalize(message);
-        myConflicts.add(message);
+        myConflicts.put(mySource, message);
       }
     }
   }
index 3e995e4ef64df08a448699716b2bbbf5d5a9e9d6..a750fcfc019e25b2c6a23f761268888c547c03d5 100644 (file)
@@ -12,8 +12,8 @@ import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
 
 /**
  *  @author dsl
@@ -60,7 +60,7 @@ public class AutocreatingSingleSourceRootMoveDestination extends AutocreatingMov
   }
 
   public void analyzeModuleConflicts(final Collection<PsiElement> elements,
-                                     ArrayList<String> conflicts, final UsageInfo[] usages) {
+                                     Map<PsiElement,String> conflicts, final UsageInfo[] usages) {
     RefactoringUtil.analyzeModuleConflicts(getTargetPackage().getManager().getProject(), elements, usages, mySourceRoot, conflicts);
   }
 
index bc3d84bc275949888f7f87c2b08ec601ee47d3bc..82eb2071befd55dc454daefd1eb9e183f6ddc1a6 100644 (file)
@@ -264,11 +264,12 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
     return result;
   }
 
-  public List<String> getConflicts(final UsageInfo[] usages) {
-    List<String> conflicts = new ArrayList<String>();
+  public Map<PsiElement, String> getConflicts(final UsageInfo[] usages) {
+    Map<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
 
-    if (myTargetClass.findInnerClassByName(myClassToMove.getName(), false) != null) {
-      conflicts.add(RefactoringBundle.message("move.to.inner.duplicate.inner.class",
+    final PsiClass innerClass = myTargetClass.findInnerClassByName(myClassToMove.getName(), false);
+    if (innerClass != null) {
+      conflicts.put(innerClass, RefactoringBundle.message("move.to.inner.duplicate.inner.class",
                                               CommonRefactoringUtil.htmlEmphasize(myTargetClass.getQualifiedName()),
                                               CommonRefactoringUtil.htmlEmphasize(myClassToMove.getName())));
     }
@@ -343,10 +344,10 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
   }
 
   private class ConflictsCollector {
-    private final List<String> myConflicts;
+    private final Map<PsiElement, String> myConflicts;
     private final Set<PsiElement> myReportedContainers = new HashSet<PsiElement>();
 
-    public ConflictsCollector(final List<String> conflicts) {
+    public ConflictsCollector(final Map<PsiElement, String> conflicts) {
       myConflicts = conflicts;
     }
 
@@ -361,7 +362,7 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
         final String message = RefactoringBundle.message("element.will.no.longer.be.accessible",
                                                          targetDescription,
                                                          RefactoringUIUtil.getDescription(container, true));
-        myConflicts.add(message);
+        myConflicts.put(targetElement, message);
       }
     }
   }
index b0b1c1634e879cbf748d57a0f9c0f7df3c8717e1..b549bb575611e0261ec232b9e9d415216c80e746 100644 (file)
@@ -120,7 +120,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
   @NotNull
   protected UsageInfo[] findUsages() {
     List<UsageInfo> allUsages = new ArrayList<UsageInfo>();
-    ArrayList<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     for (PsiElement element : myElementsToMove) {
       String newName = getNewQName(element);
       final UsageInfo[] usages = MoveClassesOrPackagesUtil.findUsages(element, mySearchInComments,
@@ -148,14 +148,14 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
   }
 
   protected static class ConflictsUsageInfo extends UsageInfo {
-    private final ArrayList<String> myConflicts;
+    private final Map<PsiElement, String> myConflicts;
 
-    public ConflictsUsageInfo(PsiElement pseudoElement, ArrayList<String> conflicts) {
+    public ConflictsUsageInfo(PsiElement pseudoElement, Map<PsiElement, String> conflicts) {
       super(pseudoElement);
       myConflicts = conflicts;
     }
 
-    public ArrayList<String> getConflicts() {
+    public Map<PsiElement, String> getConflicts() {
       return myConflicts;
     }
   }
@@ -164,11 +164,11 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     final UsageInfo[] usages = refUsages.get();
-    final ArrayList<String> conflicts = new ArrayList<String>();
+    final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     ArrayList<UsageInfo> filteredUsages = new ArrayList<UsageInfo>();
     for (UsageInfo usage : usages) {
       if (usage instanceof ConflictsUsageInfo) {
-        conflicts.addAll(((ConflictsUsageInfo)usage).getConflicts());
+        conflicts.putAll(((ConflictsUsageInfo)usage).getConflicts());
       }
       else {
         filteredUsages.add(usage);
@@ -188,7 +188,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
     return false;
   }
 
-  private void detectPackageLocalsUsed(final ArrayList<String> conflicts) {
+  private void detectPackageLocalsUsed(final Map<PsiElement, String> conflicts) {
     PackageLocalsUsageCollector visitor = new PackageLocalsUsageCollector(myElementsToMove, myTargetPackage, conflicts);
 
     for (PsiElement element : myElementsToMove) {
@@ -199,7 +199,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
     }
   }
 
-  private void detectPackageLocalsMoved(final UsageInfo[] usages, final ArrayList<String> conflicts) {
+  private void detectPackageLocalsMoved(final UsageInfo[] usages, final Map<PsiElement, String> conflicts) {
 //    final HashSet reportedPackageLocalUsed = new HashSet();
     final HashSet<PsiClass> movedClasses = new HashSet<PsiClass>();
     final HashMap<PsiClass,HashSet<PsiElement>> reportedClassToContainers = new HashMap<PsiClass, HashSet<PsiElement>>();
@@ -237,7 +237,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
                                                                    CommonRefactoringUtil.htmlEmphasize(aClass.getName()),
                                                                    RefactoringUIUtil.getDescription(
                                                                    container, true));
-                  conflicts.add(message);
+                  conflicts.put(aClass, message);
                 }
               }
             }
@@ -470,11 +470,11 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
   }
 
   private class MyClassInstanceReferenceVisitor implements ClassInstanceScanner.ClassInstanceReferenceVisitor {
-    private final ArrayList<String> myConflicts;
+    private final Map<PsiElement, String> myConflicts;
     private final HashMap<PsiModifierListOwner,HashSet<PsiElement>> myReportedElementToContainer = new HashMap<PsiModifierListOwner, HashSet<PsiElement>>();
     private final HashMap<PsiClass, RefactoringUtil.IsDescendantOf> myIsDescendantOfCache = new HashMap<PsiClass,RefactoringUtil.IsDescendantOf>();
 
-    public MyClassInstanceReferenceVisitor(ArrayList<String> conflicts) {
+    public MyClassInstanceReferenceVisitor(Map<PsiElement, String> conflicts) {
       myConflicts = conflicts;
     }
 
@@ -538,7 +538,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
               if (!myTargetPackage.equalToPackage(aPackage)) {
                 String message = RefactoringBundle.message("0.will.be.inaccessible.from.1", RefactoringUIUtil.getDescription(member, true),
                                                       RefactoringUIUtil.getDescription(container, true));
-                myConflicts.add(CommonRefactoringUtil.capitalize(message));
+                myConflicts.put(member, CommonRefactoringUtil.capitalize(message));
               }
             }
           }
index 1a042e003c32577a205b042b0cd2cb8807c8d9f2..0ce688911ee546aedfe7e0dff825c15d838255d8 100644 (file)
@@ -9,8 +9,8 @@ import com.intellij.usageView.UsageInfo;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
 
 /**
  *  @author dsl
@@ -77,7 +77,7 @@ public class MultipleRootsMoveDestination extends AutocreatingMoveDestination {
   }
 
   public void analyzeModuleConflicts(final Collection<PsiElement> elements,
-                                     ArrayList<String> conflicts, final UsageInfo[] usages) {
+                                     Map<PsiElement,String> conflicts, final UsageInfo[] usages) {
   }
 
   public PsiDirectory getTargetIfExists(PsiDirectory source) {
index dee8266fe40e3ba5d72c2178fa0c251e0611c024..f99de8d920dc8cd122311158034401a8fd960228 100644 (file)
@@ -4,22 +4,22 @@ import com.intellij.psi.*;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.refactoring.PackageWrapper;
 import com.intellij.refactoring.RefactoringBundle;
+import com.intellij.refactoring.util.CommonRefactoringUtil;
 import com.intellij.refactoring.util.ConflictsUtil;
-import com.intellij.util.VisibilityUtil;
 import com.intellij.refactoring.util.RefactoringUIUtil;
-import com.intellij.refactoring.util.CommonRefactoringUtil;
+import com.intellij.util.VisibilityUtil;
 import com.intellij.util.containers.HashMap;
 
 import java.util.HashSet;
-import java.util.List;
+import java.util.Map;
 
 class PackageLocalsUsageCollector extends JavaRecursiveElementWalkingVisitor {
   private final HashMap<PsiElement,HashSet<PsiElement>> myReported = new HashMap<PsiElement, HashSet<PsiElement>>();
   private final PsiElement[] myElementsToMove;
-  private final List<String> myConflicts;
+  private final Map<PsiElement, String> myConflicts;
   private final PackageWrapper myTargetPackage;
 
-  public PackageLocalsUsageCollector(final PsiElement[] elementsToMove, final PackageWrapper targetPackage, List<String> conflicts) {
+  public PackageLocalsUsageCollector(final PsiElement[] elementsToMove, final PackageWrapper targetPackage, Map<PsiElement,String> conflicts) {
     myElementsToMove = elementsToMove;
     myConflicts = conflicts;
     myTargetPackage = targetPackage;
@@ -56,7 +56,7 @@ class PackageLocalsUsageCollector extends JavaRecursiveElementWalkingVisitor {
                 final String message = RefactoringBundle.message("0.uses.a.package.local.1",
                                                                  RefactoringUIUtil.getDescription(container, true),
                                                                  RefactoringUIUtil.getDescription(resolved, true));
-                myConflicts.add(CommonRefactoringUtil.capitalize(message));
+                myConflicts.put(resolved, CommonRefactoringUtil.capitalize(message));
                 reportedRefs.add(container);
               }
             }
index f9fe8a92aa570fac276ef3790c363a854a8476c5..0cb10e960173b62813620f90a830ae7b3848a990 100644 (file)
@@ -7,8 +7,8 @@ import com.intellij.refactoring.PackageWrapper;
 import com.intellij.refactoring.util.RefactoringUtil;
 import com.intellij.usageView.UsageInfo;
 
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
 
 /**
  *  @author dsl
@@ -54,7 +54,7 @@ public class SingleSourceRootMoveDestination implements MoveDestination {
   }
 
   public void analyzeModuleConflicts(final Collection<PsiElement> elements,
-                                     ArrayList<String> conflicts, final UsageInfo[] usages) {
+                                     Map<PsiElement,String> conflicts, final UsageInfo[] usages) {
     RefactoringUtil.analyzeModuleConflicts(myPackage.getManager().getProject(), elements, usages, myTargetDirectory, conflicts);
   }
 
index 53b73d3d9ae6261815cc30d5bec0c24481a1ea77..8a411847863e369559dd3d1a469cc25d15b922be 100644 (file)
@@ -27,7 +27,10 @@ import com.intellij.refactoring.listeners.RefactoringElementListener;
 import com.intellij.refactoring.move.MoveCallback;
 import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesUtil;
 import com.intellij.refactoring.rename.RenameUtil;
-import com.intellij.refactoring.util.*;
+import com.intellij.refactoring.util.ConflictsUtil;
+import com.intellij.refactoring.util.NonCodeUsageInfo;
+import com.intellij.refactoring.util.RefactoringUIUtil;
+import com.intellij.refactoring.util.RefactoringUtil;
 import com.intellij.usageView.UsageInfo;
 import com.intellij.usageView.UsageViewDescriptor;
 import com.intellij.usageView.UsageViewUtil;
@@ -38,10 +41,7 @@ import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
+import java.util.*;
 
 public class MoveInnerProcessor extends BaseRefactoringProcessor {
   private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.move.moveInner.MoveInnerProcessor");
@@ -326,7 +326,7 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
   }
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
-    final ArrayList<String> conflicts = new ArrayList<String>();
+    final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
 
     class Visitor extends JavaRecursiveElementWalkingVisitor {
       private final HashMap<PsiElement,HashSet<PsiElement>> reported = new HashMap<PsiElement, HashSet<PsiElement>>();
@@ -347,7 +347,7 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
             String message = RefactoringBundle.message("0.will.become.inaccessible.from.1",
                                                        RefactoringUIUtil.getDescription(resolved, true),
                                                        RefactoringUIUtil.getDescription(container, true));
-            conflicts.add(message);
+            conflicts.put(resolved, message);
           }
         }
       }
index 84d2b271f85aab03d2da40f953bc92de67ffb9c9..25451fbab762259cfe9c3cae79c235b1a3113f0e 100644 (file)
@@ -69,18 +69,18 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     final UsageInfo[] usages = refUsages.get();
-    ArrayList<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     final Set<PsiMember> members = new HashSet<PsiMember>();
     members.add(myMethod);
     if (myTargetVariable instanceof PsiField) members.add((PsiMember)myTargetVariable);
     if (!myTargetClass.isInterface()) {
-      conflicts.addAll(Arrays.asList(MoveMembersProcessor.analyzeAccessibilityConflicts(members, myTargetClass, new LinkedHashSet<String>(), myNewVisibility)));
+      conflicts.putAll(MoveMembersProcessor.analyzeAccessibilityConflicts(members, myTargetClass, new LinkedHashMap<PsiElement, String>(), myNewVisibility));
     }
     else {
       for (final UsageInfo usage : usages) {
         if (usage instanceof InheritorUsageInfo) {
-          conflicts.addAll(Arrays.asList(MoveMembersProcessor.analyzeAccessibilityConflicts(
-            members, ((InheritorUsageInfo)usage).getInheritor(), new LinkedHashSet<String>(), myNewVisibility)));
+          conflicts.putAll(MoveMembersProcessor.analyzeAccessibilityConflicts(
+            members, ((InheritorUsageInfo)usage).getInheritor(), new LinkedHashMap<PsiElement, String>(), myNewVisibility));
         }
       }
     }
@@ -99,7 +99,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
               String message = RefactoringBundle.message("0.contains.call.with.null.argument.for.parameter.1",
                                                          RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(methodCall), true),
                                                          CommonRefactoringUtil.htmlEmphasize(parameter.getName()));
-              conflicts.add(message);
+              conflicts.put(instanceValue, message);
             }
           }
         }
index aad5c48669eaaf44f473f8b8645808a4db69b5f5..cd99907a10e4a51728d8fa9d862bff1488c4bee9 100644 (file)
@@ -26,7 +26,6 @@ import com.intellij.refactoring.util.*;
 import com.intellij.usageView.UsageInfo;
 import com.intellij.usageView.UsageViewDescriptor;
 import com.intellij.usageView.UsageViewUtil;
-import com.intellij.util.ArrayUtil;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.VisibilityUtil;
 import com.intellij.util.containers.HashMap;
@@ -223,7 +222,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
   }
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
-    final ArrayList<String> conflicts = new ArrayList<String>();
+    final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     final UsageInfo[] usages = refUsages.get();
     try {
       addInaccessiblleConflicts(conflicts, usages);
@@ -235,7 +234,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
     return showConflicts(conflicts);
   }
 
-  private void addInaccessiblleConflicts(final ArrayList<String> conflicts, final UsageInfo[] usages) throws IncorrectOperationException {
+  private void addInaccessiblleConflicts(final Map<PsiElement, String> conflicts, final UsageInfo[] usages) throws IncorrectOperationException {
     String newVisibility = myNewVisibility;
     if (VisibilityUtil.ESCALATE_VISIBILITY.equals(newVisibility)) { //Still need to check for access object
       newVisibility = PsiModifier.PUBLIC;
@@ -269,7 +268,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
               String message =
                 RefactoringBundle.message("0.with.1.visibility.is.not.accesible.from.2", RefactoringUIUtil.getDescription(member, true),
                                           newVisibility, RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
-              conflicts.add(message);
+              conflicts.put(member, message);
             }
           }
         }
@@ -289,8 +288,8 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
   }
 
   private boolean canRefactor() {
-    final String[] conflicts = analyzeMoveConflicts(myMembersToMove, myTargetClass, myNewVisibility);
-    if (conflicts.length > 0) {
+    final Map<PsiElement, String> conflicts = analyzeMoveConflicts(myMembersToMove, myTargetClass, myNewVisibility);
+    if (!conflicts.isEmpty()) {
       ConflictsDialog dialog = new ConflictsDialog(myProject, conflicts);
       dialog.show();
       return dialog.isOK();
@@ -298,15 +297,15 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
     return true;
   }
 
-  private static String[] analyzeMoveConflicts(@NotNull Set<PsiMember> membersToMove, final PsiClass targetClass, final String newVisibility) {
-    final LinkedHashSet<String> conflicts = new LinkedHashSet<String>();
+  private static Map<PsiElement, String> analyzeMoveConflicts(@NotNull Set<PsiMember> membersToMove, final PsiClass targetClass, final String newVisibility) {
+    final LinkedHashMap<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
     for (final PsiMember member : membersToMove) {
       if (member instanceof PsiMethod) {
         PsiMethod method = (PsiMethod)member;
         if (hasMethod(targetClass, method)) {
           String message = RefactoringBundle.message("0.already.exists.in.the.target.class", RefactoringUIUtil.getDescription(method, false));
           message = CommonRefactoringUtil.capitalize(message);
-          conflicts.add(message);
+          conflicts.put(method, message);
         }
       }
       else if (member instanceof PsiField) {
@@ -314,16 +313,16 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
         if (hasField(targetClass, field)) {
           String message = RefactoringBundle.message("0.already.exists.in.the.target.class", RefactoringUIUtil.getDescription(field, false));
           message = CommonRefactoringUtil.capitalize(message);
-          conflicts.add(message);
+          conflicts.put(field, message);
         }
       }
     }
     return analyzeAccessibilityConflicts(membersToMove, targetClass, conflicts, newVisibility);
   }
 
-  public static String[] analyzeAccessibilityConflicts(@NotNull Set<PsiMember> membersToMove,
+  public static Map<PsiElement, String> analyzeAccessibilityConflicts(@NotNull Set<PsiMember> membersToMove,
                                                 final PsiClass targetClass,
-                                                final LinkedHashSet<String> conflicts, String newVisibility) {
+                                                final LinkedHashMap<PsiElement, String> conflicts, String newVisibility) {
     if (VisibilityUtil.ESCALATE_VISIBILITY.equals(newVisibility)) { //Still need to check for access object
       newVisibility = PsiModifier.PUBLIC;
     }
@@ -353,7 +352,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
                                                        VisibilityUtil.getVisibilityStringToDisplay(targetClass),
                                                        RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(ref), true));
             message = CommonRefactoringUtil.capitalize(message);
-            conflicts.add(message);
+            conflicts.put(targetClass, message);
           }
           //check for member accessibility
           else if (!manager.getResolveHelper().isAccessible(member, modifierList, ref, null, null)) {
@@ -362,15 +361,15 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
                                                        VisibilityUtil.getVisibilityStringToDisplay(member),
                                                        RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(ref), true));
             message = CommonRefactoringUtil.capitalize(message);
-            conflicts.add(message);
+            conflicts.put(member, message);
           }
         }
       }
     }
-    return ArrayUtil.toStringArray(conflicts);
+    return conflicts;
   }
 
-  private static void checkUsedElements(PsiMember member, PsiElement scope, @NotNull Set<PsiMember> membersToMove, PsiClass newContext, LinkedHashSet<String> conflicts) {
+  private static void checkUsedElements(PsiMember member, PsiElement scope, @NotNull Set<PsiMember> membersToMove, PsiClass newContext, LinkedHashMap<PsiElement, String> conflicts) {
     if(scope instanceof PsiReferenceExpression) {
       PsiReferenceExpression refExpr = (PsiReferenceExpression)scope;
       PsiElement refElement = refExpr.resolve();
@@ -420,14 +419,14 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
                                          PsiClass newContext,
                                          PsiClass accessClass,
                                          PsiMember member,
-                                         LinkedHashSet<String> conflicts) {
+                                         LinkedHashMap<PsiElement, String> conflicts) {
     if (!PsiUtil.isAccessible(refMember, newContext, accessClass)) {
       String message = RefactoringBundle.message("0.is.1.and.will.not.be.accessible.from.2.in.the.target.class",
                                                  RefactoringUIUtil.getDescription(refMember, true),
                                                  VisibilityUtil.getVisibilityStringToDisplay(refMember),
                                                  RefactoringUIUtil.getDescription(member, false));
       message = CommonRefactoringUtil.capitalize(message);
-      conflicts.add(message);
+      conflicts.put(refMember, message);
     }
   }
 
index b735180dbf47f3c767b8ce79ea1b9b9fdaaa1195..e37263ceaced974f378e7ab8ee3a9527e77be719 100644 (file)
@@ -18,8 +18,9 @@ import com.intellij.usageView.UsageViewDescriptor;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 public class RemoveMiddlemanProcessor extends FixableUsagesRefactoringProcessor {
   private static final Logger LOG = Logger.getInstance("#" + RemoveMiddlemanProcessor.class.getName());
@@ -60,12 +61,12 @@ public class RemoveMiddlemanProcessor extends FixableUsagesRefactoringProcessor
 
   @Override
   protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
-    final List<String> conflicts = new ArrayList<String>();
+    final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     for (MemberInfo memberInfo : myDelegateMethodInfos) {
       if (memberInfo.isChecked() && memberInfo.isToAbstract()) {
         final PsiMember psiMember = memberInfo.getMember();
         if (psiMember instanceof PsiMethod && ((PsiMethod)psiMember).findDeepestSuperMethods().length > 0) {
-          conflicts.add(SymbolPresentationUtil.getSymbolPresentableText(psiMember) + " will be deleted. Hierarchy will be broken");
+          conflicts.put(psiMember, SymbolPresentationUtil.getSymbolPresentableText(psiMember) + " will be deleted. Hierarchy will be broken");
         }
       }
     }
index aa9ecc4ceae4cee047b0b6c5533c6307e37a018f..e1acd21655460febff7bcf992a3b27c221431792 100644 (file)
@@ -187,7 +187,7 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor {
     return WHITE_SPACE_PATTERN.matcher(s).replaceAll("");
   }
 
-  public void findExistingNameConflicts(final PsiElement element, final String newName, final Collection<String> conflicts) {
+  public void findExistingNameConflicts(final PsiElement element, final String newName, final Map<PsiElement, String> conflicts) {
     if (element instanceof PsiCompiledElement) return;
     final PsiClass aClass = (PsiClass)element;
     if (newName.equals(aClass.getName())) return;
@@ -196,7 +196,7 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor {
       PsiClass[] innerClasses = containingClass.getInnerClasses();
       for (PsiClass innerClass : innerClasses) {
         if (newName.equals(innerClass.getName())) {
-          conflicts.add(RefactoringBundle.message("inner.class.0.is.already.defined.in.class.1", newName, containingClass.getQualifiedName()));
+          conflicts.put(innerClass, RefactoringBundle.message("inner.class.0.is.already.defined.in.class.1", newName, containingClass.getQualifiedName()));
           break;
         }
       }
@@ -207,7 +207,7 @@ public class RenameJavaClassProcessor extends RenamePsiElementProcessor {
       final PsiClass conflictingClass =
         JavaPsiFacade.getInstance(project).findClass(qualifiedNameAfterRename, GlobalSearchScope.allScope(project));
       if (conflictingClass != null) {
-        conflicts.add(RefactoringBundle.message("class.0.already.exists", qualifiedNameAfterRename));
+        conflicts.put(conflictingClass, RefactoringBundle.message("class.0.already.exists", qualifiedNameAfterRename));
       }
     }
   }
index a75d247a33bbc52ad60ac5ccd72363cc55e01095..add7e50def2996e64c20ea47f13c545828cc3640 100644 (file)
@@ -132,7 +132,7 @@ public class RenameJavaMethodProcessor extends RenameJavaMemberProcessor {
     findMemberHidesOuterMemberCollisions((PsiMethod) element, newName, result);
   }
 
-  public void findExistingNameConflicts(final PsiElement element, final String newName, final Collection<String> conflicts) {
+  public void findExistingNameConflicts(final PsiElement element, final String newName, final Map<PsiElement, String> conflicts) {
     if (element instanceof PsiCompiledElement) return;
     PsiMethod refactoredMethod = (PsiMethod)element;
     if (newName.equals(refactoredMethod.getName())) return;
index 0099b07e5a5315aabccef3eae4ed45398d375322..a63d6d648da8b674e381266f10648abb9243577b 100644 (file)
@@ -218,7 +218,7 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
     }
   }
 
-  public void findExistingNameConflicts(final PsiElement element, final String newName, final Collection<String> conflicts) {
+  public void findExistingNameConflicts(final PsiElement element, final String newName, final Map<PsiElement, String> conflicts) {
     if (element instanceof PsiCompiledElement) return;
     if (element instanceof PsiField) {
       PsiField refactoredField = (PsiField)element;
index d4c03f49331dbae6d26f7a203fc4dec38c5cf7d6..bf1c74eda00386f55f4b59291e89de724a4c28ab 100644 (file)
@@ -12,7 +12,6 @@ import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.Collection;
 import java.util.Map;
 
 /**
@@ -49,12 +48,13 @@ public class RenamePsiPackageProcessor extends RenamePsiElementProcessor {
   }
 
   @Override
-  public void findExistingNameConflicts(PsiElement element, String newName, Collection<String> conflicts) {
+  public void findExistingNameConflicts(PsiElement element, String newName, Map<PsiElement, String> conflicts) {
     final PsiPackage aPackage = (PsiPackage)element;
     final Project project = element.getProject();
     final String qualifiedNameAfterRename = getPackageQualifiedNameAfterRename(aPackage, newName, true);
-    if (JavaPsiFacade.getInstance(project).findClass(qualifiedNameAfterRename, GlobalSearchScope.allScope(project)) != null) {
-      conflicts.add("Class with qualified name \'" + qualifiedNameAfterRename + "\'  already exist");
+    final PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(qualifiedNameAfterRename, GlobalSearchScope.allScope(project));
+    if (psiClass != null) {
+      conflicts.put(psiClass, "Class with qualified name \'" + qualifiedNameAfterRename + "\'  already exist");
     }
   }
 
index 9e778ef784c2c31af2623597769d56e83a512642..621d0c7f0379ca5d2b02c7e753fd26d241cea7e3 100644 (file)
@@ -31,7 +31,7 @@ import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -251,30 +251,30 @@ public class ReplaceConstructorWithBuilderProcessor extends FixableUsagesRefacto
   }
 
   @Override
-  protected boolean showConflicts(List<String> conflicts) {
+  protected boolean showConflicts(Map<PsiElement, String> conflicts) {
     if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
-      throw new RuntimeException(StringUtil.join(conflicts, "\n"));
+      throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
     }
     return super.showConflicts(conflicts);
   }
 
   @Override
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
-    final List<String> conflicts = new ArrayList<String>();
+    final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
     final PsiClass builderClass =
       psiFacade.findClass(StringUtil.getQualifiedName(myPackageName, myClassName), GlobalSearchScope.projectScope(myProject));
     if (builderClass == null) {
       if (!myCreateNewBuilderClass) {
-        conflicts.add("Selected class was not found.");
+        conflicts.put(null, "Selected class was not found.");
       }
     } else if (myCreateNewBuilderClass){
-      conflicts.add("Class with chosen name already exist.");
+      conflicts.put(builderClass, "Class with chosen name already exist.");
     }
 
     final PsiMethod commonConstructor = getMostCommonConstructor();
     if (commonConstructor == null) {
-      conflicts.add("Found constructors are not reducible to simple chain");
+      conflicts.put(null, "Found constructors are not reducible to simple chain");
     }
 
     return showConflicts(conflicts);
index c0dacaa6c55514b5618c8af48bd15212575027ec..aee74b58d1e55dd76081127942a7e479fa04c697 100644 (file)
@@ -114,13 +114,14 @@ public class ReplaceConstructorWithFactoryProcessor extends BaseRefactoringProce
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     UsageInfo[] usages = refUsages.get();
 
-    ArrayList<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     final PsiResolveHelper helper = JavaPsiFacade.getInstance(myProject).getResolveHelper();
-    if (!helper.isAccessible(getConstructorContainingClass(), myTargetClass, null)) {
+    final PsiClass constructorContainingClass = getConstructorContainingClass();
+    if (!helper.isAccessible(constructorContainingClass, myTargetClass, null)) {
       String message = RefactoringBundle.message("class.0.is.not.accessible.from.target.1",
-                                                 RefactoringUIUtil.getDescription(getConstructorContainingClass(), true),
+                                                 RefactoringUIUtil.getDescription(constructorContainingClass, true),
                                                  RefactoringUIUtil.getDescription(myTargetClass, true));
-      conflicts.add(message);
+      conflicts.put(constructorContainingClass, message);
     }
 
     HashSet<PsiElement> reportedContainers = new HashSet<PsiElement>();
@@ -133,7 +134,7 @@ public class ReplaceConstructorWithFactoryProcessor extends BaseRefactoringProce
           String message = RefactoringBundle.message("target.0.is.not.accessible.from.1",
                                                      targetClassDescription,
                                                      RefactoringUIUtil.getDescription(container, true));
-          conflicts.add(message);
+          conflicts.put(myTargetClass, message);
         }
       }
     }
@@ -146,8 +147,9 @@ public class ReplaceConstructorWithFactoryProcessor extends BaseRefactoringProce
 
           if (PsiTreeUtil.isAncestor(containingClass, myTargetClass, true)) {
             String message = RefactoringBundle.message("constructor.being.refactored.is.used.in.initializer.of.0",
-                                                       RefactoringUIUtil.getDescription(field, true), RefactoringUIUtil.getDescription(getConstructorContainingClass(), false));
-            conflicts.add(message);
+                                                       RefactoringUIUtil.getDescription(field, true), RefactoringUIUtil.getDescription(
+                constructorContainingClass, false));
+            conflicts.put(field, message);
           }
         }
       }
index 02dd5db77de08ce06225bf58ba0993fcfcbd4ffa..06fb3a4fe3904a8a7eae096a76b4ca93de1dfb72 100644 (file)
@@ -11,7 +11,7 @@ import com.intellij.refactoring.RefactoringBundle;
 import com.intellij.usageView.UsageViewUtil;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.Collection;
+import java.util.Map;
 
 public class ConflictsUtil {
   private ConflictsUtil() {
@@ -31,7 +31,7 @@ public class ConflictsUtil {
   public static void checkMethodConflicts(@Nullable PsiClass aClass,
                                           PsiMethod refactoredMethod,
                                           PsiMethod prototype,
-                                          final Collection<String> conflicts) {
+                                          final Map<PsiElement,String> conflicts) {
     if (prototype == null) return;
 
     PsiMethod method = aClass != null ? aClass.findMethodBySignature(prototype, true) : null;
@@ -41,7 +41,7 @@ public class ConflictsUtil {
         final String classDescr = aClass instanceof PsiAnonymousClass ?
                                   RefactoringBundle.message("current.class") :
                                   RefactoringUIUtil.getDescription(aClass, false);
-        conflicts.add(RefactoringBundle.message("method.0.is.already.defined.in.the.1",
+        conflicts.put(method, RefactoringBundle.message("method.0.is.already.defined.in.the.1",
                                                 getMethodPrototypeString(prototype),
                                                 classDescr));
       }
@@ -55,10 +55,10 @@ public class ConflictsUtil {
             final String conflict = isMethodAbstract != isMyMethodAbstract ?
                                     RefactoringBundle.message("method.0.will.implement.method.of.the.base.class", protoMethodInfo, className) :
                                     RefactoringBundle.message("method.0.will.override.a.method.of.the.base.class", protoMethodInfo, className);
-            conflicts.add(conflict);
+            conflicts.put(method, conflict);
           }
           else { // prototype is private, will be compile-error
-            conflicts.add(RefactoringBundle.message("method.0.will.hide.method.of.the.base.class",
+            conflicts.put(method, RefactoringBundle.message("method.0.will.hide.method.of.the.base.class",
                                                     protoMethodInfo, className));
           }
         }
@@ -74,7 +74,7 @@ public class ConflictsUtil {
     );
   }
 
-  public static void checkFieldConflicts(@Nullable PsiClass aClass, String newName, final Collection<String> conflicts) {
+  public static void checkFieldConflicts(@Nullable PsiClass aClass, String newName, final Map<PsiElement, String> conflicts) {
     PsiField existingField = aClass != null ? aClass.findFieldByName(newName, true) : null;
     if (existingField != null) {
       if (aClass.equals(existingField.getContainingClass())) {
@@ -83,7 +83,7 @@ public class ConflictsUtil {
                            RefactoringUIUtil.getDescription(aClass, false);
         final String conflict = RefactoringBundle.message("field.0.is.already.defined.in.the.1",
                                                           existingField.getName(), className);
-        conflicts.add(conflict);
+        conflicts.put(existingField, conflict);
       }
       else { // method somewhere in base class
         if (!existingField.hasModifierProperty(PsiModifier.PRIVATE)) {
@@ -91,7 +91,7 @@ public class ConflictsUtil {
           String className = RefactoringUIUtil.getDescription(existingField.getContainingClass(), false);
           final String descr = RefactoringBundle.message("field.0.will.hide.field.1.of.the.base.class",
                                                          newName, fieldInfo, className);
-          conflicts.add(descr);
+          conflicts.put(existingField, descr);
         }
       }
     }
index 623d1b06c61a026885fa7ae0bf45aaf5f644dc1e..52ca2e53a46818542e994bb5183da03b8e486c08 100644 (file)
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 public abstract class FixableUsagesRefactoringProcessor extends BaseRefactoringProcessor {
   private static final Logger LOG = Logger.getInstance("#" + FixableUsagesRefactoringProcessor.class.getName());
@@ -47,11 +48,11 @@ public abstract class FixableUsagesRefactoringProcessor extends BaseRefactoringP
 
   protected abstract void findUsages(@NotNull List<FixableUsageInfo> usages);
 
-  protected static void checkConflicts(final Ref<UsageInfo[]> refUsages, final List<String> conflicts) {
+  protected static void checkConflicts(final Ref<UsageInfo[]> refUsages, final Map<PsiElement, String> conflicts) {
     for (UsageInfo info : refUsages.get()) {
       final String conflict = ((FixableUsageInfo)info).getConflictMessage();
       if (conflict != null) {
-        conflicts.add(XmlUtil.escape(conflict));
+        conflicts.put(info.getElement(), XmlUtil.escape(conflict));
       }
     }
   }
index deb9b5feaa583746adbe2dd86a301720b74d079c..6e9a962f8a84af44a258b401ef8192e85f51a63d 100644 (file)
@@ -1092,7 +1092,7 @@ public class RefactoringUtil {
                                             Collection<? extends PsiElement> scope,
                                             final UsageInfo[] usages,
                                             PsiElement target,
-                                            final Collection<String> conflicts) {
+                                            final Map<PsiElement, String> conflicts) {
     if (scope == null) return;
     final VirtualFile vFile = PsiUtilBase.getVirtualFile(target);
     if (vFile == null) return;
@@ -1103,7 +1103,7 @@ public class RefactoringUtil {
                                             final Collection<? extends PsiElement> scopes,
                                             final UsageInfo[] usages,
                                             final VirtualFile vFile,
-                                            final Collection<String> conflicts) {
+                                            final Map<PsiElement, String> conflicts) {
     if (scopes == null) return;
 
     for (final PsiElement scope : scopes) {
@@ -1128,7 +1128,7 @@ public class RefactoringUtil {
                                                                RefactoringUIUtil.getDescription(resolved, true)), scopeDescription,
                                                                                                                CommonRefactoringUtil.htmlEmphasize(
                                                                                                                  targetModule.getName()));
-            conflicts.add(message);
+            conflicts.put(resolved, message);
             reported.add(resolved);
           }
         }
@@ -1164,21 +1164,22 @@ public class RefactoringUtil {
               Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(usageVFile);
               if (module != null) {
                 final String message;
+                final PsiElement referencedElement = moveRenameUsageInfo.getReferencedElement();
                 if (module == targetModule && isInTestSources) {
                   message = RefactoringBundle.message("0.referenced.in.1.will.not.be.accessible.from.production.of.module.2",
                                                       CommonRefactoringUtil.capitalize(
-                                                        RefactoringUIUtil.getDescription(moveRenameUsageInfo.getReferencedElement(), true)),
+                                                        RefactoringUIUtil.getDescription(referencedElement, true)),
                                                       scopeDescription,
                                                       CommonRefactoringUtil.htmlEmphasize(module.getName()));
                 }
                 else {
                   message = RefactoringBundle.message("0.referenced.in.1.will.not.be.accessible.from.module.2", 
                                                       CommonRefactoringUtil.capitalize(
-                                                        RefactoringUIUtil.getDescription(moveRenameUsageInfo.getReferencedElement(), true)),
+                                                        RefactoringUIUtil.getDescription(referencedElement, true)),
                                                       scopeDescription,
                                                       CommonRefactoringUtil.htmlEmphasize(module.getName()));
                 }
-                conflicts.add(message);
+                conflicts.put(referencedElement, message);
               }
             }
           }
index 50ef776c8730f83c5b286ee1ff52e15c8873c596..13df51b5388727dfe5c797e0267a3cb99df65068 100644 (file)
@@ -33,10 +33,7 @@ import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor {
 
@@ -140,11 +137,11 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
 
   @Override
   protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
-    List<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     final PsiClass existingClass = JavaPsiFacade.getInstance(myProject).findClass(myQualifiedName);
     if (myUseExistingClass) {
       if (existingClass == null) {
-        conflicts.add(RefactorJBundle.message("could.not.find.selected.wrapping.class"));
+        conflicts.put(existingClass, RefactorJBundle.message("could.not.find.selected.wrapping.class"));
       }
       else {
         boolean foundConstructor = false;
@@ -198,25 +195,26 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
           }
         }
         if (!foundConstructor) {
-          conflicts.add("Existing class does not have appropriate constructor");
+          conflicts.put(existingClass, "Existing class does not have appropriate constructor");
         }
       }
       if (unwrapMethodName.length() == 0) {
-        conflicts.add("Existing class does not have getter for selected field");
+        conflicts.put(existingClass,
+                      "Existing class does not have getter for selected field");
       }
     }
     else {
       if (existingClass != null) {
-        conflicts.add(RefactorJBundle.message("there.already.exists.a.class.with.the.selected.name"));
+        conflicts.put(existingClass, RefactorJBundle.message("there.already.exists.a.class.with.the.selected.name"));
       }
     }
     return showConflicts(conflicts);
   }
 
   @Override
-  protected boolean showConflicts(final List<String> conflicts) {
+  protected boolean showConflicts(final Map<PsiElement,String> conflicts) {
     if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
-      throw new RuntimeException(StringUtil.join(conflicts, "\n"));
+      throw new RuntimeException(StringUtil.join(conflicts.values(), "\n"));
     }
     return super.showConflicts(conflicts);
   }
index 4c7c87e4335d03445c4c64be7108e04124df6081..799dc49d05b12b53e1507b69c8a70c11d4314961 100644 (file)
@@ -8,6 +8,7 @@ import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiClass;
 import com.intellij.psi.PsiDocumentManager;
+import com.intellij.psi.PsiElement;
 import com.intellij.psi.impl.source.PostprocessReformattingAspect;
 import com.intellij.psi.search.ProjectScope;
 import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassToInnerProcessor;
@@ -16,7 +17,7 @@ import com.intellij.testFramework.PsiTestUtil;
 import com.intellij.usageView.UsageInfo;
 
 import java.io.File;
-import java.util.List;
+import java.util.Map;
 
 /**
  * @author yole
@@ -113,8 +114,8 @@ public class MoveClassToInnerTest extends CodeInsightTestCase {
     PsiClass targetClass = myJavaFacade.findClass(targetClassName, ProjectScope.getAllScope(myProject));
     MoveClassToInnerProcessor processor = new MoveClassToInnerProcessor(myProject, classToMove, targetClass, true, true, null);
     UsageInfo[] usages = processor.findUsages();
-    List<String> conflicts = processor.getConflicts(usages);
-    assertSameElements(conflicts, expectedConflicts);
+    Map<PsiElement,String> conflicts = processor.getConflicts(usages);
+    assertSameElements(conflicts.values() , expectedConflicts);
   }
 
   private void performAction(String[] classNames, String targetClassName) throws Exception{
index e4477a714a3a067f6ab616a922673e68f72b61a1..3c5e217d9311fb10f6a6c633c316a5df58d0510c 100644 (file)
@@ -14,6 +14,7 @@ import com.intellij.JavaTestUtil;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 public class PushDownTest extends LightCodeInsightTestCase {
   @Override
@@ -53,7 +54,7 @@ public class PushDownTest extends LightCodeInsightTestCase {
 
     new PushDownProcessor(getProject(), membersToMove.toArray(new MemberInfo[membersToMove.size()]), classes[0], new DocCommentPolicy(DocCommentPolicy.ASIS)){
       @Override
-      protected boolean showConflicts(final List<String> conflicts) {
+      protected boolean showConflicts(Map<PsiElement, String> conflicts) {
         if (failure ? conflicts.isEmpty() : !conflicts.isEmpty()) {
           fail(failure ? "Conflict was not detected" : "False conflict was detected");
         }
index 75003c4828612932ccb9e73389451f5d298f4a36..3d821857cc99cade9442c9e15ea1b3917ac772ec 100644 (file)
@@ -6,6 +6,7 @@ import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiElement;
 import com.intellij.psi.impl.source.PostprocessReformattingAspect;
 import com.intellij.psi.search.ProjectScope;
 import com.intellij.testFramework.IdeaTestUtil;
@@ -13,7 +14,7 @@ import com.intellij.testFramework.PsiTestUtil;
 import com.intellij.usageView.UsageInfo;
 
 import java.io.File;
-import java.util.ArrayList;
+import java.util.Map;
 
 /**
  * @author yole
@@ -45,7 +46,7 @@ public class InlineToAnonymousClassMultifileTest extends CodeInsightTestCase {
                                                                                     classToInline,
                                                                                     null, false, false, false);
     UsageInfo[] usages = processor.findUsages();
-    ArrayList<String> conflicts = processor.getConflicts(usages);
+    Map<PsiElement,String> conflicts = processor.getConflicts(usages);
     assertEquals(0, conflicts.size());
     processor.run();
 
index 12c89c7ffc341e43da16c3bf346be3ad96f0350c..0134f4231dc227e9a492d2ebc0b83f7d040074d1 100644 (file)
@@ -11,7 +11,7 @@ import com.intellij.testFramework.LightCodeInsightTestCase;
 import com.intellij.usageView.UsageInfo;
 import org.jetbrains.annotations.NonNls;
 
-import java.util.ArrayList;
+import java.util.Map;
 
 /**
  * @author yole
@@ -321,10 +321,10 @@ public class InlineToAnonymousClassTest extends LightCodeInsightTestCase {
   public void testConflictInaccessibleOuterField() throws Exception {
     InlineToAnonymousClassProcessor processor = prepareProcessor();
     UsageInfo[] usages = processor.findUsages();
-    ArrayList<String> conflicts = processor.getConflicts(usages);
+    Map<PsiElement,String> conflicts = processor.getConflicts(usages);
     assertEquals(1, conflicts.size());
     assertEquals("Field <b><code>C2.a</code></b> that is used in inlined method is not accessible from call site(s) in method <b><code>C2User.test()</code></b>",
-                 conflicts.get(0));
+                 conflicts.values().iterator().next());
   }
 
   private void doTestNoInline(final String expectedMessage) throws Exception {
@@ -374,7 +374,7 @@ public class InlineToAnonymousClassTest extends LightCodeInsightTestCase {
     final InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(getProject(), classToInline, callToInline, inlineThisOnly,
                                                                                           false, searchInNonJavaFiles);
     UsageInfo[] usages = processor.findUsages();
-    ArrayList<String> conflicts = processor.getConflicts(usages);
+    Map<PsiElement, String> conflicts = processor.getConflicts(usages);
     assertEquals(0, conflicts.size());
     processor.run();
   }
index f512498d80695ce525711d8706d94614458f3aa2..72943df86df0c8e9ef610f09c9181eb257794078 100644 (file)
@@ -23,8 +23,8 @@ import com.intellij.usageView.UsageInfo;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
 
 /**
  * Represents a destination of Move Classes/Packages refactoring.
@@ -60,5 +60,5 @@ public interface MoveDestination {
   @Nullable
   String verify(PsiPackage source);
 
-  void analyzeModuleConflicts(final Collection<PsiElement> elements, ArrayList<String> conflicts, final UsageInfo[] usages);
+  void analyzeModuleConflicts(final Collection<PsiElement> elements, Map<PsiElement,String> conflicts, final UsageInfo[] usages);
 }
index a74358e24653390a4656cdbd37a823b481ee7350..ae2f53bd49c22e7657f906af80a801dbebaa86c9 100644 (file)
@@ -23,7 +23,7 @@ import com.intellij.psi.PsiReference;
 import com.intellij.usageView.UsageInfo;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.Collection;
+import java.util.Map;
 
 /**
  * Interface that should be implemented by the language in order to provide inline functionality and possibly
@@ -71,7 +71,7 @@ public interface InlineHandler {
      * or null if no conflicts detected.
      */
     @Nullable
-    Collection<String> getConflicts(PsiReference reference, PsiElement referenced);
+    Map<PsiElement, String> getConflicts(PsiReference reference, PsiElement referenced);
 
     /**
      * Perform actual inline of element to the point where it is referenced
diff --git a/platform/lang-api/src/com/intellij/refactoring/ui/ConflictsDialog.java b/platform/lang-api/src/com/intellij/refactoring/ui/ConflictsDialog.java
deleted file mode 100644 (file)
index 436ac2f..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2000-2007 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * created at Sep 12, 2001
- * @author Jeka
- */
-package com.intellij.refactoring.ui;
-
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.refactoring.RefactoringBundle;
-import com.intellij.util.ArrayUtil;
-import org.jetbrains.annotations.NonNls;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.util.Collection;
-
-public class ConflictsDialog extends DialogWrapper{
-  private String[] myConflictDescriptions;
-
-  public ConflictsDialog(Project project, Collection<String> conflictDescriptions) {
-    this(project, ArrayUtil.toStringArray(conflictDescriptions));
-  }
-  public ConflictsDialog(Project project, String... conflictDescriptions) {
-    super(project, true);
-    myConflictDescriptions = conflictDescriptions;
-    setTitle(RefactoringBundle.message("problems.detected.title"));
-    setOKButtonText(RefactoringBundle.message("continue.button"));
-    init();
-  }
-
-  protected Action[] createActions(){
-    return new Action[]{getOKAction(),new CancelAction()};
-  }
-
-  protected JComponent createCenterPanel() {
-    JPanel panel = new JPanel(new BorderLayout());
-    @NonNls final String contentType = "text/html";
-    final JEditorPane messagePane = new JEditorPane(contentType, "");
-    messagePane.setEditable(false);
-    JScrollPane scrollPane = new JScrollPane(messagePane);
-    scrollPane.setPreferredSize(new Dimension(500, 400));
-    panel.add(new JLabel(RefactoringBundle.message("the.following.problems.were.found")), BorderLayout.NORTH);
-    panel.add(scrollPane, BorderLayout.CENTER);
-
-    @NonNls StringBuffer buf = new StringBuffer();
-    for (String description : myConflictDescriptions) {
-      buf.append(description);
-      buf.append("<br><br>");
-    }
-    messagePane.setText(buf.toString());
-    return panel;
-  }
-
-  protected JComponent createSouthPanel() {
-    JPanel panel = new JPanel(new BorderLayout());
-    panel.add(super.createSouthPanel(), BorderLayout.CENTER);
-    panel.add(new JLabel(RefactoringBundle.message("do.you.wish.to.ignore.them.and.continue")), BorderLayout.WEST);
-    return panel;
-  }
-
-  private class CancelAction extends AbstractAction {
-    public CancelAction() {
-      super(RefactoringBundle.message("cancel.button"));
-      putValue(DialogWrapper.DEFAULT_ACTION,Boolean.TRUE);
-    }
-
-    public void actionPerformed(ActionEvent e) {
-      doCancelAction();
-    }
-  }
-}
index 2e6f31dd68eb132a7e545b441b652cb087ade885..6a0e13e3485469d90ac7c804ff078f1f0c859cd6 100644 (file)
@@ -434,11 +434,14 @@ public abstract class BaseRefactoringProcessor {
     performPsiSpoilingRefactoring();
   }
 
-  protected boolean showConflicts(final List<String> conflicts) {
+  protected boolean showConflicts(final Map<PsiElement, String> conflicts) {
     if (!conflicts.isEmpty() && myPrepareSuccessfulSwingThreadCallback != null) {
       final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
       conflictsDialog.show();
-      if (!conflictsDialog.isOK()) return false;
+      if (!conflictsDialog.isOK()){
+        if (conflictsDialog.isShowConflicts()) prepareSuccessful();
+        return false;
+      }
     }
 
     prepareSuccessful();
index 188be48be66826b10bcf6b195dcd27d8da494bac..6ec4bb9a9e48b324bc273e81601ee764afb44180 100644 (file)
@@ -36,7 +36,7 @@ public class GenericInlineHandler {
       settings.isOnlyOneReferenceToInline() ? Collections.singleton(invocationReference) : ReferencesSearch.search(element).findAll();
     final Map<Language, InlineHandler.Inliner> inliners = new HashMap<Language, InlineHandler.Inliner>();
 
-    final Set<String> conflicts = new HashSet<String>();
+    final Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     for (PsiReference ref : allReferences) {
       final Language language = ref.getElement().getLanguage();
       if (inliners.containsKey(language)) continue;
@@ -51,7 +51,7 @@ public class GenericInlineHandler {
         }
       }
       if (inliner == null) {
-        conflicts.add("Cannot inline reference from " + language.getID());
+        conflicts.put(null, "Cannot inline reference from " + language.getID());
       }
     }
 
@@ -62,11 +62,13 @@ public class GenericInlineHandler {
     final Project project = element.getProject();
     if (!conflicts.isEmpty()) {
       if (ApplicationManager.getApplication().isUnitTestMode()) {
-        throw new ConflictsFoundInTestException("Refactoring cannot be performed:" + conflicts.iterator().next());
+        throw new ConflictsFoundInTestException("Refactoring cannot be performed:" + conflicts.values().iterator().next());
       } else {
         final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
         conflictsDialog.show();
-        if (!conflictsDialog.isOK()) return true;
+        if (!conflictsDialog.isOK()){
+          return true;
+        }
       }
     }
 
@@ -115,13 +117,13 @@ public class GenericInlineHandler {
   private static void collectConflicts(final PsiReference reference,
                                        final PsiElement element,
                                        final Map<Language, InlineHandler.Inliner> inliners,
-                                       final Set<String> conflicts) {
+                                       final Map<PsiElement, String> conflicts) {
     final Language language = reference.getElement().getLanguage();
     final InlineHandler.Inliner inliner = inliners.get(language);
     if (inliner != null) {
-      final Collection<String> refConflicts = inliner.getConflicts(reference, element);
+      final Map<PsiElement, String> refConflicts = inliner.getConflicts(reference, element);
       if (refConflicts != null) {
-        conflicts.addAll(refConflicts);
+        conflicts.putAll(refConflicts);
       }
     }
   }
index 589b46b338f26dba83b783a2f15225a3964605bf..587602aad434e07961792e49f2d763a24788ada3 100644 (file)
@@ -100,14 +100,15 @@ public class RenameProcessor extends BaseRefactoringProcessor {
 
   public boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     UsageInfo[] usagesIn = refUsages.get();
-    Set<String> conflicts = new HashSet<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
 
-    conflicts.addAll(RenameUtil.getConflictDescriptions(usagesIn));
+    conflicts.putAll(RenameUtil.getConflictDescriptions(usagesIn));
     RenamePsiElementProcessor.forElement(myPrimaryElement).findExistingNameConflicts(myPrimaryElement, myNewName, conflicts);
     if (!conflicts.isEmpty()) {
       ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
       conflictsDialog.show();
       if (!conflictsDialog.isOK()) {
+        if (conflictsDialog.isShowConflicts()) prepareSuccessful();
         return false;
       }
     }
index 2cafad16eb3d6aa3759c68aa3a2efa6ea6dd2f1a..cdc9771b144e1d3d4c61f1cc77870622887e972b 100644 (file)
@@ -52,7 +52,7 @@ public abstract class RenamePsiElementProcessor {
   public void prepareRenaming(final PsiElement element, final String newName, final Map<PsiElement, String> allRenames) {
   }
 
-  public void findExistingNameConflicts(final PsiElement element, final String newName, final Collection<String> conflicts) {
+  public void findExistingNameConflicts(final PsiElement element, final String newName, final Map<PsiElement, String> conflicts) {
   }
 
   @NotNull
index 241f8a9af3509b1c1b7253bee6bbb19bf40d0aea..53508d21b17855aca834f13512cc937b43cc1399 100644 (file)
@@ -41,7 +41,7 @@ public class RenameUtil {
                                        boolean searchInStringsAndComments,
                                        boolean searchForTextOccurences,
                                        Map<? extends PsiElement, String> allRenames) {
-    final List<UsageInfo> result = new ArrayList<UsageInfo>();
+    final List<UsageInfo> result = Collections.synchronizedList(new ArrayList<UsageInfo>());
 
     PsiManager manager = element.getManager();
     GlobalSearchScope projectScope = GlobalSearchScope.projectScope(manager.getProject());
@@ -227,12 +227,12 @@ public class RenameUtil {
     }
   }
 
-  public static Collection<String> getConflictDescriptions(UsageInfo[] usages) {
-    ArrayList<String> descriptions = new ArrayList<String>();
+  public static Map<PsiElement, String> getConflictDescriptions(UsageInfo[] usages) {
+    Map<PsiElement, String> descriptions = new HashMap<PsiElement, String>();
 
     for (UsageInfo usage : usages) {
       if (usage instanceof UnresolvableCollisionUsageInfo) {
-        descriptions.add(((UnresolvableCollisionUsageInfo)usage).getDescription());
+        descriptions.put(usage.getElement(), ((UnresolvableCollisionUsageInfo)usage).getDescription());
       }
     }
     return descriptions;
diff --git a/platform/lang-impl/src/com/intellij/refactoring/ui/ConflictsDialog.java b/platform/lang-impl/src/com/intellij/refactoring/ui/ConflictsDialog.java
new file mode 100644 (file)
index 0000000..4907e8d
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2000-2007 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * created at Sep 12, 2001
+ * @author Jeka
+ */
+package com.intellij.refactoring.ui;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.psi.PsiElement;
+import com.intellij.refactoring.RefactoringBundle;
+import com.intellij.ui.SimpleTextAttributes;
+import com.intellij.usageView.UsageInfo;
+import com.intellij.usages.*;
+import com.intellij.util.ArrayUtil;
+import com.intellij.codeInsight.highlighting.ReadWriteAccessDetector;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.util.Collection;
+import java.util.Map;
+
+public class ConflictsDialog extends DialogWrapper{
+  private static final int SHOW_CONFLICTS_EXIT_CODE = 4;
+
+  private String[] myConflictDescriptions;
+  private Map<PsiElement, String> myElementConflictDescription;
+  private final Project myProject;
+
+  public ConflictsDialog(Project project, Map<PsiElement, String> conflictDescriptions) {
+    super(project, true);
+    myProject = project;
+    myConflictDescriptions = ArrayUtil.toStringArray(conflictDescriptions.values());
+    myElementConflictDescription = conflictDescriptions;
+    setTitle(RefactoringBundle.message("problems.detected.title"));
+    setOKButtonText(RefactoringBundle.message("continue.button"));
+    init();
+  }
+
+  public ConflictsDialog(Project project, Collection<String> conflictDescriptions) {
+    this(project, ArrayUtil.toStringArray(conflictDescriptions));
+  }
+  public ConflictsDialog(Project project, String... conflictDescriptions) {
+    super(project, true);
+    myProject = project;
+    myConflictDescriptions = conflictDescriptions;
+    setTitle(RefactoringBundle.message("problems.detected.title"));
+    setOKButtonText(RefactoringBundle.message("continue.button"));
+    init();
+  }
+
+  protected Action[] createActions(){
+    if (myElementConflictDescription == null) {
+      return new Action[]{getOKAction(),new CancelAction()};
+    }
+    return new Action[]{getOKAction(), new MyShowConflictsInUsageViewAction(), new CancelAction()};
+  }
+
+  public boolean isShowConflicts() {
+    return getExitCode() == SHOW_CONFLICTS_EXIT_CODE;
+  }
+
+  protected JComponent createCenterPanel() {
+    JPanel panel = new JPanel(new BorderLayout());
+    @NonNls final String contentType = "text/html";
+    final JEditorPane messagePane = new JEditorPane(contentType, "");
+    messagePane.setEditable(false);
+    JScrollPane scrollPane = new JScrollPane(messagePane);
+    scrollPane.setPreferredSize(new Dimension(500, 400));
+    panel.add(new JLabel(RefactoringBundle.message("the.following.problems.were.found")), BorderLayout.NORTH);
+    panel.add(scrollPane, BorderLayout.CENTER);
+
+    @NonNls StringBuffer buf = new StringBuffer();
+    for (String description : myConflictDescriptions) {
+      buf.append(description);
+      buf.append("<br><br>");
+    }
+    messagePane.setText(buf.toString());
+    return panel;
+  }
+
+  protected JComponent createSouthPanel() {
+    JPanel panel = new JPanel(new BorderLayout());
+    panel.add(super.createSouthPanel(), BorderLayout.CENTER);
+    panel.add(new JLabel(RefactoringBundle.message("do.you.wish.to.ignore.them.and.continue")), BorderLayout.WEST);
+    return panel;
+  }
+
+  private class CancelAction extends AbstractAction {
+    public CancelAction() {
+      super(RefactoringBundle.message("cancel.button"));
+      putValue(DialogWrapper.DEFAULT_ACTION,Boolean.TRUE);
+    }
+
+    public void actionPerformed(ActionEvent e) {
+      doCancelAction();
+    }
+  }
+
+  private class MyShowConflictsInUsageViewAction extends AbstractAction {
+
+
+    public MyShowConflictsInUsageViewAction() {
+      super("Show in view");
+    }
+
+    public void actionPerformed(ActionEvent e) {
+      final UsageViewPresentation presentation = new UsageViewPresentation();
+      final String codeUsagesString = "Conflicts";
+      presentation.setCodeUsagesString(codeUsagesString);
+      presentation.setTabName(codeUsagesString);
+      presentation.setTabText(codeUsagesString);
+
+      final Usage[] usages = new Usage[myElementConflictDescription.size()];
+      int i = 0;
+      for (final PsiElement element : myElementConflictDescription.keySet()) {
+        boolean isRead = false;
+        boolean isWrite = false;
+        for (ReadWriteAccessDetector detector : Extensions.getExtensions(ReadWriteAccessDetector.EP_NAME)) {
+          if (detector.isReadWriteAccessible(element)) {
+            final ReadWriteAccessDetector.Access access = detector.getExpressionAccess(element);
+            isRead = access != ReadWriteAccessDetector.Access.Write;
+            isWrite = access != ReadWriteAccessDetector.Access.Read;
+            break;
+          }
+        }
+
+        usages[i++] = isRead || isWrite ? new ReadWriteAccessUsageInfo2UsageAdapter(new UsageInfo(element), isRead, isWrite) {
+          @NotNull
+          @Override
+          public UsagePresentation getPresentation() {
+            final UsagePresentation usagePresentation = super.getPresentation();
+            return MyShowConflictsInUsageViewAction.this.getPresentation(usagePresentation, element);
+          }
+        } : new UsageInfo2UsageAdapter(new UsageInfo(element)) {
+          @NotNull
+          @Override
+          public UsagePresentation getPresentation() {
+            final UsagePresentation usagePresentation = super.getPresentation();
+            return MyShowConflictsInUsageViewAction.this.getPresentation(usagePresentation, element);
+          }
+        };
+      }
+      UsageViewManager.getInstance(myProject).showUsages(UsageTarget.EMPTY_ARRAY, usages, presentation);
+      close(SHOW_CONFLICTS_EXIT_CODE);
+    }
+
+    private UsagePresentation getPresentation(final UsagePresentation usagePresentation, PsiElement element) {
+      final String conflictDescription = " (" + myElementConflictDescription.get(element) + ")";
+      return new UsagePresentation() {
+        @NotNull
+        public TextChunk[] getText() {
+          final TextChunk[] chunks = usagePresentation.getText();
+          return ArrayUtil
+            .append(chunks, new TextChunk(SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES.toTextAttributes(), conflictDescription));
+        }
+
+        @NotNull
+        public String getPlainText() {
+          return usagePresentation.getPlainText() + conflictDescription;
+        }
+
+        public Icon getIcon() {
+          return usagePresentation.getIcon();
+        }
+
+        public String getTooltipText() {
+          return usagePresentation.getTooltipText();
+        }
+      };
+    }
+  }
+}