don't get in the way when typing a label name in java/groovy
authorpeter <peter@jetbrains.com>
Tue, 24 Jan 2012 15:14:51 +0000 (16:14 +0100)
committerpeter <peter@jetbrains.com>
Tue, 24 Jan 2012 17:05:28 +0000 (18:05 +0100)
java/java-impl/src/com/intellij/codeInsight/completion/JavaCharFilter.java
java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyReferenceCharFilter.java
plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyAutoPopupTest.groovy

index a27fc2f952403da80c26808ea3b90dc6048ca773..8f8449945e4b537664c069fbd1e7c7e69647fb9b 100644 (file)
@@ -105,6 +105,17 @@ public class JavaCharFilter extends CharFilter {
     }
     if (c == '.' && isWithinLiteral(lookup)) return Result.ADD_TO_PREFIX;
 
+    if (c == ':') {
+      PsiFile file = lookup.getPsiFile();
+      PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
+      PsiElement element = lookup.getPsiElement();
+      if (PsiTreeUtil.getParentOfType(element, PsiSwitchLabelStatement.class) != null ||
+          PsiTreeUtil.getParentOfType(element, PsiConditionalExpression.class) != null) {
+        return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
+      }
+      return Result.HIDE_LOOKUP;
+    }
+
     if ((c == '[' || c == '<' || c == '.' || c == ' ' || c == '(') && isNonImportedClassEntered((LookupImpl)lookup)) {
       return Result.HIDE_LOOKUP;
     }
index 49fa6a2a352a7ad30682e6d8b7ffc718fc0e7ca0..87fef910ec3c83df1886ccfb37157723cb7efee9 100644 (file)
@@ -532,7 +532,7 @@ public interface Test {
     }
     edt { myFixture.type '\t' }
     myFixture.checkResult 'public interface Test { RuntimeException<caret>x }'
 }
+ }
 
   private def registerContributor(final Class contributor, LoadingOrder order = LoadingOrder.LAST) {
     def ep = Extensions.rootArea.getExtensionPoint("com.intellij.completion.contributor")
@@ -1194,5 +1194,13 @@ class Foo {{
     assert 'io' in myFixture.lookupElementStrings
   }
 
+  public void testEnteringLabel() {
+    myFixture.configureByText 'a.java', '''class Foo {{
+  <caret>
+}}
+'''
+    type 'FIS:'
+    assert myFixture.file.text.contains('FIS:')
+  }
 
 }
index eae8a4c942f487230a07a7c16a1cd44a4908039e..998d1ac5a3fbf3b6bf5cd640c9b477514dcfcbca 100644 (file)
@@ -20,10 +20,14 @@ import com.intellij.codeInsight.lookup.CharFilter;
 import com.intellij.codeInsight.lookup.Lookup;
 import com.intellij.codeInsight.lookup.LookupElement;
 import com.intellij.codeInsight.lookup.impl.LookupImpl;
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiFile;
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.GroovyFileType;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseLabel;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression;
 
 /**
  * @author ilyas
@@ -51,6 +55,21 @@ public class GroovyReferenceCharFilter extends CharFilter {
       return Result.HIDE_LOOKUP;
     }
 
+    if (c == ':') {
+      PsiFile file = lookup.getPsiFile();
+      PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
+      PsiElement element = lookup.getPsiElement();
+      if (PsiTreeUtil.getParentOfType(element, GrCaseLabel.class) != null ||
+          PsiTreeUtil.getParentOfType(element, GrConditionalExpression.class) != null ||
+          PsiTreeUtil.getParentOfType(element, GrArgumentList.class) != null ||
+          PsiTreeUtil.getParentOfType(element, GrListOrMap.class) != null
+        ) {
+        return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
+      }
+      return Result.HIDE_LOOKUP;
+    }
+
+
     if (c == '[') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
     if (c == '<' && item.getObject() instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
 
index 38edecf025c663de5cb93157845338d6d7a27d2f..5cb4306414a9fdc75e21445cd7229dc922673362 100644 (file)
@@ -226,4 +226,10 @@ class GroovyAutoPopupTest extends CompletionAutoPopupTestCase {
     assert myFixture.lookupElementStrings == ['PrimaBalerina']
   }
 
+  public void testEnteringLabel() {
+    myFixture.configureByText 'a.groovy', '<caret>'
+    type 'FIS:'
+    assert myFixture.file.text == 'FIS:'
+  }
+
 }