IDEA-51934: Groovy constructor calls should be disambiguated by parameter count
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Fri, 19 Feb 2010 14:28:26 +0000 (17:28 +0300)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Fri, 19 Feb 2010 14:28:26 +0000 (17:28 +0300)
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/CompletionProcessor.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java

index 69fa1301397c9e34511d8a619bddfa2350acc5d0..7f681e2ada7661fd63298ff34eeffffa487fe337 100644 (file)
@@ -348,7 +348,7 @@ public class ResolveUtil {
     return elements;
   }
 
-  public static GroovyResolveResult[] filterSameSignatureCandidates(Collection<GroovyResolveResult> candidates) {
+  public static GroovyResolveResult[] filterSameSignatureCandidates(Collection<GroovyResolveResult> candidates, int argumentCount) {
     GroovyResolveResult[] array = candidates.toArray(new GroovyResolveResult[candidates.size()]);
     if (array.length == 1) return array;
 
@@ -365,10 +365,10 @@ public class ResolveUtil {
           PsiElement element = otherResolveResult.getElement();
           if (element instanceof PsiMethod) {
             PsiMethod method = (PsiMethod)element;
-            if (dominated(currentMethod, array[i].getSubstitutor(), method, otherResolveResult.getSubstitutor())) {
+            if (dominated(currentMethod, array[i].getSubstitutor(), method, otherResolveResult.getSubstitutor(), argumentCount)) {
               continue Outer;
             }
-            else if (dominated(method, otherResolveResult.getSubstitutor(), currentMethod, array[i].getSubstitutor())) {
+            else if (dominated(method, otherResolveResult.getSubstitutor(), currentMethod, array[i].getSubstitutor(), argumentCount)) {
               iterator.remove();
             }
           }
@@ -384,11 +384,13 @@ public class ResolveUtil {
   public static boolean dominated(PsiMethod method1,
                                   PsiSubstitutor substitutor1,
                                   PsiMethod method2,
-                                  PsiSubstitutor substitutor2) {  //method1 has more general parameter types thn method2
+                                  PsiSubstitutor substitutor2,
+                                  int argumentCount) {  //method1 has more general parameter types then method2
     if (!method1.getName().equals(method2.getName())) return false;
 
     PsiParameter[] params1 = method1.getParameterList().getParameters();
     PsiParameter[] params2 = method2.getParameterList().getParameters();
+    if (argumentCount != params1.length && argumentCount == params2.length) return true;
 
     if (params1.length != params2.length) return false;
 
index 16209a63aa010eda869331da52efef759b4e32e4..d60adfc72832373d7f7a260a5adbe2242e17b4fb 100644 (file)
@@ -55,6 +55,6 @@ public class CompletionProcessor extends ResolverProcessor {
 
   public GroovyResolveResult[] getCandidates() {
     if (myCandidates.size() == 0) return GroovyResolveResult.EMPTY_ARRAY;
-    return ResolveUtil.filterSameSignatureCandidates(myCandidates);
+    return ResolveUtil.filterSameSignatureCandidates(myCandidates, -1);
   }
 }
\ No newline at end of file
index d43dcbb5c16f0e31274a27da355b6294bd08b6f7..530cbe2cdff1f74a95b9dbb1b918f96cd9cb0b21 100644 (file)
@@ -212,7 +212,7 @@ public class MethodResolverProcessor extends ResolverProcessor {
       return filterCandidates();
     }
     if (!myInapplicableCandidates.isEmpty()) {
-      return ResolveUtil.filterSameSignatureCandidates(myInapplicableCandidates);
+      return ResolveUtil.filterSameSignatureCandidates(myInapplicableCandidates, myArgumentTypes != null ? myArgumentTypes.length : -1);
     }
     return GroovyResolveResult.EMPTY_ARRAY;
   }