refactoring conflicts in usage view: strip html
authorAnna Kozlova <Anna.Kozlova@jetbrains.com>
Thu, 17 Sep 2009 13:38:07 +0000 (17:38 +0400)
committerAnna Kozlova <Anna.Kozlova@jetbrains.com>
Thu, 17 Sep 2009 13:38:07 +0000 (17:38 +0400)
java/java-impl/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationProcessor.java
platform/lang-impl/src/com/intellij/refactoring/ui/ConflictsDialog.java

index 390a321276338e89299348de6f247ccb5ad86a84..1316df548f090b53f79bdd9a46e102503ddfd30b 100644 (file)
@@ -172,12 +172,12 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
     addAll(oldUsages, usagesIn);
     final ObjectUpcastedUsageInfo[] objectUpcastedUsageInfos = objectUpcastedUsages(usagesIn);
     if (myPrepareSuccessfulSwingThreadCallback != null) {
-      ArrayList<String> conflicts = new ArrayList<String>();
+      Map<PsiElement, String> conflicts = new LinkedHashMap<PsiElement, String>();
       if (objectUpcastedUsageInfos.length > 0) {
         final String message = RefactoringBundle.message("instances.of.0.upcasted.to.1.were.found",
                                                          RefactoringUIUtil.getDescription(myClass, true), CommonRefactoringUtil.htmlEmphasize("java.lang.Object"));
 
-        conflicts.add(message);
+        conflicts.put(myClass, message);
       }
 
       analyzeConflicts(usagesIn, conflicts);
@@ -185,7 +185,10 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
         ConflictsDialog conflictsDialog =
                 new ConflictsDialog(myProject, conflicts);
         conflictsDialog.show();
-        if (!conflictsDialog.isOK()) return false;
+        if (!conflictsDialog.isOK()){
+          if (conflictsDialog.isShowConflicts()) prepareSuccessful();
+          return false;
+        }
       }
 
       if (objectUpcastedUsageInfos.length > 0) {
@@ -199,7 +202,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
     return true;
   }
 
-  private void analyzeConflicts(UsageInfo[] usage, ArrayList<String> conflicts) {
+  private void analyzeConflicts(UsageInfo[] usage, Map<PsiElement, String> conflicts) {
     HashMap<PsiElement,HashSet<PsiElement>> reportedNonDelegatedUsages = new HashMap<PsiElement, HashSet<PsiElement>>();
     HashMap<PsiClass,HashSet<PsiElement>> reportedUpcasts = new HashMap<PsiClass, HashSet<PsiElement>>();
 //    HashSet reportedObjectUpcasts = new HashSet();
@@ -232,7 +235,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
             if (container != null && !reportedContainers.contains(container)) {
               String message = RefactoringBundle.message("0.uses.1.of.an.instance.of.a.2", RefactoringUIUtil.getDescription(container, true),
                                                          RefactoringUIUtil.getDescription(nonDelegatedMember, true), classDescription);
-              conflicts.add(CommonRefactoringUtil.capitalize(message));
+              conflicts.put(container, CommonRefactoringUtil.capitalize(message));
               reportedContainers.add(container);
             }
           }
@@ -248,7 +251,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
               String message = RefactoringBundle.message("0.upcasts.an.instance.of.1.to.2",
                                                          RefactoringUIUtil.getDescription(container, true), classDescription,
                                                          RefactoringUIUtil.getDescription(upcastedTo, false));
-              conflicts.add(CommonRefactoringUtil.capitalize(message));
+              conflicts.put(container, CommonRefactoringUtil.capitalize(message));
               reportedContainers.add(container);
             }
           }
@@ -259,7 +262,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
         String message = RefactoringBundle.message("0.will.no.longer.override.1",
                                                    RefactoringUIUtil.getDescription(info.getSubClassMethod(), true),
                                                    RefactoringUIUtil.getDescription(info.getOverridenMethod(), true));
-        conflicts.add(message);
+        conflicts.put(info.getSubClassMethod(), message);
       }
     }
   }
index 4907e8df89e9cb50cc296b97b59c10f2e676ee44..2d953563e609f944b73ebfffc9ce1e21834ad896 100644 (file)
  */
 package com.intellij.refactoring.ui;
 
+import com.intellij.codeInsight.highlighting.ReadWriteAccessDetector;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.fileEditor.FileEditorLocation;
 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 org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.util.Collection;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 public class ConflictsDialog extends DialogWrapper{
   private static final int SHOW_CONFLICTS_EXIT_CODE = 4;
@@ -108,7 +111,7 @@ public class ConflictsDialog extends DialogWrapper{
   private class CancelAction extends AbstractAction {
     public CancelAction() {
       super(RefactoringBundle.message("cancel.button"));
-      putValue(DialogWrapper.DEFAULT_ACTION,Boolean.TRUE);
+      putValue(DEFAULT_ACTION,Boolean.TRUE);
     }
 
     public void actionPerformed(ActionEvent e) {
@@ -133,6 +136,10 @@ public class ConflictsDialog extends DialogWrapper{
       final Usage[] usages = new Usage[myElementConflictDescription.size()];
       int i = 0;
       for (final PsiElement element : myElementConflictDescription.keySet()) {
+        if (element == null) {
+          usages[i++] = new DescriptionOnlyUsage();
+          continue;
+        }
         boolean isRead = false;
         boolean isWrite = false;
         for (ReadWriteAccessDetector detector : Extensions.getExtensions(ReadWriteAccessDetector.EP_NAME)) {
@@ -165,7 +172,7 @@ public class ConflictsDialog extends DialogWrapper{
     }
 
     private UsagePresentation getPresentation(final UsagePresentation usagePresentation, PsiElement element) {
-      final String conflictDescription = " (" + myElementConflictDescription.get(element) + ")";
+      final String conflictDescription = " (" + Pattern.compile("<[^<>]*>").matcher(myElementConflictDescription.get(element)).replaceAll("") + ")";
       return new UsagePresentation() {
         @NotNull
         public TextChunk[] getText() {
@@ -188,5 +195,57 @@ public class ConflictsDialog extends DialogWrapper{
         }
       };
     }
+
+    private class DescriptionOnlyUsage implements Usage {
+      private final String myConflictDescription = Pattern.compile("<[^<>]*>").matcher(myElementConflictDescription.get(null)).replaceAll("");
+
+      @NotNull
+      public UsagePresentation getPresentation() {
+        return new UsagePresentation() {
+          @NotNull
+          public TextChunk[] getText() {
+            return new TextChunk[0];
+          }
+
+          @Nullable
+          public Icon getIcon() {
+            return null;
+          }
+
+          public String getTooltipText() {
+            return myConflictDescription;
+          }
+
+          @NotNull
+          public String getPlainText() {
+            return myConflictDescription;
+          }
+        };
+      }
+
+      public boolean canNavigateToSource() {
+        return false;
+      }
+
+      public boolean canNavigate() {
+        return false;
+      }
+      public void navigate(boolean requestFocus) {}
+
+      public FileEditorLocation getLocation() {
+        return null;
+      }
+
+      public boolean isReadOnly() {
+        return false;
+      }
+
+      public boolean isValid() {
+        return true;
+      }
+
+      public void selectInEditor() {}
+      public void highlightInEditor() {}
+    }
   }
 }