show refactoring conflicts in usage view
authorAnna Kozlova <Anna.Kozlova@jetbrains.com>
Wed, 16 Sep 2009 17:42:51 +0000 (21:42 +0400)
committerAnna Kozlova <Anna.Kozlova@jetbrains.com>
Wed, 16 Sep 2009 17:42:51 +0000 (21:42 +0400)
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/inline/GroovyInlineVariableUtil.java
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/inline/GroovyMethodInliner.java
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduceParameter/java2groovy/GroovyIntroduceParameterMethodUsagesProcessor.java
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/move/MoveGroovyScriptProcessor.java

index 0aca46fea608de2ee17ab95ee66fc2ed04f5c9e7..23a2bdfb9c998d481e710ab691aa451be3944645 100644 (file)
@@ -54,6 +54,8 @@ import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringUtil;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * @author ilyas
@@ -71,13 +73,13 @@ public class GroovyInlineVariableUtil {
     return new InlineHandler.Inliner() {
 
       @Nullable
-      public Collection<String> getConflicts(PsiReference reference, PsiElement referenced) {
-        ArrayList<String> conflicts = new ArrayList<String>();
+      public Map<PsiElement, String> getConflicts(PsiReference reference, PsiElement referenced) {
+        Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
         GrExpression expr = (GrExpression) reference.getElement();
         if (expr.getParent() instanceof GrAssignmentExpression) {
           GrAssignmentExpression parent = (GrAssignmentExpression) expr.getParent();
           if (expr.equals(parent.getLValue())) {
-            conflicts.add(GroovyRefactoringBundle.message("local.varaible.is.lvalue"));
+            conflicts.put(expr, GroovyRefactoringBundle.message("local.varaible.is.lvalue"));
           }
         }
         return conflicts;
index 612019e9aaf65cddb0b0ee0789c067bc7a7ef54b..b7a778e12e84fef53a8875ddc311071f75ceaa7d 100644 (file)
@@ -57,6 +57,8 @@ import org.jetbrains.plugins.groovy.refactoring.NameValidator;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * @author ilyas
@@ -71,7 +73,7 @@ public class GroovyMethodInliner implements InlineHandler.Inliner {
   }
 
   @Nullable
-  public Collection<String> getConflicts(PsiReference reference, PsiElement referenced) {
+  public Map<PsiElement, String> getConflicts(PsiReference reference, PsiElement referenced) {
     PsiElement element = reference.getElement();
     assert element instanceof GrExpression && element.getParent() instanceof GrCallExpression;
     GrCallExpression call = (GrCallExpression) element.getParent();
@@ -79,8 +81,8 @@ public class GroovyMethodInliner implements InlineHandler.Inliner {
     return collectConflicts(call, infos);
   }
 
-  private static Collection<String> collectConflicts(GrCallExpression call, Collection<GroovyInlineMethodUtil.ReferenceExpressionInfo> infos) {
-    ArrayList<String> conflicts = new ArrayList<String>();
+  private static Map<PsiElement, String> collectConflicts(GrCallExpression call, Collection<GroovyInlineMethodUtil.ReferenceExpressionInfo> infos) {
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
 
     for (GroovyInlineMethodUtil.ReferenceExpressionInfo info : infos) {
       if (!(PsiUtil.isAccessible(call, info.declaration))) {
@@ -88,11 +90,11 @@ public class GroovyMethodInliner implements InlineHandler.Inliner {
           String className = info.containingClass.getName();
           String signature = GroovyRefactoringUtil.getMethodSignature(((PsiMethod) info.declaration));
           String name = CommonRefactoringUtil.htmlEmphasize(className + "." + signature);
-          conflicts.add(GroovyRefactoringBundle.message("method.is.not.accessible.form.context.0", name));
+          conflicts.put(info.declaration, GroovyRefactoringBundle.message("method.is.not.accessible.form.context.0", name));
         } else if (info.declaration instanceof PsiField) {
           String className = info.containingClass.getName();
           String name = CommonRefactoringUtil.htmlEmphasize(className + "." + info.getPresentation());
-          conflicts.add(GroovyRefactoringBundle.message("field.is.not.accessible.form.context.0", name));
+          conflicts.put(info.declaration, GroovyRefactoringBundle.message("field.is.not.accessible.form.context.0", name));
         }
       }
     }
index d2a1e19fcf8ee25644010ed6c00ef508313ce81b..9073dc30bc8f01e4d8b26d7b865cef04bc0fc695 100644 (file)
@@ -66,32 +66,34 @@ public class GroovyIntroduceParameterMethodUsagesProcessor implements IntroduceP
     return GroovyRefactoringUtil.isMethodUsage(usage.getElement()) && isGroovyUsage(usage);
   }
 
-  public List<String> findConflicts(IntroduceParameterData data, UsageInfo[] usages) {
+  public Map<PsiElement, String> findConflicts(IntroduceParameterData data, UsageInfo[] usages) {
     Set<UsageInfo> groovyUsages = new HashSet<UsageInfo>();
     for (UsageInfo usage : usages) {
       if (isMethodUsage(usage)) groovyUsages.add(usage);
     }
-    if (groovyUsages.size() == 0) return Collections.emptyList();
-    List<String> conflicts = new ArrayList<String>();
+    if (groovyUsages.size() == 0) return Collections.emptyMap();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     data.getParameterInitializer().accept(new InitializerVisitor(conflicts));
     return conflicts;
   }
 
   private static class InitializerVisitor extends JavaRecursiveElementWalkingVisitor {
-    private final List<String> conflicts;
+    private final Map<PsiElement, String> conflicts;
 
-    private InitializerVisitor(List<String> conflicts) {
+    private InitializerVisitor(Map<PsiElement, String> conflicts) {
       this.conflicts = conflicts;
     }
 
     @Override
     public void visitNewExpression(PsiNewExpression expression) {
       super.visitNewExpression(expression);
-      if (expression.getQualifier() != null) {
-        conflicts.add(GroovyRefactoringBundle.message("groovy.does.not.support.inner.classes.but.it.is.used.in.parameter.initializer"));
+      final PsiExpression qualifier = expression.getQualifier();
+      if (qualifier != null) {
+        conflicts.put(qualifier, GroovyRefactoringBundle.message("groovy.does.not.support.inner.classes.but.it.is.used.in.parameter.initializer"));
       }
-      if (expression.getAnonymousClass() != null) {
-        conflicts.add(GroovyRefactoringBundle.message("groovy.does.not.support.anonymous.classes.but.it.is.used.in.parameter.initializer"));
+      final PsiAnonymousClass anonymousClass = expression.getAnonymousClass();
+      if (anonymousClass != null) {
+        conflicts.put(anonymousClass, GroovyRefactoringBundle.message("groovy.does.not.support.anonymous.classes.but.it.is.used.in.parameter.initializer"));
       }
     }
   }
index 58aa1fb8cd22d1cf3e498940fe8dd33f01edefe6..acf42269da80a12f4adea7642f8b4335c823acda 100644 (file)
@@ -55,7 +55,7 @@ public class MoveGroovyScriptProcessor extends MoveClassesOrPackagesProcessor {
   @Override
   protected UsageInfo[] findUsages() {
     List<UsageInfo> allUsages = new ArrayList<UsageInfo>();
-    ArrayList<String> conflicts = new ArrayList<String>();
+    Map<PsiElement, String> conflicts = new HashMap<PsiElement, String>();
     final List<PsiElement> elements = getElements();
     for (PsiElement element : elements) {
       final GroovyFile groovyFile = (GroovyFile)element;
@@ -77,7 +77,7 @@ public class MoveGroovyScriptProcessor extends MoveClassesOrPackagesProcessor {
 
   @Override
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
-    return showConflicts(Collections.<String>emptyList());
+    return showConflicts(Collections.<PsiElement, String>emptyMap());
   }
 
   @Override