using NoVariantsDelegator
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Mon, 19 Dec 2011 09:49:39 +0000 (13:49 +0400)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Mon, 19 Dec 2011 09:49:39 +0000 (13:49 +0400)
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyNoVariantsDelegator.java

index 034c164852fef9eb0c7221d8d30920a1681ec6a0..ef74cc4702e93c2765199231f42bc79b5c84fe29 100644 (file)
@@ -18,52 +18,35 @@ package org.jetbrains.plugins.groovy.lang.completion;
 import com.intellij.codeInsight.completion.*;
 import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
 import com.intellij.codeInsight.lookup.LookupElement;
-import com.intellij.openapi.util.Ref;
 import com.intellij.util.Consumer;
 
 /**
  * @author peter
  */
-public class GroovyNoVariantsDelegator extends CompletionContributor {
+public class GroovyNoVariantsDelegator extends NoVariantsDelegator {
 
   @Override
-  public void fillCompletionVariants(final CompletionParameters parameters, final CompletionResultSet result) {
-    final Ref<Boolean> empty = Ref.create(true);
-    Consumer<CompletionResult> passResult = new Consumer<CompletionResult>() {
-      public void consume(final CompletionResult lookupElement) {
-        empty.set(false);
-        result.passResult(lookupElement);
-      }
-    };
-    result.runRemainingContributors(parameters, passResult);
-
-    if (!empty.get() && parameters.getInvocationCount() == 0) {
-      result.restartCompletionWhenNothingMatches();
-    }
-
-    if (empty.get()) {
-      if (parameters.getCompletionType() == CompletionType.BASIC &&
-          parameters.getInvocationCount() <= 1 &&
-          JavaCompletionContributor.mayStartClassName(result, false) &&
-          GroovyCompletionContributor.isClassNamePossible(parameters.getPosition())) {
-        final ClassByNameMerger merger = new ClassByNameMerger(parameters.getInvocationCount() == 0, result);
-
-        GroovyCompletionContributor.addAllClasses(parameters, result,
-                                                         new Consumer<LookupElement>() {
-          @Override
-          public void consume(LookupElement element) {
-            JavaPsiClassReferenceElement classElement = element.as(JavaPsiClassReferenceElement.CLASS_CONDITION_KEY);
-            if (classElement != null) {
-              classElement.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
-            }
-            merger.consume(classElement);
+  protected void delegate(CompletionParameters parameters, CompletionResultSet result, Consumer<CompletionResult> passResult) {
+    if (parameters.getCompletionType() == CompletionType.BASIC &&
+        parameters.getInvocationCount() <= 1 &&
+        JavaCompletionContributor.mayStartClassName(result, false) &&
+        GroovyCompletionContributor.isClassNamePossible(parameters.getPosition())) {
+      final ClassByNameMerger merger = new ClassByNameMerger(parameters.getInvocationCount() == 0, result);
+
+      GroovyCompletionContributor.addAllClasses(parameters, result,
+                                                       new Consumer<LookupElement>() {
+        @Override
+        public void consume(LookupElement element) {
+          JavaPsiClassReferenceElement classElement = element.as(JavaPsiClassReferenceElement.CLASS_CONDITION_KEY);
+          if (classElement != null) {
+            classElement.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
           }
-        }, new InheritorsHolder(parameters.getPosition(), result));
+          merger.consume(classElement);
+        }
+      }, new InheritorsHolder(parameters.getPosition(), result));
 
-        merger.finishedClassProcessing();
+      merger.finishedClassProcessing();
 
-      }
     }
   }
-
 }