mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
when typing a class name which is not yet imported, just type the space/[/</dot after it, don't select what's there in the autopopup
This commit is contained in:
@@ -40,6 +40,28 @@ public class JavaCharFilter extends CharFilter {
|
||||
return psiElement != null && psiElement.getParent() instanceof PsiLiteralExpression;
|
||||
}
|
||||
|
||||
public static boolean isNonImportedClassEntered(LookupImpl lookup) {
|
||||
if (lookup.isSelectionTouched() || !lookup.isCompletion()) return false;
|
||||
|
||||
CompletionProcess process = CompletionService.getCompletionService().getCurrentCompletion();
|
||||
if (process == null || !process.isAutopopupCompletion()) return false;
|
||||
|
||||
LookupElement item = lookup.getCurrentItem();
|
||||
if (item == null) return false;
|
||||
|
||||
PsiFile file = lookup.getPsiFile();
|
||||
if (file == null) return false;
|
||||
|
||||
Object o = item.getObject();
|
||||
if (o instanceof PsiClass && ((PsiClass)o).getName().length() > lookup.itemPattern(item).length()) {
|
||||
if (JavaPsiFacade.getInstance(file.getProject()).getShortNamesCache().getClassesByName(lookup.itemPattern(item), file.getResolveScope()).length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Result acceptChar(char c, final int prefixLength, final Lookup lookup) {
|
||||
if (!lookup.isCompletion()) return null;
|
||||
|
||||
@@ -63,6 +85,11 @@ public class JavaCharFilter extends CharFilter {
|
||||
return null;
|
||||
}
|
||||
if (c == '.' && isWithinLiteral(lookup)) return Result.ADD_TO_PREFIX;
|
||||
|
||||
if ((c == '[' || c == '<' || c == '.' || c == ' ') && isNonImportedClassEntered((LookupImpl)lookup)) {
|
||||
return Result.HIDE_LOOKUP;
|
||||
}
|
||||
|
||||
if (c == '[') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
if (c == '<' && o instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
if (c == '(' && o instanceof PsiClass) {
|
||||
|
||||
@@ -1037,4 +1037,21 @@ class LiveComplete {
|
||||
assert myFixture.lookupElementStrings == ['iterator']
|
||||
}
|
||||
|
||||
public void testTypingNonImportedClassName() {
|
||||
myFixture.addClass("package foo; public class Foo239 {} ")
|
||||
myFixture.addClass("class Foo239Util {} ")
|
||||
myFixture.addClass("class Foo239Util2 {} ")
|
||||
|
||||
myFixture.configureByText "a.java", "class Foo {{ <caret> }}"
|
||||
type 'Foo239 '
|
||||
assert myFixture.file.text.contains('Foo239 ')
|
||||
|
||||
myFixture.configureByText "a.java", "class Foo {{ <caret> }}"
|
||||
type 'Foo239'
|
||||
edt { myFixture.performEditorAction IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN }
|
||||
type ' '
|
||||
assert myFixture.file.text.contains('Foo239Util2 ')
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+6
@@ -15,9 +15,11 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.JavaCharFilter;
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
@@ -39,6 +41,10 @@ public class GroovyReferenceCharFilter extends CharFilter {
|
||||
return Result.ADD_TO_PREFIX;
|
||||
}
|
||||
|
||||
if ((c == '[' || c == '<' || c == '.' || c == ' ') && JavaCharFilter.isNonImportedClassEntered((LookupImpl)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;
|
||||
|
||||
|
||||
+16
@@ -121,5 +121,21 @@ class GroovyAutoPopupTest extends CompletionAutoPopupTestCase {
|
||||
assert myFixture.lookupElementStrings == ['xxxxx']
|
||||
}
|
||||
|
||||
public void testTypingNonImportedClassName() {
|
||||
CodeInsightSettings.instance.AUTOPOPUP_FOCUS_POLICY = CodeInsightSettings.ALWAYS
|
||||
|
||||
try {
|
||||
myFixture.addClass("package foo; public class Foo239 {} ")
|
||||
myFixture.addClass("class Foo239Util {} ")
|
||||
myFixture.configureByText "a.groovy", "<caret>"
|
||||
type 'Foo239 '
|
||||
myFixture.checkResult 'Foo239 <caret>'
|
||||
}
|
||||
finally {
|
||||
CodeInsightSettings.instance.AUTOPOPUP_FOCUS_POLICY = CodeInsightSettings.SMART
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user