diff --git a/java/java-tests/testData/codeInsight/completion/javadoc/See1.java b/java/java-tests/testData/codeInsight/completion/javadoc/See1.java index 3ff4c483f89b..36fd1a607ff2 100644 --- a/java/java-tests/testData/codeInsight/completion/javadoc/See1.java +++ b/java/java-tests/testData/codeInsight/completion/javadoc/See1.java @@ -1,7 +1,7 @@ class C{ /** - * @see #n + * @see #not */ private int foo(int a, char b, String c) {} } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/javadoc/See2.java b/java/java-tests/testData/codeInsight/completion/javadoc/See2.java index f8eed0a74d49..53f421a60709 100644 --- a/java/java-tests/testData/codeInsight/completion/javadoc/See2.java +++ b/java/java-tests/testData/codeInsight/completion/javadoc/See2.java @@ -1,7 +1,7 @@ class C{ /** - * @see #n + * @see #not * * @since */ diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java index 0ad4a0585a4a..28ac231a533a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java @@ -110,6 +110,7 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{ configureByFile(path + "/before3.java"); performSmartCompletion(); + select(Lookup.NORMAL_SELECT_CHAR, 0); checkResultByFile(path + "/after3.java"); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index aab8ac0292cd..3f2a50a1d1b2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -1,1293 +1,1297 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInsight.completion - -import com.intellij.codeInsight.CodeInsightSettings -import com.intellij.codeInsight.TargetElementUtil -import com.intellij.codeInsight.completion.impl.CompletionServiceImpl -import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler -import com.intellij.codeInsight.lookup.Lookup -import com.intellij.codeInsight.lookup.LookupManager -import com.intellij.codeInsight.lookup.impl.LookupImpl -import com.intellij.codeInsight.template.TemplateManager -import com.intellij.codeInsight.template.impl.TemplateManagerImpl -import com.intellij.ide.DataManager -import com.intellij.ide.ui.UISettings -import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.IdeActions -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.command.CommandProcessor -import com.intellij.openapi.command.WriteCommandAction -import com.intellij.openapi.command.impl.CurrentEditorProvider -import com.intellij.openapi.command.impl.UndoManagerImpl -import com.intellij.openapi.command.undo.UndoManager -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.editor.EditorFactory -import com.intellij.openapi.editor.LogicalPosition -import com.intellij.openapi.editor.actionSystem.EditorActionManager -import com.intellij.openapi.extensions.Extensions -import com.intellij.openapi.extensions.LoadingOrder -import com.intellij.openapi.fileEditor.FileEditor -import com.intellij.openapi.fileEditor.FileEditorManager -import com.intellij.openapi.progress.ProgressManager -import com.intellij.psi.PsiFile -import com.intellij.psi.PsiJavaFile - -/** - * @author peter - */ -class JavaAutoPopupTest extends CompletionAutoPopupTestCase { - - public void testNewItemsOnLongerPrefix() { - myFixture.configureByText("a.java", """ - class Foo { - void foo(String iterable) { - - } - } - """) - type('i') - assertSameElements myFixture.lookupElementStrings, "if", "iterable", "int" - - type('t') - assertOrderedEquals myFixture.lookupElementStrings, "iterable" - assertEquals 'iterable', lookup.currentItem.lookupString - - type('er') - assertOrderedEquals myFixture.lookupElementStrings, "iter", "iterable" - assertEquals 'iterable', lookup.currentItem.lookupString - assert lookup.focused - - type 'a' - assert lookup.focused - } - - public void testRecalculateItemsOnBackspace() { - myFixture.configureByText("a.java", """ - class Foo { - void foo(String iterable) { - int itaa; - ite - } - } - """) - type "r" - assertOrderedEquals myFixture.lookupElementStrings, "iter", "iterable" - - type '\b' - assertOrderedEquals myFixture.lookupElementStrings, "iterable" - - type '\b' - assertOrderedEquals myFixture.lookupElementStrings, "itaa", "iterable" - type "a" - assertOrderedEquals myFixture.lookupElementStrings, "itaa" - type '\b' - assertOrderedEquals myFixture.lookupElementStrings, "itaa", "iterable" - type "e" - assertOrderedEquals myFixture.lookupElementStrings, "iterable" - - type "r" - assertOrderedEquals myFixture.lookupElementStrings, "iter", "iterable" - } - - public void testExplicitSelectionShouldSurvive() { - myFixture.configureByText("a.java", """ - class Foo { - void foo(String iterable) { - int iterable2; - it - } - } - """) - type "e" - assertOrderedEquals myFixture.lookupElementStrings, "iterable", "iterable2" - - assertEquals 'iterable', lookup.currentItem.lookupString - edt { myFixture.performEditorAction IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN } - assertEquals 'iterable2', lookup.currentItem.lookupString - - type "r" - assertOrderedEquals myFixture.lookupElementStrings, "iter", "iterable", 'iterable2' - assertEquals 'iterable2', lookup.currentItem.lookupString - - } - - public void testExplicitMouseSelectionShouldSurvive() { - myFixture.configureByText("a.java", """ - class Foo { - void foo(String iterable) { - int iterable2; - it - } - } - """) - type "e" - assertOrderedEquals myFixture.lookupElementStrings, "iterable", "iterable2" - - assertEquals 'iterable', lookup.currentItem.lookupString - lookup.currentItem = lookup.items[1] - assertEquals 'iterable2', lookup.currentItem.lookupString - - type "r" - assertOrderedEquals myFixture.lookupElementStrings, "iter", "iterable", 'iterable2' - assertEquals 'iterable2', lookup.currentItem.lookupString - - } - - public void testGenerallyFocusLookupInJavaMethod() { - myFixture.configureByText("a.java", """ - class Foo { - String foo(String iterable) { - return it; - } - } - """) - type 'e' - assertTrue lookup.focused - } - - public void testNoLookupFocusInJavaVariable() { - myFixture.configureByText("a.java", """ - class Foo { - String foo(String st) { - } - } - """) - type 'r' - assertFalse lookup.focused - } - - public void testNoStupidNameSuggestions() { - myFixture.configureByText("a.java", """ - class Foo { - String foo(String ) { - } - } - """) - type 'r' - assertNull lookup - } - - public void testExplicitSelectionShouldBeHonoredFocused() { - myFixture.configureByText("a.java", """ - class Foo { - String foo() { - int abcd; - int abce; - a - } - } - """) - type 'b' - assert lookup.focused - type 'c' - - assertOrderedEquals myFixture.lookupElementStrings, 'abcd', 'abce' - assertEquals 'abcd', lookup.currentItem.lookupString - lookup.currentItem = lookup.items[1] - assertEquals 'abce', lookup.currentItem.lookupString - - type '\t' - myFixture.checkResult """ - class Foo { - String foo() { - int abcd; - int abce; - abce - } - } - """ - } - - - public void testFocusInJavadoc() { - myFixture.configureByText("a.java", """ - /** - * {@link AIO} - */ - class Foo {} - """) - type 'O' - assert lookup.focused - - } - - public void testPrefixLengthDependentSorting() { - myFixture.addClass("package foo; public class PsiJavaCodeReferenceElement {}") - myFixture.configureByText("a.java", """ - import foo.PsiJavaCodeReferenceElement; - - class PsiJavaCodeReferenceElementImpl { - { } - } - """) - type 'PJCR' - assertOrderedEquals myFixture.lookupElementStrings, 'PsiJavaCodeReferenceElement', 'PsiJavaCodeReferenceElementImpl' - - } - - public void testQuickSelectAfterReuse() { - myFixture.configureByText("a.java", """ - class A { Iterable iterable; - { } - } - """) - type 'ite' - edt { - myFixture.type 'r' - lookup.markReused() - lookup.currentItem = lookup.items[0] - CommandProcessor.instance.executeCommand project, {lookup.finishLookup Lookup.NORMAL_SELECT_CHAR}, null, null - - } - myFixture.checkResult """ - class A { Iterable iterable; - { iterable } - } - """ - } - - public void testQuickSelectAfterReuseAndBackspace() { - myFixture.configureByText("a.java", """ - class A { Iterable iterable; - { } - } - """) - type 'ite' - edt { - myFixture.type 'r' - lookup.markReused() - myFixture.type '\b\b' - lookup.currentItem = lookup.items[0] - CommandProcessor.instance.executeCommand project, ({lookup.finishLookup Lookup.NORMAL_SELECT_CHAR} as Runnable), null, null - } - myFixture.checkResult """ - class A { Iterable iterable; - { iterable } - } - """ - } - - public void testQuickSelectLiveTemplate() { - myFixture.configureByText("a.java", """ - class A { - { } - } - """) - type 'th' - edt { myFixture.type 'r\t'} - myFixture.checkResult """ - class A { - { throw new } - } - """ - } - - public void testTwoQuickRestartsAfterHiding() { - for (i in 0..10) { - myFixture.configureByText("a${i}.java", """ - class A { - { } - } - """) - edt { myFixture.type 'A' } - joinAutopopup() // completion started - boolean tooQuick = false - edt { - tooQuick = lookup == null - myFixture.type 'IO' - } - joinAutopopup() //I - joinAutopopup() //O - joinCompletion() - assert lookup - assert 'ArrayIndexOutOfBoundsException' in myFixture.lookupElementStrings - if (!tooQuick) { - return - } - edt { - LookupManager.getInstance(project).hideActiveLookup() - CompletionProgressIndicator.cleanupForNextTest() - } - } - fail "too many too quick attempts" - } - - public void testTypingDuringExplicitCompletion() { - myFixture.configureByText("a.java", """ - class A { - { Runnable r = new } - } - """) - myFixture.complete CompletionType.SMART - edt { myFixture.type 'Thr' } - joinCompletion() - assert lookup - assert 'Thread' in myFixture.lookupElementStrings - } - - public void testDotAfterVariable() { - myFixture.configureByText("a.java", """ - class A { - { Object ooo; } - } - """) - type 'o.' - assert myFixture.file.text.contains("ooo.") - assert lookup - } - - public void testDotAfterCall() { - myFixture.configureByText("a.java", """ - class A { - { } - } - """) - type 'tos.' - assert myFixture.file.text.contains("toString().") - assert lookup - } - - public void testDotAfterClassName() { - myFixture.configureByText("a.java", """ - class A { - { } - } - """) - type 'AIOO.' - assert myFixture.file.text.contains("ArrayIndexOutOfBoundsException.") - assert lookup - } - - public void testDotAfterClassNameInParameter() { - myFixture.configureByText("a.java", """ - class A { - void foo() {} - } - """) - type 'AIOO...' - assert myFixture.editor.document.text.contains("ArrayIndexOutOfBoundsException...") - assert !lookup - } - - void testArrow(boolean up, boolean cycleScrolling, boolean lookupAbove, int index) { - myFixture.configureByText("a.java", """ - class A { - { ArrayIndexOutOfBoundsException } - } - """) - - type 'o' - assert lookup - assert !lookup.focused - assert lookup.items.size() == 2 - - lookup.positionedAbove = lookupAbove - UISettings.instance.CYCLE_SCROLLING = cycleScrolling - - def action = up ? IdeActions.ACTION_EDITOR_MOVE_CARET_UP : IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN - try { - edt { myFixture.performEditorAction(action) } - if (lookup) { - assert lookup.focused - assert index >= 0 - assert lookup.items[index] == lookup.currentItem - edt { lookup.hide() } - } else { - assert index == -1 - } - type '\b' - } - finally { - UISettings.instance.CYCLE_SCROLLING = true - } - - } - - void testArrows(boolean cycleScrolling, boolean lookupAbove, int indexDown, int indexUp) { - testArrow true, cycleScrolling, lookupAbove, indexUp - testArrow false, cycleScrolling, lookupAbove, indexDown - } - - public void testVerticalArrows() { - testArrows false, false, 0, -1 - testArrows false, true, 0, -1 - testArrows true, false, 0, 1 - testArrows true, true, 0, 1 - } - - public void testHideOnOnePrefixVariant() { - myFixture.configureByText("a.java", """ - class A { - Object foo() { return nu } - } - """) - type 'll' - assert !lookup - } - - public void testResumeAfterBackspace() { - myFixture.configureByText("a.java", """ - class A { - Object foo() { this } - } - """) - type '.' - assert lookup - type 'a' - assert !lookup - type '\b' - assert !lookup - type 'c' - assert lookup - } - - public void testHideOnInvalidSymbolAfterBackspace() { - myFixture.configureByText("a.java", """ - class A { - Object foo() { this } - } - """) - type '.' - assert lookup - type 'c' - assert lookup - type '\b' - assert lookup - type 'x' - assert !lookup - } - - public void testDoubleLiteralInField() { - myFixture.configureByText "a.java", """ -public interface Test { - double FULL = 1.0 -}""" - type 'd' - assert !lookup - } - - public void testCancellingDuringCalculation() { - myFixture.configureByText "a.java", """ -class Aaaaaaa {} -public interface Test { - -}""" - edt { myFixture.type 'A' } - joinAutopopup() - def first = lookup - assert first - edt { - assert first == lookup - lookup.hide() - myFixture.type 'a' - } - joinAutopopup() - joinAutopopup() - joinAutopopup() - assert lookup != first - } - - static class LongReplacementOffsetContributor extends CompletionContributor { - @Override - void duringCompletion(CompletionInitializationContext cxt) { - Thread.sleep 500 - ProgressManager.checkCanceled() - cxt.replacementOffset--; - } - } - - static class LongContributor extends CompletionContributor { - - @Override - void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) { - result.runRemainingContributors(parameters, true) - Thread.sleep 1000 - } - } - - public void testDuringCompletionMustFinish() { - registerContributor(LongReplacementOffsetContributor) - - edt { myFixture.addFileToProject 'directory/foo.txt', '' } - myFixture.configureByText "a.java", 'public interface Test { RuntiExcexxx }' - myFixture.completeBasic() - while (!lookup.items) { - Thread.sleep(10) - edt { lookup.refreshUi(false, false) } - } - edt { myFixture.type '\t' } - myFixture.checkResult 'public interface Test { RuntimeExceptionx }' - } - - private def registerContributor(final Class contributor, LoadingOrder order = LoadingOrder.LAST) { - def ep = Extensions.rootArea.getExtensionPoint("com.intellij.completion.contributor") - def bean = new CompletionContributorEP(language: 'JAVA', implementationClass: contributor.name) - ep.registerExtension(bean, order) - disposeOnTearDown({ ep.unregisterExtension(bean) } as Disposable) - } - - public void testLeftRightMovements() { - myFixture.configureByText("a.java", """ - class Foo { - void foo(String iterable) { - ter x - } - } - """) - type('i') - def offset = myFixture.editor.caretModel.offset - assertSameElements myFixture.lookupElementStrings, "if", "iterable", "int" - - edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT) } - assert myFixture.editor.caretModel.offset == offset + 1 - assertOrderedEquals myFixture.lookupElementStrings, "iterable" - assertEquals 'iterable', lookup.currentItem.lookupString - - edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT) } - assert myFixture.editor.caretModel.offset == offset - assertSameElements myFixture.lookupElementStrings, "if", "iterable", "int" - assertEquals 'iterable', lookup.currentItem.lookupString - - edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT) } - joinAutopopup() - joinCompletion() - assert lookup.items.size() > 3 - - for (i in 0.."iter".size()) { - edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT) } - } - assert !lookup - } - - public void testTypingInAnotherEditor() { - myFixture.configureByText("a.java", "") - type 'c' - assert lookup - - Editor another = null - def wca = new WriteCommandAction.Simple(getProject(), new PsiFile[0]) { - @Override - protected void run() { - EditorActionManager.instance.getTypedAction().handler.execute(another, (char) 'x', DataManager.instance.dataContext) - } - } - - try { - edt { - assert !lookup.calculating - lookup.hide() - def file = myFixture.addFileToProject("b.java", "") - another = EditorFactory.instance.createEditor(file.viewProvider.document, project) - wca.execute() - assert 'x' == another.document.text - } - joinAutopopup() - joinCompletion() - LookupImpl l1 = LookupManager.getActiveLookup(another) - if (l1) { - printThreadDump() - println l1.items - println l1.calculating - println myFixture.editor - println another - println CompletionServiceImpl.completionPhase - assert false : l1.items - } - type 'l' - assert lookup - } - finally { - edt { EditorFactory.instance.releaseEditor(another) } - } - - } - - public void testExplicitCompletionOnEmptyAutopopup() { - myFixture.configureByText("a.java", "") - type 'cccccc' - myFixture.completeBasic() - joinCompletion() - assert !lookup - } - - public void testNoSingleTemplateLookup() { - myFixture.configureByText 'a.java', 'class Foo {{ ite }}' - type 'r' - assert !lookup - } - - public void testTemplatesWithNonImportedClasses() { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE - myFixture.addClass("package foo.bar; public class LayoutStore {}") - try { - myFixture.configureByText 'a.java', 'class Foo {{ foo() }}' - type 'lst' - assert lookup - assert 'lst' in myFixture.lookupElementStrings - assert 'LayoutStore' in myFixture.lookupElementStrings - } - finally { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER - } - } - - public void testTemplateSelectionByComma() { - myFixture.configureByText("a.java", """ -class Foo { - int itea = 2; - int itera = 2; - - { - it - } -} -""") - type 'e' - assertOrderedEquals myFixture.lookupElementStrings, "itea", "itera" - type 'r' - assertOrderedEquals myFixture.lookupElementStrings, "iter", "itera" - type ',' - assert !lookup - assert myFixture.editor.document.text.contains('itera,') - } - - public void testTemplateSelectionBySpace() { - myFixture.configureByText("a.java", """ -class Foo { - int ITER = 2; - int itea = 2; - - { - it - } -} -""") - type 'er ' - assert myFixture.editor.document.text.contains('iter ') - } - - public void testNewClassParenthesis() { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE - try { - myFixture.configureByText("a.java", """ class Foo { { new } } """) - type 'aioo(' - assert myFixture.editor.document.text.contains('new ArrayIndexOutOfBoundsException()') - } - finally { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER - } - } - - public void testUnknownMethodParenthesis() { - myFixture.configureByText("a.java", """ class Foo { { } } """) - type 'filinpstr(' - assert myFixture.editor.document.text.contains('filinpstr()') - } - - public void testNoAutopopupAfterSpace() { - myFixture.configureByText("a.java", """ class Foo { { int newa; } } """) - edt { myFixture.type('new ') } - joinAutopopup() - joinCompletion() - assert !lookup - } - - public void testRestartAndTypingDuringCopyCommit() { - registerContributor(LongReplacementOffsetContributor) - - myFixture.configureByText("a.java", """ class Foo { { int newa; } } """) - myFixture.type 'n' - joinAutopopup() - myFixture.type 'e' - joinCommit() // original commit - myFixture.type 'w' - joinAutopopup() - joinCompletion() - myFixture.type '\n' - myFixture.checkResult(" class Foo { { int newa; new } } ") - assert !lookup - } - - public void testAutoRestartAndTypingDuringCopyCommit() { - registerContributor(LongReplacementOffsetContributor) - - myFixture.configureByText("a.java", """ class Foo { { int iteraaa; } } """) - type 'ite' - assert !('iter' in myFixture.lookupElementStrings) - myFixture.type 'r' - joinCommit() - myFixture.type 'a' - joinAutopopup() - joinCompletion() - myFixture.type '\n' - myFixture.checkResult(" class Foo { { int iteraaa; iteraaa } } ") - assert !lookup - } - - public void testChoosingItemDuringCopyCommit() { - registerContributor(LongReplacementOffsetContributor) - - myFixture.configureByText("a.java", """ class Foo { { int iteraaa; } } """) - type 'ite' - assert !('iter' in myFixture.lookupElementStrings) - assert 'iteraaa' in myFixture.lookupElementStrings - myFixture.type 'r' - joinCommit() - myFixture.type 'a.' - myFixture.checkResult(" class Foo { { int iteraaa; iteraaa. } } ") - } - - public void testRestartWithInvisibleLookup() { - registerContributor(LongReplacementOffsetContributor) - - myFixture.configureByText("a.java", """ class Foo { { int abcdef; } } """) - myFixture.type 'a' - joinAutopopup() - assert lookup - edt { myFixture.type 'bc' } - joinAutopopup() - joinAutopopup() - joinCompletion() - assert lookup - assert lookup.shown - } - - public void testRestartWithVisibleLookup() { - registerContributor(LongContributor, LoadingOrder.FIRST) - - myFixture.configureByText("a.java", """ class Foo { { int abcdef; a } } """) - myFixture.completeBasic() - while (!lookup.shown) { - Thread.sleep(1) - } - def l = lookup - edt { - assert lookup.calculating - myFixture.type 'b' - } - joinCommit { - myFixture.type 'c' - } - joinAutopopup() - joinCompletion() - assert lookup == l - assert !lookup.calculating - assert lookup.shown - } - - private void joinSomething(int degree) { - if (degree == 0) return - joinAlarm() - if (degree == 1) return - joinCommit() - if (degree == 2) return - joinCommit() - if (degree == 3) return - edt {} - if (degree == 4) return - joinCompletion() - } - - public void testEveryPossibleWayToTypeIf() { - def src = "class Foo { { int ifa; } }" - def result = "class Foo { { int ifa; if } }" - int actions = 5 - - for (a1 in 0..actions) { - println "a1 = $a1" - for (a2 in 0..actions) { - myFixture.configureByText("$a1 $a2 .java", src) - myFixture.type 'i' - joinSomething(a1) - myFixture.type 'f' - joinSomething(a2) - myFixture.type ' ' - - joinAutopopup() - joinCompletion() - myFixture.checkResult(result) - assert !lookup - } - } - - for (a1 in 0..actions) { - myFixture.configureByText("$a1 if .java", src) - edt { myFixture.type 'if' } - joinSomething(a1) - - myFixture.type ' ' - - joinAutopopup() - joinCompletion() - myFixture.checkResult(result) - assert !lookup - } - - for (a1 in 0..actions) { - myFixture.configureByText("$a1 if .java", src) - myFixture.type 'i' - joinSomething(a1) - - edt { myFixture.type 'f ' } - - joinAutopopup() - joinCompletion() - myFixture.checkResult(result) - assert !lookup - } - - } - - public void testNonFinishedParameterComma() { - myFixture.configureByText("a.java", """ class Foo { void foo(int aaa, int aaaaa) { foo() } } """) - type 'a,' - assert myFixture.editor.document.text.contains('foo(aaa, )') - } - - public void testFinishedParameterComma() { - myFixture.configureByText("a.java", """ class Foo { void foo(int aaa, int aaaaa) { foo() } } """) - type 'aaa,' - assert myFixture.editor.document.text.contains('foo(aaa,)') - } - - public void testNonFinishedVariableEq() { - myFixture.configureByText("a.java", """ class Foo { void foo(int aaa, int aaaaa) { } } """) - type 'a=' - assert myFixture.editor.document.text.contains('aaa = ') - } - - public void testFinishedVariableEq() { - myFixture.configureByText("a.java", """ class Foo { void foo(int aaa, int aaaaa) { } } """) - type 'aaa=' - assert myFixture.editor.document.text.contains('aaa=') - } - - public void testCompletionWhenLiveTemplateAreNotSufficient() { - ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(true); - try { - myFixture.configureByText("a.java", """ - class Foo { - { - Iterable l1 = null; - Iterable l2 = null; - Object asdf = null; - iter - } - } - """) - type '\t' - assert myFixture.lookupElementStrings == ['l2', 'l1'] - type 'as' - assert lookup - assert myFixture.lookupElementStrings == ['asdf', 'assert'] - type '\n.' - assert lookup - assert 'hashCode' in myFixture.lookupElementStrings - assert myFixture.file.text.contains('asdf.') - } - finally { - ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(false); - } - - } - - public void testNoWordCompletionAutoPopup() { - myFixture.configureByText "a.java", 'class Bar { void foo() { "f" }}' - type 'o' - assert !lookup - } - - public void testMethodNameRestart() { - myFixture.configureByText "a.java", ''' -public class Bar { - private static List getS - -} -''' - type 'ta' - assert !lookup - } - - public void testTargetElementInLookup() { - myFixture.configureByText 'a.java', ''' -class Foo { - void x__foo() {} - void bar() { - - } - void x__goo() {} -} -''' - def cls = ((PsiJavaFile)myFixture.file).getClasses()[0] - def foo = cls.methods[0] - def goo = cls.methods[2] - type('x') - assert myFixture.lookupElementStrings == ['x__foo', 'x__goo'] - edt { - assert foo == TargetElementUtil.instance.findTargetElement(myFixture.editor, TargetElementUtil.LOOKUP_ITEM_ACCEPTED) - myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN) - assert goo == TargetElementUtil.instance.findTargetElement(myFixture.editor, TargetElementUtil.LOOKUP_ITEM_ACCEPTED) - } - - type('_') - assert myFixture.lookupElementStrings == ['x__foo', 'x__goo'] - edt { - assert goo == TargetElementUtil.instance.findTargetElement(myFixture.editor, TargetElementUtil.LOOKUP_ITEM_ACCEPTED) - myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP) - assert foo == TargetElementUtil.instance.findTargetElement(myFixture.editor, TargetElementUtil.LOOKUP_ITEM_ACCEPTED) - } - } - - public void testExplicitAutocompletionAfterAutoPopup() { - myFixture.configureByText 'a.java', 'class Foo ' - type 'ext' - - CompletionAutoPopupHandler.ourTestingAutopopup = false - edt { - myFixture.completeBasic() - } - myFixture.checkResult 'class Foo extends ' - } - - public void testExplicitMultipleVariantCompletionAfterAutoPopup() { - myFixture.configureByText 'a.java', 'class Foo {}' - type 'pr' - - CompletionAutoPopupHandler.ourTestingAutopopup = false - edt { - myFixture.completeBasic() - } - myFixture.checkResult 'class Foo {pr}' - - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - void run() { - getLookup().items.each { - getLookup().list.cellRenderer.getListCellRendererComponent(getLookup().list, it, 0, false, false) - } - } - }); - assert myFixture.lookupElementStrings.containsAll(['private', 'protected']) - } - - public void testArrays() { - myFixture.configureByText "a.java", "class Foo {{ }}" - type 'Arrays.' - myFixture.checkResult "class Foo {{ Arrays. }}" - assert 'Arrays.asList' in myFixture.lookupElementStrings - } - - - public void testExactMatchesFirst() { - myFixture.configureByText("a.java", """ -public class UTest { - void nextWord() {} - - void foo() { - n - } -}""") - type 'ew' - assert myFixture.lookupElementStrings == ['new', 'nextWord'] - } - - public void testUpdatePrefixMatchingOnTyping() { - myFixture.addClass("class CertificateEncodingException {}") - myFixture.addClass("class CertificateException {}") - myFixture.configureByText 'a.java', 'class Foo {}' - type 'CertificateExce' - assert myFixture.lookupElementStrings == ['CertificateException', 'CertificateEncodingException'] - } - - public void testNoClassesInUnqualifiedImports() { - myFixture.addClass("package xxxxx; public class Xxxxxxxxx {}") - myFixture.configureByText 'a.java', 'package foo; import ' - type 'xxx' - assert !lookup - } - - public void testPopupAfterDotAfterPackage() { - myFixture.configureByText 'a.java', '' - type 'import jav' - assert lookup - type '.' - assert lookup - } - - public void testSamePrefixIgnoreCase() { - myFixture.addClass("package xxxxx; public class SYSTEM_EXCEPTION {}") - myFixture.configureByText "a.java", "import xxxxx.*; class Foo { S }" - type 'Ystem' - assert 'java.lang.System' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[0]).qualifiedName - assert 'xxxxx.SYSTEM_EXCEPTION' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[1]).qualifiedName - } - - public void testSamePrefixIgnoreCase2() { - myFixture.addClass("package xxxxx; public class SYSTEM_EXCEPTION {}") - myFixture.addClass("package xxxxx; public class SYstem {}") - myFixture.configureByText "a.java", "import xxxxx.*; class Foo { S }" - type 'Ystem' - assert 'xxxxx.SYstem' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[0]).qualifiedName - assert 'java.lang.System' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[1]).qualifiedName - assert 'xxxxx.SYSTEM_EXCEPTION' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[2]).qualifiedName - } - - private FileEditor openEditorForUndo() { - FileEditor editor; - edt { editor = FileEditorManager.getInstance(project).openFile(myFixture.file.virtualFile, false)[0] } - def manager = (UndoManagerImpl) UndoManager.getInstance(project) - def old = manager.editorProvider - manager.editorProvider = new CurrentEditorProvider() { - @Override - public FileEditor getCurrentEditor() { - return editor; - } - }; - disposeOnTearDown ({ manager.editorProvider = old } as Disposable) - return editor - } - - public void _testCharSelectionUndo() { - myFixture.configureByText "a.java", "class Foo {{ }}" - def editor = openEditorForUndo(); - type('ArrStoExce.') - edt { UndoManager.getInstance(project).undo(editor) } - assert myFixture.editor.document.text.contains('ArrStoExce.') - } - - public void testAutopopupTypingUndo() { - myFixture.configureByText "a.java", "class Foo {{ }}" - def editor = openEditorForUndo(); - type 'aioobeeee' - edt { UndoManager.getInstance(project).undo(editor) } - assert !myFixture.editor.document.text.contains('aioo') - } - - public void testNoLiveTemplatesAfterDot() { - myFixture.configureByText "a.java", "class Foo {{ Iterable t; t. }}" - type 'iter' - 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 {{ }}" - type 'Foo239 ' - assert myFixture.file.text.contains('Foo239 ') - - myFixture.configureByText "a.java", "class Foo {{ }}" - type 'Foo239' - edt { myFixture.performEditorAction IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN } - type ' ' - assert myFixture.file.text.contains('Foo239Util2 ') - - myFixture.configureByText "a.java", "class Foo {{ }}" - type 'new Foo239(' - assert myFixture.file.text.contains('new Foo239()') - } - - public void testTypingFirstVarargDot() { - myFixture.configureByText "a.java", "class Foo { void foo(Foo[] a) { }; class Bar {}}" - type '.' - assert !lookup - } - - public void testBlockSelection() { - doTestBlockSelection """ -class Foo {{ - tx; - tx; -}}""", '\n', ''' -class Foo {{ - toString()x; - toString()x; -}}''' - } - - public void testBlockSelectionTab() { - doTestBlockSelection """ -class Foo {{ - tx; - tx; -}}""", '\t', ''' -class Foo {{ - toString(); - toString(); -}}''' - } - - public void testBlockSelectionBackspace() { - doTestBlockSelection """ -class Foo {{ - t; - t; -}}""", '\b\t', ''' -class Foo {{ - toString(); - toString(); -}}''' - } - - private doTestBlockSelection(final String textBefore, final String toType, final String textAfter) { - myFixture.configureByText "a.java", textBefore - edt { - def caret = myFixture.editor.offsetToLogicalPosition(myFixture.editor.caretModel.offset) - myFixture.editor.selectionModel.setBlockSelection(caret, new LogicalPosition(caret.line + 1, caret.column + 1)) - } - type 'toStr' - assert lookup - type toType - myFixture.checkResult textAfter - def start = myFixture.editor.selectionModel.blockStart - def end = myFixture.editor.selectionModel.blockEnd - assert start.line == end.line - 1 - assert start.column == end.column - assert end == myFixture.editor.caretModel.logicalPosition - } - - public void testNonImportedClass() { - myFixture.addClass("package foo; public class Abcdefg {}") - myFixture.configureByText 'a.java', 'class Foo extends ' - type 'Abcde ' - myFixture.checkResult 'import foo.Abcdefg;\n\nclass Foo extends Abcdefg ' - } - - public void testTwoNonImportedClasses() { - myFixture.addClass("package foo; public class Abcdefg {}") - myFixture.addClass("package bar; public class Abcdefg {}") - myFixture.configureByText 'a.java', 'class Foo extends ' - type 'Abcde ' - myFixture.checkResult 'class Foo extends Abcdefg ' - } - - public void testClassNameInProperties() { - myFixture.addClass("package java.langa; public class Abcdefg {}") - myFixture.configureByText 'a.properties', 'key.11=java' - type '.' - assert lookup - type 'lang' - assert myFixture.lookupElementStrings.size() >= 2 - type '.' - assert lookup - edt { myFixture.editor.caretModel.moveToOffset(myFixture.editor.document.text.indexOf('lang')) } - assert !lookup - type 'i' - assert 'io' in myFixture.lookupElementStrings - } - - public void testEnteringLabel() { - myFixture.configureByText 'a.java', '''class Foo {{ - -}} -''' - type 'FIS:' - assert myFixture.file.text.contains('FIS:') - } - - public void testSoutvTemplate() { - ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(true); - try { - myFixture.configureByText 'a.java', 'class Foo {{ }}' - type 'soutv\tgetcl.' - myFixture.checkResult '''class Foo {{ - System.out.println("getClass(). = " + getClass().); }}''' - } - finally { - ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(false); - } - } - - public void testReturnLParen() { - myFixture.configureByText 'a.java', 'class Foo { int foo() { }}' - type 're(' - myFixture.checkResult 'class Foo { int foo() { re() }}' - } - - public void testAmbiguousClassQualifier() { - myFixture.addClass("package foo; public class Util { public static void foo() {} }") - myFixture.addClass("package bar; public class Util { public static void bar() {} }") - myFixture.configureByText 'a.java', 'class Foo {{ }}' - type 'Util.' - assert myFixture.lookupElementStrings == ['Util.bar', 'Util.foo'] - type 'fo\n' - myFixture.checkResult '''import foo.Util; - -class Foo {{ - Util.foo(); }}''' - } - - public void testPackageQualifier() { - myFixture.addClass("package com.too; public class Util {}") - myFixture.configureByText 'a.java', 'class Foo { void foo(Object command) { }}' - type 'com.t' - assert myFixture.lookupElementStrings.containsAll(['too', 'command.toString']) - } - - public void testUnfinishedString() { - myFixture.configureByText 'a.java', ''' -// Date -class Foo { - String s = " - String s2 = s; -} -''' - type 'D' - assert !lookup - } - - public void testVarargParenthesis() { - myFixture.configureByText 'a.java', ''' -class Foo { - void foo(File... files) { } - { foo(new ) } -} -''' - type 'File(' - assert myFixture.file.text.contains('new File()') - } - - public void "test inaccessible class in another package shouldn't prevent choosing by space"() { - myFixture.addClass("package foo; class b {}") - myFixture.configureByText 'a.java', 'class Foo {{ }}' - type 'b' - assert lookup?.currentItem?.lookupString == 'boolean' - type ' ' - myFixture.checkResult 'class Foo {{ boolean }}' - } - - @Override - protected void tearDown() { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER - super.tearDown() - } - - public void testBackspaceShouldShowPreviousVariants() { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE - myFixture.addClass("class OuterX { static class TrueLine {} }") - myFixture.configureByText 'a.java', 'class Foo{ void foo(int truex) { return tr }}' - type 'ue' - assert myFixture.lookupElementStrings == ['true', 'truex'] - type 'l' - assert myFixture.lookupElementStrings == ['TrueLine'] - type '\b' - assert myFixture.lookupElementStrings == ['true', 'truex'] - } - -} +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.completion + +import com.intellij.codeInsight.CodeInsightSettings +import com.intellij.codeInsight.TargetElementUtil +import com.intellij.codeInsight.completion.impl.CompletionServiceImpl +import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler +import com.intellij.codeInsight.lookup.Lookup +import com.intellij.codeInsight.lookup.LookupManager +import com.intellij.codeInsight.lookup.impl.LookupImpl +import com.intellij.codeInsight.template.TemplateManager +import com.intellij.codeInsight.template.impl.TemplateManagerImpl +import com.intellij.ide.DataManager +import com.intellij.ide.ui.UISettings +import com.intellij.openapi.Disposable +import com.intellij.openapi.actionSystem.IdeActions +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.command.CommandProcessor +import com.intellij.openapi.command.WriteCommandAction +import com.intellij.openapi.command.impl.CurrentEditorProvider +import com.intellij.openapi.command.impl.UndoManagerImpl +import com.intellij.openapi.command.undo.UndoManager +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.editor.EditorFactory +import com.intellij.openapi.editor.LogicalPosition +import com.intellij.openapi.editor.actionSystem.EditorActionManager +import com.intellij.openapi.extensions.Extensions +import com.intellij.openapi.extensions.LoadingOrder +import com.intellij.openapi.fileEditor.FileEditor +import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.progress.ProgressManager +import com.intellij.psi.PsiFile +import com.intellij.psi.PsiJavaFile + +/** + * @author peter + */ +class JavaAutoPopupTest extends CompletionAutoPopupTestCase { + + public void testNewItemsOnLongerPrefix() { + myFixture.configureByText("a.java", """ + class Foo { + void foo(String iterable) { + + } + } + """) + type('i') + assertContains("if", "iterable", "int") + + type('t') + assertContains "iterable" + assertEquals 'iterable', lookup.currentItem.lookupString + + type('er') + assertContains("iter", "iterable") + assertEquals 'iterable', lookup.currentItem.lookupString + assert lookup.focused + + type 'a' + assert lookup.focused + } + + def assertContains(String... items) { + assert myFixture.lookupElementStrings.containsAll(items as List) + } + + public void testRecalculateItemsOnBackspace() { + myFixture.configureByText("a.java", """ + class Foo { + void foo(String iterable) { + int itaa; + ite + } + } + """) + type "r" + assertContains "iter", "iterable" + + type '\b' + assertContains "iterable" + + type '\b' + assertContains "itaa", "iterable" + type "a" + assertContains "itaa" + type '\b' + assertContains "itaa", "iterable" + type "e" + assertContains "iterable" + + type "r" + assertContains "iter", "iterable" + } + + public void testExplicitSelectionShouldSurvive() { + myFixture.configureByText("a.java", """ + class Foo { + void foo(String iterable) { + int iterable2; + it + } + } + """) + type "e" + assertContains "iterable", "iterable2" + + assertEquals 'iterable', lookup.currentItem.lookupString + edt { myFixture.performEditorAction IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN } + assertEquals 'iterable2', lookup.currentItem.lookupString + + type "r" + assertContains "iter", "iterable", 'iterable2' + assertEquals 'iterable2', lookup.currentItem.lookupString + + } + + public void testExplicitMouseSelectionShouldSurvive() { + myFixture.configureByText("a.java", """ + class Foo { + void foo(String iterable) { + int iterable2; + it + } + } + """) + type "e" + assertContains "iterable", "iterable2" + + assertEquals 'iterable', lookup.currentItem.lookupString + lookup.currentItem = lookup.items[1] + assertEquals 'iterable2', lookup.currentItem.lookupString + + type "r" + assertContains "iter", "iterable", 'iterable2' + assertEquals 'iterable2', lookup.currentItem.lookupString + + } + + public void testGenerallyFocusLookupInJavaMethod() { + myFixture.configureByText("a.java", """ + class Foo { + String foo(String iterable) { + return it; + } + } + """) + type 'e' + assertTrue lookup.focused + } + + public void testNoLookupFocusInJavaVariable() { + myFixture.configureByText("a.java", """ + class Foo { + String foo(String st) { + } + } + """) + type 'r' + assertFalse lookup.focused + } + + public void testNoStupidNameSuggestions() { + myFixture.configureByText("a.java", """ + class Foo { + String foo(String ) { + } + } + """) + type 'x' + assert !myFixture.lookupElementStrings + } + + public void testExplicitSelectionShouldBeHonoredFocused() { + myFixture.configureByText("a.java", """ + class Foo { + String foo() { + int abcd; + int abce; + a + } + } + """) + type 'b' + assert lookup.focused + type 'c' + + assertContains 'abcd', 'abce' + assertEquals 'abcd', lookup.currentItem.lookupString + lookup.currentItem = lookup.items[1] + assertEquals 'abce', lookup.currentItem.lookupString + + type '\t' + myFixture.checkResult """ + class Foo { + String foo() { + int abcd; + int abce; + abce + } + } + """ + } + + + public void testFocusInJavadoc() { + myFixture.configureByText("a.java", """ + /** + * {@link AIO} + */ + class Foo {} + """) + type 'O' + assert lookup.focused + + } + + public void testPrefixLengthDependentSorting() { + myFixture.addClass("package foo; public class PsiJavaCodeReferenceElement {}") + myFixture.configureByText("a.java", """ + import foo.PsiJavaCodeReferenceElement; + + class PsiJavaCodeReferenceElementImpl { + { } + } + """) + type 'PJCR' + assertContains 'PsiJavaCodeReferenceElement', 'PsiJavaCodeReferenceElementImpl' + + } + + public void testQuickSelectAfterReuse() { + myFixture.configureByText("a.java", """ + class A { Iterable iterable; + { } + } + """) + type 'ite' + edt { + myFixture.type 'r' + lookup.markReused() + lookup.currentItem = lookup.items[0] + CommandProcessor.instance.executeCommand project, {lookup.finishLookup Lookup.NORMAL_SELECT_CHAR}, null, null + + } + myFixture.checkResult """ + class A { Iterable iterable; + { iterable } + } + """ + } + + public void testQuickSelectAfterReuseAndBackspace() { + myFixture.configureByText("a.java", """ + class A { Iterable iterable; + { } + } + """) + type 'ite' + edt { + myFixture.type 'r' + lookup.markReused() + myFixture.type '\b\b' + lookup.currentItem = lookup.items[0] + CommandProcessor.instance.executeCommand project, ({lookup.finishLookup Lookup.NORMAL_SELECT_CHAR} as Runnable), null, null + } + myFixture.checkResult """ + class A { Iterable iterable; + { iterable } + } + """ + } + + public void testQuickSelectLiveTemplate() { + myFixture.configureByText("a.java", """ + class A { + { } + } + """) + type 'th' + edt { myFixture.type 'r\t'} + myFixture.checkResult """ + class A { + { throw new } + } + """ + } + + public void testTwoQuickRestartsAfterHiding() { + for (i in 0..10) { + myFixture.configureByText("a${i}.java", """ + class A { + { } + } + """) + edt { myFixture.type 'A' } + joinAutopopup() // completion started + boolean tooQuick = false + edt { + tooQuick = lookup == null + myFixture.type 'IO' + } + joinAutopopup() //I + joinAutopopup() //O + joinCompletion() + assert lookup + assert 'ArrayIndexOutOfBoundsException' in myFixture.lookupElementStrings + if (!tooQuick) { + return + } + edt { + LookupManager.getInstance(project).hideActiveLookup() + CompletionProgressIndicator.cleanupForNextTest() + } + } + fail "too many too quick attempts" + } + + public void testTypingDuringExplicitCompletion() { + myFixture.configureByText("a.java", """ + class A { + { Runnable r = new } + } + """) + myFixture.complete CompletionType.SMART + edt { myFixture.type 'Thr' } + joinCompletion() + assert lookup + assert 'Thread' in myFixture.lookupElementStrings + } + + public void testDotAfterVariable() { + myFixture.configureByText("a.java", """ + class A { + { Object ooo; } + } + """) + type 'o.' + assert myFixture.file.text.contains("ooo.") + assert lookup + } + + public void testDotAfterCall() { + myFixture.configureByText("a.java", """ + class A { + { } + } + """) + type 'tos.' + assert myFixture.file.text.contains("toString().") + assert lookup + } + + public void testDotAfterClassName() { + myFixture.configureByText("a.java", """ + class A { + { } + } + """) + type 'AIOO.' + assert myFixture.file.text.contains("ArrayIndexOutOfBoundsException.") + assert lookup + } + + public void testDotAfterClassNameInParameter() { + myFixture.configureByText("a.java", """ + class A { + void foo() {} + } + """) + type 'AIOO...' + assert myFixture.editor.document.text.contains("ArrayIndexOutOfBoundsException...") + assert !lookup + } + + void testArrow(boolean up, boolean cycleScrolling, boolean lookupAbove, int index) { + myFixture.configureByText("a.java", """ + class A { + { ArrayIndexOutOfBoundsException } + } + """) + + type 'ind' + assert lookup + assert !lookup.focused + assert lookup.items.size() == 2 + + lookup.positionedAbove = lookupAbove + UISettings.instance.CYCLE_SCROLLING = cycleScrolling + + def action = up ? IdeActions.ACTION_EDITOR_MOVE_CARET_UP : IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN + try { + edt { myFixture.performEditorAction(action) } + if (lookup) { + assert lookup.focused + assert index >= 0 + assert lookup.items[index] == lookup.currentItem + edt { lookup.hide() } + } else { + assert index == -1 + } + type '\b' + } + finally { + UISettings.instance.CYCLE_SCROLLING = true + } + + } + + void testArrows(boolean cycleScrolling, boolean lookupAbove, int indexDown, int indexUp) { + testArrow true, cycleScrolling, lookupAbove, indexUp + testArrow false, cycleScrolling, lookupAbove, indexDown + } + + public void testVerticalArrows() { + testArrows false, false, 0, -1 + testArrows false, true, 0, -1 + testArrows true, false, 0, 1 + testArrows true, true, 0, 1 + } + + public void testHideOnOnePrefixVariant() { + myFixture.configureByText("a.java", """ + class A { + Object foo() { return nu } + } + """) + type 'll' + assert !lookup + } + + public void testResumeAfterBackspace() { + myFixture.configureByText("a.java", """ + class A { + Object foo() { this } + } + """) + type '.' + assert lookup + type 'x' + assert !lookup + type '\b' + assert !lookup + type 'c' + assert lookup + } + + public void testHideOnInvalidSymbolAfterBackspace() { + myFixture.configureByText("a.java", """ + class A { + Object foo() { this } + } + """) + type '.' + assert lookup + type 'c' + assert lookup + type '\b' + assert lookup + type 'x' + assert !lookup + } + + public void testDoubleLiteralInField() { + myFixture.configureByText "a.java", """ +public interface Test { + double FULL = 1.0 +}""" + type 'd' + assert !lookup + } + + public void testCancellingDuringCalculation() { + myFixture.configureByText "a.java", """ +class Aaaaaaa {} +public interface Test { + +}""" + edt { myFixture.type 'A' } + joinAutopopup() + def first = lookup + assert first + edt { + assert first == lookup + lookup.hide() + myFixture.type 'a' + } + joinAutopopup() + joinAutopopup() + joinAutopopup() + assert lookup != first + } + + static class LongReplacementOffsetContributor extends CompletionContributor { + @Override + void duringCompletion(CompletionInitializationContext cxt) { + Thread.sleep 500 + ProgressManager.checkCanceled() + cxt.replacementOffset--; + } + } + + static class LongContributor extends CompletionContributor { + + @Override + void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) { + result.runRemainingContributors(parameters, true) + Thread.sleep 1000 + } + } + + public void testDuringCompletionMustFinish() { + registerContributor(LongReplacementOffsetContributor) + + edt { myFixture.addFileToProject 'directory/foo.txt', '' } + myFixture.configureByText "a.java", 'public interface Test { RuntiExcexxx }' + myFixture.completeBasic() + while (!lookup.items) { + Thread.sleep(10) + edt { lookup.refreshUi(false, false) } + } + edt { myFixture.type '\t' } + myFixture.checkResult 'public interface Test { RuntimeExceptionx }' + } + + private def registerContributor(final Class contributor, LoadingOrder order = LoadingOrder.LAST) { + def ep = Extensions.rootArea.getExtensionPoint("com.intellij.completion.contributor") + def bean = new CompletionContributorEP(language: 'JAVA', implementationClass: contributor.name) + ep.registerExtension(bean, order) + disposeOnTearDown({ ep.unregisterExtension(bean) } as Disposable) + } + + public void testLeftRightMovements() { + myFixture.configureByText("a.java", """ + class Foo { + void foo(String iterable) { + ter x + } + } + """) + type('i') + def offset = myFixture.editor.caretModel.offset + assertContains "if", "iterable", "int" + + edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT) } + assert myFixture.editor.caretModel.offset == offset + 1 + assertContains "iterable" + assertEquals 'iterable', lookup.currentItem.lookupString + + edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT) } + assert myFixture.editor.caretModel.offset == offset + assertContains "if", "iterable", "int" + assertEquals 'iterable', lookup.currentItem.lookupString + + edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT) } + joinAutopopup() + joinCompletion() + assert lookup.items.size() > 3 + + for (i in 0.."iter".size()) { + edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT) } + } + assert !lookup + } + + public void testTypingInAnotherEditor() { + myFixture.configureByText("a.java", "") + type 'c' + assert lookup + + Editor another = null + def wca = new WriteCommandAction.Simple(getProject(), new PsiFile[0]) { + @Override + protected void run() { + EditorActionManager.instance.getTypedAction().handler.execute(another, (char) 'x', DataManager.instance.dataContext) + } + } + + try { + edt { + assert !lookup.calculating + lookup.hide() + def file = myFixture.addFileToProject("b.java", "") + another = EditorFactory.instance.createEditor(file.viewProvider.document, project) + wca.execute() + assert 'x' == another.document.text + } + joinAutopopup() + joinCompletion() + LookupImpl l1 = LookupManager.getActiveLookup(another) + if (l1) { + printThreadDump() + println l1.items + println l1.calculating + println myFixture.editor + println another + println CompletionServiceImpl.completionPhase + assert false : l1.items + } + type 'l' + assert lookup + } + finally { + edt { EditorFactory.instance.releaseEditor(another) } + } + + } + + public void testExplicitCompletionOnEmptyAutopopup() { + myFixture.configureByText("a.java", "") + type 'cccccc' + myFixture.completeBasic() + joinCompletion() + assert !lookup + } + + public void testNoSingleTemplateLookup() { + myFixture.configureByText 'a.java', 'class Foo {{ ite }}' + type 'r' + assert !lookup + } + + public void testTemplatesWithNonImportedClasses() { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE + myFixture.addClass("package foo.bar; public class ToArray {}") + try { + myFixture.configureByText 'a.java', 'class Foo {{ foo() }}' + type 'toar' + assert lookup + assert 'toar' in myFixture.lookupElementStrings + assert 'ToArray' in myFixture.lookupElementStrings + } + finally { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER + } + } + + public void testTemplateSelectionByComma() { + myFixture.configureByText("a.java", """ +class Foo { + int itea = 2; + int itera = 2; + + { + it + } +} +""") + type 'e' + assertContains "itea", "itera" + type 'r' + assertContains "iter", "itera" + type ',' + assert !lookup + assert myFixture.editor.document.text.contains('itera,') + } + + public void testTemplateSelectionBySpace() { + myFixture.configureByText("a.java", """ +class Foo { + int ITER = 2; + int itea = 2; + + { + it + } +} +""") + type 'er ' + assert myFixture.editor.document.text.contains('iter ') + } + + public void testNewClassParenthesis() { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE + try { + myFixture.configureByText("a.java", """ class Foo { { new } } """) + type 'aioo(' + assert myFixture.editor.document.text.contains('new ArrayIndexOutOfBoundsException()') + } + finally { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER + } + } + + public void testUnknownMethodParenthesis() { + myFixture.configureByText("a.java", """ class Foo { { } } """) + type 'filinpstr(' + assert myFixture.editor.document.text.contains('filinpstr()') + } + + public void testNoAutopopupAfterSpace() { + myFixture.configureByText("a.java", """ class Foo { { int newa; } } """) + edt { myFixture.type('new ') } + joinAutopopup() + joinCompletion() + assert !lookup + } + + public void testRestartAndTypingDuringCopyCommit() { + registerContributor(LongReplacementOffsetContributor) + + myFixture.configureByText("a.java", """ class Foo { { int newa; } } """) + myFixture.type 'n' + joinAutopopup() + myFixture.type 'e' + joinCommit() // original commit + myFixture.type 'w' + joinAutopopup() + joinCompletion() + myFixture.type '\n' + myFixture.checkResult(" class Foo { { int newa; new } } ") + assert !lookup + } + + public void testAutoRestartAndTypingDuringCopyCommit() { + registerContributor(LongReplacementOffsetContributor) + + myFixture.configureByText("a.java", """ class Foo { { int iteraaa; } } """) + type 'ite' + assert !('iter' in myFixture.lookupElementStrings) + myFixture.type 'r' + joinCommit() + myFixture.type 'a' + joinAutopopup() + joinCompletion() + myFixture.type '\n' + myFixture.checkResult(" class Foo { { int iteraaa; iteraaa } } ") + assert !lookup + } + + public void testChoosingItemDuringCopyCommit() { + registerContributor(LongReplacementOffsetContributor) + + myFixture.configureByText("a.java", """ class Foo { { int iteraaa; } } """) + type 'ite' + assert !('iter' in myFixture.lookupElementStrings) + assert 'iteraaa' in myFixture.lookupElementStrings + myFixture.type 'r' + joinCommit() + myFixture.type 'a.' + myFixture.checkResult(" class Foo { { int iteraaa; iteraaa. } } ") + } + + public void testRestartWithInvisibleLookup() { + registerContributor(LongReplacementOffsetContributor) + + myFixture.configureByText("a.java", """ class Foo { { int abcdef; } } """) + myFixture.type 'a' + joinAutopopup() + assert lookup + edt { myFixture.type 'bc' } + joinAutopopup() + joinAutopopup() + joinCompletion() + assert lookup + assert lookup.shown + } + + public void testRestartWithVisibleLookup() { + registerContributor(LongContributor, LoadingOrder.FIRST) + + myFixture.configureByText("a.java", """ class Foo { { int abcdef; a } } """) + myFixture.completeBasic() + while (!lookup.shown) { + Thread.sleep(1) + } + def l = lookup + edt { + assert lookup.calculating + myFixture.type 'b' + } + joinCommit { + myFixture.type 'c' + } + joinAutopopup() + joinCompletion() + assert lookup == l + assert !lookup.calculating + assert lookup.shown + } + + private void joinSomething(int degree) { + if (degree == 0) return + joinAlarm() + if (degree == 1) return + joinCommit() + if (degree == 2) return + joinCommit() + if (degree == 3) return + edt {} + if (degree == 4) return + joinCompletion() + } + + public void testEveryPossibleWayToTypeIf() { + def src = "class Foo { { int ifa; } }" + def result = "class Foo { { int ifa; if } }" + int actions = 5 + + for (a1 in 0..actions) { + println "a1 = $a1" + for (a2 in 0..actions) { + myFixture.configureByText("$a1 $a2 .java", src) + myFixture.type 'i' + joinSomething(a1) + myFixture.type 'f' + joinSomething(a2) + myFixture.type ' ' + + joinAutopopup() + joinCompletion() + myFixture.checkResult(result) + assert !lookup + } + } + + for (a1 in 0..actions) { + myFixture.configureByText("$a1 if .java", src) + edt { myFixture.type 'if' } + joinSomething(a1) + + myFixture.type ' ' + + joinAutopopup() + joinCompletion() + myFixture.checkResult(result) + assert !lookup + } + + for (a1 in 0..actions) { + myFixture.configureByText("$a1 if .java", src) + myFixture.type 'i' + joinSomething(a1) + + edt { myFixture.type 'f ' } + + joinAutopopup() + joinCompletion() + myFixture.checkResult(result) + assert !lookup + } + + } + + public void testNonFinishedParameterComma() { + myFixture.configureByText("a.java", """ class Foo { void foo(int aaa, int aaaaa) { foo() } } """) + type 'a,' + assert myFixture.editor.document.text.contains('foo(aaa, )') + } + + public void testFinishedParameterComma() { + myFixture.configureByText("a.java", """ class Foo { void foo(int aaa, int aaaaa) { foo() } } """) + type 'aaa,' + assert myFixture.editor.document.text.contains('foo(aaa,)') + } + + public void testNonFinishedVariableEq() { + myFixture.configureByText("a.java", """ class Foo { void foo(int aaa, int aaaaa) { } } """) + type 'a=' + assert myFixture.editor.document.text.contains('aaa = ') + } + + public void testFinishedVariableEq() { + myFixture.configureByText("a.java", """ class Foo { void foo(int aaa, int aaaaa) { } } """) + type 'aaa=' + assert myFixture.editor.document.text.contains('aaa=') + } + + public void testCompletionWhenLiveTemplateAreNotSufficient() { + ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(true); + try { + myFixture.configureByText("a.java", """ + class Foo { + { + Iterable l1 = null; + Iterable l2 = null; + Object asdf = null; + iter + } + } + """) + type '\t' + assert myFixture.lookupElementStrings == ['l2', 'l1'] + type 'as' + assert lookup + assertContains 'asdf', 'assert' + type '\n.' + assert lookup + assert 'hashCode' in myFixture.lookupElementStrings + assert myFixture.file.text.contains('asdf.') + } + finally { + ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(false); + } + + } + + public void testNoWordCompletionAutoPopup() { + myFixture.configureByText "a.java", 'class Bar { void foo() { "f" }}' + type 'o' + assert !lookup + } + + public void testMethodNameRestart() { + myFixture.configureByText "a.java", ''' +public class Bar { + private static List getS + +} +''' + type 'ta' + assert !lookup + } + + public void testTargetElementInLookup() { + myFixture.configureByText 'a.java', ''' +class Foo { + void x__foo() {} + void bar() { + + } + void x__goo() {} +} +''' + def cls = ((PsiJavaFile)myFixture.file).getClasses()[0] + def foo = cls.methods[0] + def goo = cls.methods[2] + type('x') + assertContains 'x__foo', 'x__goo' + edt { + assert foo == TargetElementUtil.instance.findTargetElement(myFixture.editor, TargetElementUtil.LOOKUP_ITEM_ACCEPTED) + myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN) + assert goo == TargetElementUtil.instance.findTargetElement(myFixture.editor, TargetElementUtil.LOOKUP_ITEM_ACCEPTED) + } + + type('_') + assertContains 'x__foo', 'x__goo' + edt { + assert goo == TargetElementUtil.instance.findTargetElement(myFixture.editor, TargetElementUtil.LOOKUP_ITEM_ACCEPTED) + myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP) + assert foo == TargetElementUtil.instance.findTargetElement(myFixture.editor, TargetElementUtil.LOOKUP_ITEM_ACCEPTED) + } + } + + public void testExplicitAutocompletionAfterAutoPopup() { + myFixture.configureByText 'a.java', 'class Foo ' + type 'ext' + + CompletionAutoPopupHandler.ourTestingAutopopup = false + edt { + myFixture.completeBasic() + } + myFixture.checkResult 'class Foo extends ' + } + + public void testExplicitMultipleVariantCompletionAfterAutoPopup() { + myFixture.configureByText 'a.java', 'class Foo {}' + type 'pr' + + CompletionAutoPopupHandler.ourTestingAutopopup = false + edt { + myFixture.completeBasic() + } + myFixture.checkResult 'class Foo {pr}' + + ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override + void run() { + getLookup().items.each { + getLookup().list.cellRenderer.getListCellRendererComponent(getLookup().list, it, 0, false, false) + } + } + }); + assert myFixture.lookupElementStrings.containsAll(['private', 'protected']) + } + + public void testArrays() { + myFixture.configureByText "a.java", "class Foo {{ }}" + type 'Arrays.' + myFixture.checkResult "class Foo {{ Arrays. }}" + assert 'Arrays.asList' in myFixture.lookupElementStrings + } + + + public void testExactMatchesFirst() { + myFixture.configureByText("a.java", """ +public class UTest { + void nextWord() {} + + void foo() { + n + } +}""") + type 'ew' + assert myFixture.lookupElementStrings == ['new', 'nextWord'] + } + + public void testUpdatePrefixMatchingOnTyping() { + myFixture.addClass("class CertificateEncodingException {}") + myFixture.addClass("class CertificateException {}") + myFixture.configureByText 'a.java', 'class Foo {}' + type 'CertificateExce' + assert myFixture.lookupElementStrings == ['CertificateException', 'CertificateEncodingException'] + } + + public void testNoClassesInUnqualifiedImports() { + myFixture.addClass("package xxxxx; public class Xxxxxxxxx {}") + myFixture.configureByText 'a.java', 'package foo; import ' + type 'xxx' + assert !lookup + } + + public void testPopupAfterDotAfterPackage() { + myFixture.configureByText 'a.java', '' + type 'import jav' + assert lookup + type '.' + assert lookup + } + + public void testSamePrefixIgnoreCase() { + myFixture.addClass("package xxxxx; public class SYSTEM_EXCEPTION {}") + myFixture.configureByText "a.java", "import xxxxx.*; class Foo { S }" + type 'Ystem' + assert 'java.lang.System' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[0]).qualifiedName + assert 'xxxxx.SYSTEM_EXCEPTION' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[1]).qualifiedName + } + + public void testSamePrefixIgnoreCase2() { + myFixture.addClass("package xxxxx; public class SYSTEM_EXCEPTION {}") + myFixture.addClass("package xxxxx; public class SYstem {}") + myFixture.configureByText "a.java", "import xxxxx.*; class Foo { S }" + type 'Ystem' + assert 'xxxxx.SYstem' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[0]).qualifiedName + assert 'java.lang.System' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[1]).qualifiedName + assert 'xxxxx.SYSTEM_EXCEPTION' == ((JavaPsiClassReferenceElement) myFixture.lookupElements[2]).qualifiedName + } + + private FileEditor openEditorForUndo() { + FileEditor editor; + edt { editor = FileEditorManager.getInstance(project).openFile(myFixture.file.virtualFile, false)[0] } + def manager = (UndoManagerImpl) UndoManager.getInstance(project) + def old = manager.editorProvider + manager.editorProvider = new CurrentEditorProvider() { + @Override + public FileEditor getCurrentEditor() { + return editor; + } + }; + disposeOnTearDown ({ manager.editorProvider = old } as Disposable) + return editor + } + + public void _testCharSelectionUndo() { + myFixture.configureByText "a.java", "class Foo {{ }}" + def editor = openEditorForUndo(); + type('ArrStoExce.') + edt { UndoManager.getInstance(project).undo(editor) } + assert myFixture.editor.document.text.contains('ArrStoExce.') + } + + public void testAutopopupTypingUndo() { + myFixture.configureByText "a.java", "class Foo {{ }}" + def editor = openEditorForUndo(); + type 'aioobeeee' + edt { UndoManager.getInstance(project).undo(editor) } + assert !myFixture.editor.document.text.contains('aioo') + } + + public void testNoLiveTemplatesAfterDot() { + myFixture.configureByText "a.java", "class Foo {{ Iterable t; t. }}" + type 'iter' + 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 {{ }}" + type 'Foo239 ' + assert myFixture.file.text.contains('Foo239 ') + + myFixture.configureByText "a.java", "class Foo {{ }}" + type 'Foo239' + edt { myFixture.performEditorAction IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN } + type ' ' + assert myFixture.file.text.contains('Foo239Util2 ') + + myFixture.configureByText "a.java", "class Foo {{ }}" + type 'new Foo239(' + assert myFixture.file.text.contains('new Foo239()') + } + + public void testTypingFirstVarargDot() { + myFixture.configureByText "a.java", "class Foo { void foo(Foo[] a) { }; class Bar {}}" + type '.' + assert !lookup + } + + public void testBlockSelection() { + doTestBlockSelection """ +class Foo {{ + tx; + tx; +}}""", '\n', ''' +class Foo {{ + toString()x; + toString()x; +}}''' + } + + public void testBlockSelectionTab() { + doTestBlockSelection """ +class Foo {{ + tx; + tx; +}}""", '\t', ''' +class Foo {{ + toString(); + toString(); +}}''' + } + + public void testBlockSelectionBackspace() { + doTestBlockSelection """ +class Foo {{ + t; + t; +}}""", '\b\t', ''' +class Foo {{ + toString(); + toString(); +}}''' + } + + private doTestBlockSelection(final String textBefore, final String toType, final String textAfter) { + myFixture.configureByText "a.java", textBefore + edt { + def caret = myFixture.editor.offsetToLogicalPosition(myFixture.editor.caretModel.offset) + myFixture.editor.selectionModel.setBlockSelection(caret, new LogicalPosition(caret.line + 1, caret.column + 1)) + } + type 'toStr' + assert lookup + type toType + myFixture.checkResult textAfter + def start = myFixture.editor.selectionModel.blockStart + def end = myFixture.editor.selectionModel.blockEnd + assert start.line == end.line - 1 + assert start.column == end.column + assert end == myFixture.editor.caretModel.logicalPosition + } + + public void testNonImportedClass() { + myFixture.addClass("package foo; public class Abcdefg {}") + myFixture.configureByText 'a.java', 'class Foo extends ' + type 'Abcde ' + myFixture.checkResult 'import foo.Abcdefg;\n\nclass Foo extends Abcdefg ' + } + + public void testTwoNonImportedClasses() { + myFixture.addClass("package foo; public class Abcdefg {}") + myFixture.addClass("package bar; public class Abcdefg {}") + myFixture.configureByText 'a.java', 'class Foo extends ' + type 'Abcde ' + myFixture.checkResult 'class Foo extends Abcdefg ' + } + + public void testClassNameInProperties() { + myFixture.addClass("package java.langa; public class Abcdefg {}") + myFixture.configureByText 'a.properties', 'key.11=java' + type '.' + assert lookup + type 'lang' + assert myFixture.lookupElementStrings.size() >= 2 + type '.' + assert lookup + edt { myFixture.editor.caretModel.moveToOffset(myFixture.editor.document.text.indexOf('lang')) } + assert !lookup + type 'i' + assert 'io' in myFixture.lookupElementStrings + } + + public void testEnteringLabel() { + myFixture.configureByText 'a.java', '''class Foo {{ + +}} +''' + type 'FIS:' + assert myFixture.file.text.contains('FIS:') + } + + public void testSoutvTemplate() { + ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(true); + try { + myFixture.configureByText 'a.java', 'class Foo {{ }}' + type 'soutv\tgetcl.' + myFixture.checkResult '''class Foo {{ + System.out.println("getClass(). = " + getClass().); }}''' + } + finally { + ((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(false); + } + } + + public void testReturnLParen() { + myFixture.configureByText 'a.java', 'class Foo { int foo() { }}' + type 're(' + myFixture.checkResult 'class Foo { int foo() { re() }}' + } + + public void testAmbiguousClassQualifier() { + myFixture.addClass("package foo; public class Util { public static void foo() {} }") + myFixture.addClass("package bar; public class Util { public static void bar() {} }") + myFixture.configureByText 'a.java', 'class Foo {{ }}' + type 'Util.' + assert myFixture.lookupElementStrings == ['Util.bar', 'Util.foo'] + type 'fo\n' + myFixture.checkResult '''import foo.Util; + +class Foo {{ + Util.foo(); }}''' + } + + public void testPackageQualifier() { + myFixture.addClass("package com.too; public class Util {}") + myFixture.configureByText 'a.java', 'class Foo { void foo(Object command) { }}' + type 'com.t' + assert myFixture.lookupElementStrings.containsAll(['too', 'command.toString']) + } + + public void testUnfinishedString() { + myFixture.configureByText 'a.java', ''' +// Date +class Foo { + String s = " + String s2 = s; +} +''' + type 'D' + assert !lookup + } + + public void testVarargParenthesis() { + myFixture.configureByText 'a.java', ''' +class Foo { + void foo(File... files) { } + { foo(new ) } +} +''' + type 'File(' + assert myFixture.file.text.contains('new File()') + } + + public void "test inaccessible class in another package shouldn't prevent choosing by space"() { + myFixture.addClass("package foo; class b {}") + myFixture.configureByText 'a.java', 'class Foo {{ }}' + type 'b' + assert lookup?.currentItem?.lookupString == 'boolean' + type ' ' + myFixture.checkResult 'class Foo {{ boolean }}' + } + + @Override + protected void tearDown() { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER + super.tearDown() + } + + public void testBackspaceShouldShowPreviousVariants() { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE + myFixture.addClass("class OuterX { static class TrueLine {} }") + myFixture.configureByText 'a.java', 'class Foo{ void foo(int truex) { return tr }}' + type 'ue' + assert myFixture.lookupElementStrings == ['true', 'truex'] + type 'l' + assert myFixture.lookupElementStrings == ['TrueLine'] + type '\b' + assert myFixture.lookupElementStrings == ['true', 'truex'] + } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java index 45c4ccc6bfb8..1f16310242b1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java @@ -1,232 +1,232 @@ -package com.intellij.codeInsight.completion; - -import com.intellij.JavaTestUtil; -import com.intellij.codeInsight.CodeInsightSettings; -import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection; -import com.intellij.lang.StdLanguages; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiReferenceBase; -import com.intellij.psi.PsiReferenceProvider; -import com.intellij.psi.codeStyle.CodeStyleSettingsManager; -import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl; -import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry; -import com.intellij.psi.javadoc.PsiDocTag; -import com.intellij.util.ObjectUtils; -import com.intellij.util.ProcessingContext; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.List; - - -/** - * @author mike - */ -public class JavadocCompletionTest extends LightFixtureCompletionTestCase { - - @Override - protected String getBasePath() { - return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/javadoc/"; - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - myFixture.enableInspections(new JavaDocLocalInspection()); - } - - public void testNamesInClass() throws Exception { - configureByFile("ClassTagName.java"); - assertStringItems("author", "deprecated", "param", "see", "serial", "since", "version"); - } - - public void testNamesInField() throws Exception { - configureByFile("FieldTagName.java"); - assertStringItems("deprecated", "see", "serial", "serialField", "since"); - } - - public void testNamesInMethod0() throws Exception { - configureByFile("MethodTagName0.java"); - assertStringItems("deprecated", "exception", "param", "return", "see", "serialData", "since", "throws"); - } - - public void testNamesInMethod1() throws Exception { - configureByFile("MethodTagName1.java"); - assertStringItems("see", "serialData", "since"); - } - - public void testParamValueCompletion() throws Exception { - configureByFile("ParamValue0.java"); - assertStringItems("a", "b", "c"); - } - - public void testParamValueWithPrefixCompletion() throws Exception { - configureByFile("ParamValue1.java"); - assertStringItems("a1", "a2", "a3"); - } - - public void testDescribedParameters() throws Exception { - configureByFile("ParamValue2.java"); - assertStringItems("a2", "a3"); - } - - public void testSee0() throws Exception { - configureByFile("See0.java"); - assertStringItems("foo", "clone", "equals", "getClass", "hashCode", "notify", "notifyAll", "Object", "toString", "wait", "wait", "wait", "finalize", "registerNatives"); - } - - public void testSee1() throws Exception { - configureByFile("See1.java"); - assertStringItems("notify", "notifyAll"); - } - - public void testSee2() throws Exception { - configureByFile("See2.java"); - assertStringItems("notify", "notifyAll"); - } - - public void testSee3() throws Exception { - configureByFile("See3.java"); - - assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myField"))); - } - - @NotNull - private List getLookupElementStrings() { - return ObjectUtils.assertNotNull(myFixture.getLookupElementStrings()); - } - - public void testSee4() throws Exception { - configureByFile("See4.java"); - - assertTrue(getLookupElementStrings().containsAll(Arrays.asList("A", "B", "C"))); - } - - public void testSee5() throws Exception { - configureByFile("See5.java"); - - assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myName"))); - } - - public void testIDEADEV10620() throws Exception { - configureByFile("IDEADEV10620.java"); - - checkResultByFile("IDEADEV10620-after.java"); - } - - public void testException0() throws Exception { - configureByFile("Exception0.java"); - assertStringItems("deprecated", "exception", "param", "see", "serialData", "since", "throws"); - } - - public void testException1() throws Exception { - configureByFile("Exception1.java"); - assertTrue(myItems.length > 18); - } - - public void testException2() throws Exception { - myFixture.configureByFile("Exception2.java"); - myFixture.complete(CompletionType.SMART); - assertStringItems("IllegalStateException", "IOException"); - } - - public void testInlineLookup() throws Exception { - configureByFile("InlineTagName.java"); - assertStringItems("code", "docRoot", "inheritDoc", "link", "linkplain", "literal", "value"); - } - - public void testFinishWithSharp() throws Throwable { - boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION; - CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false; - try { - checkFinishWithSharp(); - } - finally { - CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = old; - } - } - - private void checkFinishWithSharp() throws Exception { - myFixture.configureByFile("FinishWithSharp.java"); - myFixture.completeBasic(); - type('#'); - checkResultByFile("FinishWithSharp_after.java"); - final List items = getLookup().getItems(); - assertEquals("bar", items.get(0).getLookupString()); - assertEquals("foo", items.get(1).getLookupString()); - } - - public void testShortenClassName() throws Throwable { - CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = false; - try { - doTest(); - } - finally { - CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = true; - } - } - - public void testMethodBeforeSharp() throws Throwable { - doTest(); - } - - public void testFieldReferenceInInnerClassJavadoc() throws Throwable { - doTest(); - } - - public void testShortenClassReference() throws Throwable { doTest(); } - public void testQualifiedClassReference() throws Throwable { - configureByFile(getTestName(false) + ".java"); - myFixture.complete(CompletionType.BASIC, 2); - checkResultByFile(getTestName(false) + "_after.java"); - } - public void testThrowsNonImported() throws Throwable { - configureByFile(getTestName(false) + ".java"); - myFixture.complete(CompletionType.BASIC, 2); - checkResultByFile(getTestName(false) + "_after.java"); - } - - private void doTest() throws Exception { - configureByFile(getTestName(false) + ".java"); - checkResultByFile(getTestName(false) + "_after.java"); - } - - public void testInlinePackageReferenceCompletion() throws Exception { - configureByFile("InlineReference.java"); - assertTrue(getLookupElementStrings().containsAll(Arrays.asList("io", "lang", "util"))); - } - - public void testCustomReferenceProvider() throws Exception { - PsiReferenceRegistrarImpl registrar = - (PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA); - PsiReferenceProvider provider = new PsiReferenceProvider() { - @Override - @NotNull - public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { - return new PsiReference[]{new PsiReferenceBase(element) { - - @Override - public PsiElement resolve() { - return element; - } - - @Override - @NotNull - public Object[] getVariants() { - return new Object[]{"1", "2", "3"}; - } - }}; - } - }; - try { - registrar.registerReferenceProvider(PsiDocTag.class, provider); - configureByFile("ReferenceProvider.java"); - assertStringItems("1", "2", "3"); - } - finally { - registrar.unregisterReferenceProvider(PsiDocTag.class, provider); - } - } -} +package com.intellij.codeInsight.completion; + +import com.intellij.JavaTestUtil; +import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection; +import com.intellij.lang.StdLanguages; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReference; +import com.intellij.psi.PsiReferenceBase; +import com.intellij.psi.PsiReferenceProvider; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl; +import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry; +import com.intellij.psi.javadoc.PsiDocTag; +import com.intellij.util.ObjectUtils; +import com.intellij.util.ProcessingContext; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.List; + + +/** + * @author mike + */ +public class JavadocCompletionTest extends LightFixtureCompletionTestCase { + + @Override + protected String getBasePath() { + return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/javadoc/"; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + myFixture.enableInspections(new JavaDocLocalInspection()); + } + + public void testNamesInClass() throws Exception { + configureByFile("ClassTagName.java"); + assertStringItems("author", "deprecated", "param", "see", "serial", "since", "version"); + } + + public void testNamesInField() throws Exception { + configureByFile("FieldTagName.java"); + assertStringItems("deprecated", "see", "serial", "serialField", "since"); + } + + public void testNamesInMethod0() throws Exception { + configureByFile("MethodTagName0.java"); + assertStringItems("deprecated", "exception", "param", "return", "see", "serialData", "since", "throws"); + } + + public void testNamesInMethod1() throws Exception { + configureByFile("MethodTagName1.java"); + assertStringItems("see", "serialData", "since", "class", "throws"); + } + + public void testParamValueCompletion() throws Exception { + configureByFile("ParamValue0.java"); + assertStringItems("a", "b", "c"); + } + + public void testParamValueWithPrefixCompletion() throws Exception { + configureByFile("ParamValue1.java"); + assertStringItems("a1", "a2", "a3"); + } + + public void testDescribedParameters() throws Exception { + configureByFile("ParamValue2.java"); + assertStringItems("a2", "a3"); + } + + public void testSee0() throws Exception { + configureByFile("See0.java"); + assertStringItems("foo", "clone", "equals", "getClass", "hashCode", "notify", "notifyAll", "Object", "toString", "wait", "wait", "wait", "finalize", "registerNatives"); + } + + public void testSee1() throws Exception { + configureByFile("See1.java"); + assertStringItems("notify", "notifyAll"); + } + + public void testSee2() throws Exception { + configureByFile("See2.java"); + assertStringItems("notify", "notifyAll"); + } + + public void testSee3() throws Exception { + configureByFile("See3.java"); + + assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myField"))); + } + + @NotNull + private List getLookupElementStrings() { + return ObjectUtils.assertNotNull(myFixture.getLookupElementStrings()); + } + + public void testSee4() throws Exception { + configureByFile("See4.java"); + + assertTrue(getLookupElementStrings().containsAll(Arrays.asList("A", "B", "C"))); + } + + public void testSee5() throws Exception { + configureByFile("See5.java"); + + assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myName"))); + } + + public void testIDEADEV10620() throws Exception { + configureByFile("IDEADEV10620.java"); + + checkResultByFile("IDEADEV10620-after.java"); + } + + public void testException0() throws Exception { + configureByFile("Exception0.java"); + assertStringItems("deprecated", "exception", "param", "see", "serialData", "since", "throws"); + } + + public void testException1() throws Exception { + configureByFile("Exception1.java"); + assertTrue(myItems.length > 18); + } + + public void testException2() throws Exception { + myFixture.configureByFile("Exception2.java"); + myFixture.complete(CompletionType.SMART); + assertStringItems("IllegalStateException", "IOException"); + } + + public void testInlineLookup() throws Exception { + configureByFile("InlineTagName.java"); + assertStringItems("code", "docRoot", "inheritDoc", "link", "linkplain", "literal", "value"); + } + + public void testFinishWithSharp() throws Throwable { + boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION; + CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false; + try { + checkFinishWithSharp(); + } + finally { + CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = old; + } + } + + private void checkFinishWithSharp() throws Exception { + myFixture.configureByFile("FinishWithSharp.java"); + myFixture.completeBasic(); + type('#'); + checkResultByFile("FinishWithSharp_after.java"); + final List items = getLookup().getItems(); + assertEquals("bar", items.get(0).getLookupString()); + assertEquals("foo", items.get(1).getLookupString()); + } + + public void testShortenClassName() throws Throwable { + CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = false; + try { + doTest(); + } + finally { + CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = true; + } + } + + public void testMethodBeforeSharp() throws Throwable { + doTest(); + } + + public void testFieldReferenceInInnerClassJavadoc() throws Throwable { + doTest(); + } + + public void testShortenClassReference() throws Throwable { doTest(); } + public void testQualifiedClassReference() throws Throwable { + configureByFile(getTestName(false) + ".java"); + myFixture.complete(CompletionType.BASIC, 2); + checkResultByFile(getTestName(false) + "_after.java"); + } + public void testThrowsNonImported() throws Throwable { + configureByFile(getTestName(false) + ".java"); + myFixture.complete(CompletionType.BASIC, 2); + checkResultByFile(getTestName(false) + "_after.java"); + } + + private void doTest() throws Exception { + configureByFile(getTestName(false) + ".java"); + checkResultByFile(getTestName(false) + "_after.java"); + } + + public void testInlinePackageReferenceCompletion() throws Exception { + configureByFile("InlineReference.java"); + assertTrue(getLookupElementStrings().containsAll(Arrays.asList("io", "lang", "util"))); + } + + public void testCustomReferenceProvider() throws Exception { + PsiReferenceRegistrarImpl registrar = + (PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA); + PsiReferenceProvider provider = new PsiReferenceProvider() { + @Override + @NotNull + public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { + return new PsiReference[]{new PsiReferenceBase(element) { + + @Override + public PsiElement resolve() { + return element; + } + + @Override + @NotNull + public Object[] getVariants() { + return new Object[]{"1", "2", "3"}; + } + }}; + } + }; + try { + registrar.registerReferenceProvider(PsiDocTag.class, provider); + configureByFile("ReferenceProvider.java"); + assertStringItems("1", "2", "3"); + } + finally { + registrar.unregisterReferenceProvider(PsiDocTag.class, provider); + } + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java index 80129f0771a4..8ff29be3bdfb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java @@ -1,114 +1,123 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInsight.completion; - -import com.intellij.JavaTestUtil; -import com.intellij.psi.codeStyle.CodeStyleSettingsManager; -import org.jetbrains.annotations.NonNls; - -/** - * @author ik - * @since 20.02.2003 - */ -public class KeywordCompletionTest extends LightCompletionTestCase { - private static final String BASE_PATH = "/codeInsight/completion/keywords"; - - private static final String[] FILE_SCOPE_KEYWORDS = new String[]{ - "package", "public", "private", "import", "final", "class", "interface", "abstract", "enum", null}; - private static final String[] CLASS_SCOPE_KEYWORDS = new String[]{ - "public", "private", "protected", "import", "final", "class", "interface", "abstract", "enum", null}; - private static final String[] CLASS_SCOPE_KEYWORDS_2 = new String[]{ - "package", "public", "private", "protected", "transient", "volatile", "static", "import", "final", "class", "interface", "abstract"}; - - @Override - protected String getTestDataPath() { - return JavaTestUtil.getJavaTestDataPath(); - } - - public void testFileScope1() throws Exception { doTest(8, FILE_SCOPE_KEYWORDS); } - public void testFileScope2() throws Exception { doTest(7, CLASS_SCOPE_KEYWORDS); } - public void testClassScope1() throws Exception { doTest(5, CLASS_SCOPE_KEYWORDS); } - public void testClassScope2() throws Exception { doTest(4, CLASS_SCOPE_KEYWORDS); } - public void testClassScope3() throws Exception { doTest(0, CLASS_SCOPE_KEYWORDS); } - public void testClassScope4() throws Exception { doTest(10, CLASS_SCOPE_KEYWORDS_2); } - public void testAfterAnnotations() throws Exception { doTest(6, "public", "final", "class", "interface", "abstract", "enum", null); } - public void testExtends1() throws Exception { doTest(2, "extends", "implements", null); } - public void testExtends2() throws Exception { doTest(1, "extends", "implements", "AAA", "BBB", "instanceof"); } - public void testExtends3() throws Exception { doTest(2, "extends", "implements", "AAA", "BBB", "CCC", "instanceof"); } - public void testExtends4() throws Exception { doTest(2, "extends", "implements", "AAA", "BBB", "CCC", "instanceof"); } - public void testExtends5() throws Exception { doTest(1, "extends", "implements", "AAA", "BBB", "CCC", "instanceof"); } - public void testExtends6() throws Exception { doTest(1, "extends", "implements", "AAA", "BBB", "CCC", "instanceof"); } - public void testExtends7() throws Exception { doTest(false); } - public void testExtends8() throws Exception { doTest(false); } - public void testExtends9() throws Exception { doTest(false); } - public void testExtends10() throws Exception { doTest(false); } - public void testExtends11() throws Exception { doTest(false); } - public void testExtends12() throws Exception { doTest(false); } - public void testSynchronized1() throws Exception { doTest(false); } - - public void testSynchronized2() throws Exception { - CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_SYNCHRONIZED_PARENTHESES = false; - doTest(false); - } - - public void testMethodScope1() throws Exception { doTest(1, "throws"); } - public void testMethodScope2() throws Exception { doTest(1, "final", "public", "static", "volatile", "abstract"); } - public void testMethodScope3() throws Exception { doTest(1, "final", "public", "static", "volatile", "abstract", "throws", "instanceof"); } - public void testMethodScope4() throws Exception { doTest(6, "final", "try", "for", "while", "return", "throw"); } - public void testMethodScope5() throws Exception { doTest(false); } - public void testExtraBracketAfterFinally1() throws Exception { doTest(true); } - public void testExtraBracketAfterFinally2() throws Exception { doTest(true); } - public void testExtendsInCastTypeParameters() throws Exception { doTest(false); } - public void testExtendsWithRightContextInClassTypeParameters() throws Exception { doTest(false); } - public void testTrueInVariableDeclaration() throws Exception { doTest(false); } - public void testNullInIf() throws Exception { doTest(false); } - public void testNullInReturn() throws Exception { doTest(false); } - public void testExtendsInMethodParameters() throws Exception { doTest(false); } - public void testInstanceOf1() throws Exception { doTest(false); } - public void testInstanceOf2() throws Exception { doTest(false); } - public void testInstanceOf3() throws Exception { doTest(false); } - public void testCatchFinally() throws Exception { doTest(2, "catch", "finally"); } - public void testSuper1() throws Exception { doTest(1, "super"); } - public void testSuper2() throws Exception { doTest(0, "super"); } - public void testContinue() throws Exception { doTest(false); } - public void testThrowsOnSeparateLine() throws Exception { doTest(false); } - public void testDefaultInAnno() throws Exception { doTest(false); } - public void testDefaultInExtMethod() throws Exception { doTest(false); } - public void testNullInMethodCall() throws Exception { doTest(false); } - public void testNullInMethodCall2() throws Exception { doTest(false); } - public void testNewInMethodRefs() throws Exception { doTest(false); } - public void testAbstractInInterface() throws Exception { doTest(1, "abstract"); } - public void testCharInAnnotatedParameter() throws Exception { doTest(1, "char"); } - public void testReturnInTernary() throws Exception { doTest(1, "return"); } - - public void testTryInExpression() throws Exception { - configureByFile(BASE_PATH + "/" + getTestName(true) + ".java"); - assertStringItems("toString", "this"); - } - - private void doTest(boolean select) throws Exception { - configureByFile(BASE_PATH + "/" + getTestName(true) + ".java"); - if (select) { - selectItem(myItems[1]); - } - checkResultByFile(BASE_PATH + "/" + getTestName(true) + "_after.java"); - } - - protected void doTest(int finalCount, @NonNls String... values) { - configureByFile(BASE_PATH + "/" + getTestName(true) + ".java"); - testByCount(finalCount, values); - } +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.completion; + +import com.intellij.JavaTestUtil; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import org.jetbrains.annotations.NonNls; + +/** + * @author ik + * @since 20.02.2003 + */ +public class KeywordCompletionTest extends LightCompletionTestCase { + private static final String BASE_PATH = "/codeInsight/completion/keywords"; + + private static final String[] FILE_SCOPE_KEYWORDS = new String[]{ + "package", "public", "private", "import", "final", "class", "interface", "abstract", "enum", null}; + private static final String[] CLASS_SCOPE_KEYWORDS = new String[]{ + "public", "private", "protected", "import", "final", "class", "interface", "abstract", "enum", null}; + private static final String[] CLASS_SCOPE_KEYWORDS_2 = new String[]{ + "package", "public", "private", "protected", "transient", "volatile", "static", "import", "final", "class", "interface", "abstract"}; + + @Override + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath(); + } + + public void testFileScope1() throws Exception { doTest(8, FILE_SCOPE_KEYWORDS); } + public void testFileScope2() throws Exception { doTest(7, CLASS_SCOPE_KEYWORDS); } + public void testClassScope1() throws Exception { doTest(5, CLASS_SCOPE_KEYWORDS); } + public void testClassScope2() throws Exception { doTest(4, CLASS_SCOPE_KEYWORDS); } + public void testClassScope3() throws Exception { doTest(0, CLASS_SCOPE_KEYWORDS); } + public void testClassScope4() throws Exception { doTest(10, CLASS_SCOPE_KEYWORDS_2); } + public void testAfterAnnotations() throws Exception { doTest(6, "public", "final", "class", "interface", "abstract", "enum", null); } + public void testExtends1() throws Exception { doTest(2, "extends", "implements", null); } + public void testExtends2() throws Exception { doTest(1, "extends", "implements", "AAA", "BBB", "instanceof"); } + public void testExtends3() throws Exception { doTest(2, "extends", "implements", "AAA", "BBB", "CCC", "instanceof"); } + public void testExtends4() throws Exception { doTest(2, "extends", "implements", "AAA", "BBB", "CCC", "instanceof"); } + public void testExtends5() throws Exception { doTest(1, "extends", "implements", "AAA", "BBB", "CCC", "instanceof"); } + public void testExtends6() throws Exception { doTest(1, "extends", "implements", "AAA", "BBB", "CCC", "instanceof"); } + public void testExtends7() throws Exception { doTest(false); } + public void testExtends8() throws Exception { doTest(false); } + public void testExtends9() throws Exception { doTest(false); } + public void testExtends10() throws Exception { doTest(false); } + public void testExtends11() throws Exception { doTest(false); } + public void testExtends12() throws Exception { doTest(false); } + public void testSynchronized1() throws Exception { doTest(false); } + + public void testSynchronized2() throws Exception { + CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_SYNCHRONIZED_PARENTHESES = false; + doTest(false); + } + + public void testMethodScope1() throws Exception { doTest(1, "throws"); } + public void testMethodScope2() throws Exception { doTest(1, "final", "public", "static", "volatile", "abstract"); } + public void testMethodScope3() throws Exception { doTest(1, "final", "public", "static", "volatile", "abstract", "throws", "instanceof"); } + public void testMethodScope4() throws Exception { doTest(6, "final", "try", "for", "while", "return", "throw"); } + public void testMethodScope5() throws Exception { doTest(true); } + public void testExtraBracketAfterFinally1() throws Exception { + configureByFile(BASE_PATH + "/" + getTestName(true) + ".java"); + selectItem(myItems[1]); + checkResultByFile(BASE_PATH + "/" + getTestName(true) + "_after.java"); + } + public void testExtraBracketAfterFinally2() throws Exception { + configureByFile(BASE_PATH + "/" + getTestName(true) + ".java"); + selectItem(myItems[1]); + checkResultByFile(BASE_PATH + "/" + getTestName(true) + "_after.java"); + } + public void testExtendsInCastTypeParameters() throws Exception { doTest(false); } + public void testExtendsWithRightContextInClassTypeParameters() throws Exception { doTest(false); } + public void testTrueInVariableDeclaration() throws Exception { doTest(true); } + public void testNullInIf() throws Exception { doTest(true); } + public void testNullInReturn() throws Exception { doTest(true); } + public void testExtendsInMethodParameters() throws Exception { doTest(false); } + public void testInstanceOf1() throws Exception { doTest(true); } + public void testInstanceOf2() throws Exception { doTest(false); } + public void testInstanceOf3() throws Exception { doTest(true); } + public void testCatchFinally() throws Exception { doTest(2, "catch", "finally"); } + public void testSuper1() throws Exception { doTest(1, "super"); } + public void testSuper2() throws Exception { doTest(0, "super"); } + public void testContinue() throws Exception { doTest(false); } + public void testThrowsOnSeparateLine() throws Exception { doTest(true); } + public void testDefaultInAnno() throws Exception { doTest(false); } + public void testDefaultInExtMethod() throws Exception { doTest(false); } + public void testNullInMethodCall() throws Exception { doTest(true); } + public void testNullInMethodCall2() throws Exception { doTest(false); } + public void testNewInMethodRefs() throws Exception { doTest(false); } + public void testAbstractInInterface() throws Exception { doTest(1, "abstract"); } + public void testCharInAnnotatedParameter() throws Exception { doTest(1, "char"); } + public void testReturnInTernary() throws Exception { doTest(1, "return"); } + + public void testTryInExpression() throws Exception { + configureByFile(BASE_PATH + "/" + getTestName(true) + ".java"); + assertEquals("toString", myItems[0].getLookupString()); + assertEquals("this", myItems[1].getLookupString()); + } + + private void doTest(boolean select) throws Exception { + configureByFile(BASE_PATH + "/" + getTestName(true) + ".java"); + if (select) { + selectItem(myItems[0]); + } + checkResultByFile(BASE_PATH + "/" + getTestName(true) + "_after.java"); + } + + protected void doTest(int finalCount, @NonNls String... values) { + configureByFile(BASE_PATH + "/" + getTestName(true) + ".java"); + testByCount(finalCount, values); + } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index ca8dce67f8e3..546bfe7e17d7 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -1,1355 +1,1362 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInsight.completion; - - -import com.intellij.JavaTestUtil -import com.intellij.codeInsight.CodeInsightSettings -import com.intellij.codeInsight.lookup.Lookup -import com.intellij.codeInsight.lookup.LookupElement -import com.intellij.codeInsight.lookup.LookupElementPresentation -import com.intellij.codeInsight.lookup.LookupManager -import com.intellij.lang.java.JavaLanguage -import com.intellij.openapi.actionSystem.IdeActions -import com.intellij.openapi.fileTypes.StdFileTypes -import com.intellij.psi.codeStyle.CodeStyleSettingsManager -import com.intellij.psi.codeStyle.CommonCodeStyleSettings -import com.intellij.psi.* - -public class NormalCompletionTest extends LightFixtureCompletionTestCase { - @Override - protected String getBasePath() { - return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/normal/"; - } - - public void testSimple() throws Exception { - configureByFile("Simple.java"); - assertStringItems("_local1", "_local2", "_field", "_method", "_baseField", "_baseMethod"); - } - - public void testDontCompleteFieldsAndMethodsInReferenceCodeFragment() throws Throwable { - final String text = CommonClassNames.JAVA_LANG_OBJECT + "."; - PsiFile file = JavaCodeFragmentFactory.getInstance(project).createReferenceCodeFragment(text, null, true, true); - myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); - complete(); - myFixture.checkResult(text); - assertEmpty(myItems); - } - - public void testNoPackagesInExpressionCodeFragment() throws Throwable { - final String text = "jav"; - PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment(text, null, null, true); - myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); - complete(); - myFixture.checkResult(text); - assertEmpty(myItems); - } - - public void testSubPackagesInExpressionCodeFragment() throws Throwable { - PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment("java.la", null, null, true); - myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); - complete(); - myFixture.checkResult("java.lang."); - assertNull(myItems); - } - - public void testPrimitivesInTypeCodeFragmentWithParameterListContext() throws Throwable { - def clazz = myFixture.addClass("class Foo { void foo(int a) {} }") - - PsiFile file = JavaCodeFragmentFactory.getInstance(project).createTypeCodeFragment("b", clazz.methods[0].parameterList, true); - myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); - complete(); - assertStringItems('boolean', 'byte') - } - - public void testQualifierCastingInExpressionCodeFragment() throws Throwable { - final ctxText = "class Bar {{ Object o; o=null }}" - final ctxFile = createLightFile(StdFileTypes.JAVA, ctxText) - final context = ctxFile.findElementAt(ctxText.indexOf("o=")) - assert context - - PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment("o instanceof String && o.subst", context, null, true); - myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); - complete(); - myFixture.checkResult("o instanceof String && ((String) o).substring()"); - assertNull(myItems); - } - - public void testCastToPrimitive1() throws Exception { - configureByFile("CastToPrimitive1.java"); - - for (final LookupElement item : myItems) { - if (item.getLookupString().equals("int")) return; - } - assertTrue(false); - } - - public void testCastToPrimitive2() throws Exception { - configureByFile("CastToPrimitive2.java"); - - for (final LookupElement item : myItems) { - if (item.getLookupString().equals("int")) return; - } - assertTrue(false); - } - - public void testCastToPrimitive3() throws Exception { - configureByFile("CastToPrimitive3.java"); - - for (final LookupElement item : myItems) { - if (item.getLookupString().equals("int")) return; - } - assertTrue(false); - } - - public void testWriteInInvokeLater() throws Exception { - configureByFile("WriteInInvokeLater.java"); - } - - public void testQualifiedNew1() throws Exception { - configure() - assertStringItems "IInner", "Inner" - } - - public void testQualifiedNew2() throws Exception { - configure() - assertStringItems "AnInner", "Inner" - } - - public void testKeywordsInName() throws Exception { - doTest 'a\n' - } - - public void testSimpleVariable() throws Exception { doTest() } - - public void testMethodItemPresentation() { - configure() - LookupElementPresentation presentation = renderElement(myItems[0]) - assert "equals" == presentation.itemText - assert "(Object anObject)" == presentation.tailText - assert "boolean" == presentation.typeText - - assert !presentation.tailGrayed - assert presentation.itemTextBold - } - - private LookupElementPresentation renderElement(LookupElement element) { - def presentation = new LookupElementPresentation() - element.renderElement(presentation) - return presentation - } - - public void testMethodItemPresentationGenerics() { - configure() - LookupElementPresentation presentation = renderElement(myItems[0]) - assert "add" == presentation.itemText - assert "(String o)" == presentation.tailText - assert "boolean" == presentation.typeText - - assert !presentation.tailGrayed - assert presentation.itemTextBold - } - - public void testPreferLongerNamesOption() throws Exception { - configureByFile("PreferLongerNamesOption.java"); - - assertEquals(3, myItems.length); - assertEquals("abcdEfghIjk", myItems[0].getLookupString()); - assertEquals("efghIjk", myItems[1].getLookupString()); - assertEquals("ijk", myItems[2].getLookupString()); - - LookupManager.getInstance(getProject()).hideActiveLookup(); - - CodeStyleSettingsManager.getSettings(getProject()).PREFER_LONGER_NAMES = false; - try{ - configureByFile("PreferLongerNamesOption.java"); - - assertEquals(3, myItems.length); - assertEquals("ijk", myItems[0].getLookupString()); - assertEquals("efghIjk", myItems[1].getLookupString()); - assertEquals("abcdEfghIjk", myItems[2].getLookupString()); - } - finally{ - CodeStyleSettingsManager.getSettings(getProject()).PREFER_LONGER_NAMES = true; - } - } - - public void testSCR7208() throws Exception { - configureByFile("SCR7208.java"); - } - - public void testProtectedFromSuper() throws Exception { - configureByFile("ProtectedFromSuper.java"); - Arrays.sort(myItems); - assertTrue("Exception not found", Arrays.binarySearch(myItems, "xxx") > 0); - } - - public void testBeforeInitialization() throws Exception { - configureByFile("BeforeInitialization.java"); - assertNotNull(myItems); - assertTrue(myItems.length > 0); - } - - public void testProtectedFromSuper2() throws Exception { - - configureByFile("ProtectedFromSuper.java"); - Arrays.sort(myItems); - assertTrue("Exception not found", Arrays.binarySearch(myItems, "xxx") > 0); - } - - public void testClassLiteralInArrayAnnoInitializer() throws Throwable { doTest(); } - public void testClassLiteralInArrayAnnoInitializer2() throws Throwable { doTest(); } - - public void testReferenceParameters() throws Exception { - configureByFile("ReferenceParameters.java"); - assertNotNull(myItems); - assertEquals(myItems.length, 2); - assertEquals(myItems[0].getLookupString(), "AAAA"); - assertEquals(myItems[1].getLookupString(), "AAAB"); - } - - public void testConstructorName1() throws Exception{ - final CodeInsightSettings settings = CodeInsightSettings.getInstance(); - final boolean autocomplete_on_code_completion = settings.AUTOCOMPLETE_ON_CODE_COMPLETION; - settings.AUTOCOMPLETE_ON_CODE_COMPLETION = false; - configureByFile("ConstructorName1.java"); - assertNotNull(myItems); - boolean failed = true; - for (final LookupElement item : myItems) { - if (item.getLookupString().equals("ABCDE")) { - failed = false; - } - } - assertFalse(failed); - settings.AUTOCOMPLETE_ON_CODE_COMPLETION = autocomplete_on_code_completion; - } - - public void testConstructorName2() throws Exception{ - final CodeInsightSettings settings = CodeInsightSettings.getInstance(); - final boolean autocomplete_on_code_completion = settings.AUTOCOMPLETE_ON_CODE_COMPLETION; - settings.AUTOCOMPLETE_ON_CODE_COMPLETION = false; - configureByFile("ConstructorName2.java"); - assertNotNull(myItems); - boolean failed = true; - for (final LookupElement item : myItems) { - if (item.getLookupString().equals("ABCDE")) { - failed = false; - } - } - assertFalse(failed); - settings.AUTOCOMPLETE_ON_CODE_COMPLETION = autocomplete_on_code_completion; - } - - public void testObjectsInThrowsBlock() throws Exception { - configureByFile("InThrowsCompletion.java"); - assert "C" in myFixture.lookupElementStrings - assert !("B" in myFixture.lookupElementStrings) - } - - public void testAfterInstanceof() throws Exception { - configureByFile("AfterInstanceof.java"); - assert "A" in myFixture.lookupElementStrings - } - - public void testAfterCast1() throws Exception { - configureByFile("AfterCast1.java"); - - assertNotNull(myItems); - assertEquals(2, myItems.length); - } - - public void testAfterCast2() throws Exception { - configureByFile("AfterCast2.java"); - checkResultByFile("AfterCast2-result.java"); - } - - public void testMethodCallForTwoLevelSelection() throws Exception { - configureByFile("MethodLookup.java"); - assertEquals(2, myItems.length); - } - - public void testMethodCallBeforeAnotherStatementWithParen() throws Exception { - configureByFile("MethodLookup2.java"); - checkResultByFile("MethodLookup2_After.java"); - } - - public void testMethodCallBeforeAnotherStatementWithParen2() throws Exception { - codeStyleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true; - configureByFile("MethodLookup2.java"); - checkResultByFile("MethodLookup2_After2.java"); - } - - public void testSwitchEnumLabel() throws Exception { - configureByFile("SwitchEnumLabel.java"); - assertEquals(3, myItems.length); - } - - public void testMethodInAnnotation() throws Exception { - configureByFile("Annotation.java"); - checkResultByFile("Annotation_after.java"); - } - - public void testMethodInAnnotation2() throws Exception { - configureByFile("Annotation2.java"); - checkResultByFile("Annotation2_after.java"); - } - - public void testMethodInAnnotation3() throws Exception { - configureByFile("Annotation3.java"); - checkResultByFile("Annotation3_after.java"); - } - - public void testMethodInAnnotation5() throws Exception { - configureByFile("Annotation5.java"); - checkResultByFile("Annotation5_after.java"); - } - - public void testMethodInAnnotation7() throws Exception { - configureByFile("Annotation7.java"); - selectItem(myItems[0]); - checkResultByFile("Annotation7_after.java"); - } - - public void testEnumInAnnotation() throws Exception { - configureByFile("Annotation4.java"); - checkResultByFile("Annotation4_after.java"); - } - - public void testSecondAttribute() throws Exception { - configureByFile("Annotation6.java"); - checkResultByFile("Annotation6_after.java"); - } - - public void testIDEADEV6408() throws Exception { - configureByFile("IDEADEV6408.java"); - assertStringItems "boolean", "byte" - } - - public void testMethodWithLeftParTailType() throws Exception { - configureByFile("MethodWithLeftParTailType.java"); - type('('); - checkResultByFile("MethodWithLeftParTailType_after.java"); - - configureByFile("MethodWithLeftParTailType2.java"); - type('('); - checkResultByFile("MethodWithLeftParTailType2_after.java"); - } - - public void testMethodWithLeftParTailTypeNoPairBrace() throws Exception { - final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET; - CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false; - - try { - configureByFile(getTestName(false) + ".java"); - type('('); - checkResult() - } - finally { - CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old; - } - } - - public void testMethodWithLeftParTailTypeNoPairBrace2() throws Exception { - final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET; - CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false; - - try { - //no tail type should work the normal way - configureByFile("MethodWithLeftParTailTypeNoPairBrace.java"); - selectItem(myItems[0]); - checkResultByFile("MethodWithLeftParTailTypeNoPairBrace_after2.java"); - } - finally { - CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old; - } - } - - public void testMethodNoPairBrace() throws Exception { - final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET; - CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false; - - try { - doTest '\n' - } - finally { - CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old; - } - } - - public void testExcessSpaceInTypeCast() throws Throwable { - configure() - selectItem(myItems[0]); - checkResult() - } - - public void testFieldType() throws Throwable { doTest(); } - - public void testPackageInAnnoParam() throws Throwable { - doTest(); - } - - public void testAnonymousTypeParameter() throws Throwable { doTest(); } - - public void testClassLiteralInAnnoParam() throws Throwable { - doTest(); - } - - public void testNoForceBraces() { - codeStyleSettings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS - doTest() - } - - public void testExcludeStringBuffer() throws Throwable { - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = [StringBuffer.name] as String[] - try { - doAntiTest() - } - finally { - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] - } - } - - public void testExcludeInstanceInnerClasses() throws Throwable { - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ['foo'] - myFixture.addClass 'package foo; public class Outer { public class Inner {} }' - myFixture.addClass 'package bar; public class Inner {}' - try { - configure() - assert 'bar.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName - assert myFixture.lookupElementStrings == ['Inner'] - } - finally { - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] - } - } - - public void testExcludedInstanceInnerClassCreation() throws Throwable { - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ['foo'] - myFixture.addClass 'package foo; public class Outer { public class Inner {} }' - myFixture.addClass 'package bar; public class Inner {}' - try { - configure() - assert 'foo.Outer.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName - assert myFixture.lookupElementStrings == ['Inner'] - } - finally { - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] - } - } - - public void testExcludedInstanceInnerClassQualifiedReference() throws Throwable { - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ['foo'] - myFixture.addClass 'package foo; public class Outer { public class Inner {} }' - myFixture.addClass 'package bar; public class Inner {}' - try { - configure() - assert 'foo.Outer.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName - assert myFixture.lookupElementStrings == ['Inner'] - } - finally { - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] - } - } - - public void testAtUnderClass() throws Throwable { - doTest(); - } - - public void testLocalClassName() throws Throwable { doTest(); } - public void testAssigningFieldForTheFirstTime() throws Throwable { doTest(); } - - public void testClassTypeParameters() throws Throwable { - configure() - assert 'K' in myFixture.lookupElementStrings - } - - public void testClassTypeParametersGenericBounds() throws Throwable { - configure() - assert 'K' in myFixture.lookupElementStrings - } - - public void testLocalClassTwice() throws Throwable { - configure() - assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo' - } - - public void testLocalTopLevelConflict() throws Throwable { - configure() - assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo' - } - - public void testFinalBeforeMethodCall() throws Throwable { - configure() - assertStringItems 'final', 'finalize' - } - public void testPrivateInAnonymous() throws Throwable { doTest() } - - public void testMethodParenthesesSpaces() throws Throwable { - codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true - codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true - doTest(); - } - - public void testMethodParenthesesSpacesArgs() throws Throwable { - codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true - codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true - doTest(); - } - - public void testAtUnderClassNoModifiers() throws Throwable { - doTest(); - } - - public void testBreakInIfCondition() throws Throwable { doTest(); } - public void testAccessStaticViaInstance() throws Throwable { doTest(); } - - public void testAccessStaticViaInstanceSecond() throws Throwable { - configure() - myFixture.complete(CompletionType.BASIC, 2) - checkResult() - } - - public void testContinueLabel() throws Throwable { doTest(); } - - public void testAnonymousProcess() { - myFixture.addClass 'package java.lang; public class Process {}' - myFixture.addClass ''' -import java.util.*; -public class Process {} -interface Pred { boolean predicate(A elem); } -public class ListUtils { - public static List filter(List list, Pred pred) {} -} -''' - configure() - type '\n' - checkResult() - } - - public void testNoThisInComment() throws Throwable { doAntiTest() } - public void testIncNull() throws Throwable { doAntiTest() } - - public void testLastExpressionInFor() throws Throwable { doTest(); } - - public void testUndoCommonPrefixOnHide() throws Throwable {//actually don't undo - configureByFile(getTestName(false) + ".java"); - checkResult() - LookupManager.getInstance(getProject()).hideActiveLookup(); - checkResult() - } - - public void testOnlyKeywordsInsideSwitch() throws Throwable { - configureByFile(getTestName(false) + ".java"); - assertStringItems("case", "default"); - } - - public void testBooleanLiterals() throws Throwable { - doTest(); - } - - public void testDoubleBooleanInParameter() throws Throwable { - configure() - assertStringItems("boolean", "byte") - } - - public void testDoubleConstant() throws Throwable { - configure() - assertStringItems("XFOO") - } - - public void testNotOnlyKeywordsInsideSwitch() throws Throwable { - doTest(); - } - - public void testChainedCallOnNextLine() throws Throwable { - configureByFile(getTestName(false) + ".java"); - selectItem(myItems[0]); - checkResult() - } - - public void testFinishWithDot() throws Throwable { - configureByFile(getTestName(false) + ".java"); - type('.'); - checkResult() - } - - public void testEnclosingThis() throws Throwable { doTest(); } - - public void testSeamlessConstant() throws Throwable { - configureByFile(getTestName(false) + ".java"); - selectItem(myItems[0]); - checkResult() - } - - public void testDefaultAnnoParam() throws Throwable { doTest(); } - - public void testSpaceAfterLookupString() throws Throwable { - configureByFile(getTestName(false) + ".java"); - type(' '); - assertNull(getLookup()); - checkResult() - } - - public void testNoSpaceInParensWithoutParams() throws Throwable { - codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; - try { - doTest(); - } - finally { - codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false; - } - } - - public void testTwoSpacesInParensWithParams() throws Throwable { - codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; - doTest(); - } - - public void testFillCommonPrefixOnSecondCompletion() throws Throwable { - configureByFile(getTestName(false) + ".java"); - type('g'); - complete(); - checkResult() - assertStringItems("getBar", "getFoo", "getClass"); - } - - public void testQualifierAsPackage() throws Throwable { - configureByFile(getTestName(false) + ".java"); - selectItem(myItems[0]); - checkResult() - } - - public void testQualifierAsPackage2() throws Throwable { - doTest(); - } - - public void testQualifierAsPackage3() throws Throwable { - doTest(); - } - - public void testPreselectEditorSelection() { - configure() - assert lookup.currentItem != myFixture.lookupElements[0] - assert 'finalize' == lookup.currentItem.lookupString - } - - public void testNoMethodsInNonStaticImports() { - configure() - assertStringItems("*") - } - - public void testMembersInStaticImports() { doTest() } - - public void testPackageNamedVariableBeforeAssignment() throws Throwable { - doTest(); - } - - public void testFieldWithCastingCaret() throws Throwable { doTest(); } - - public void testInnerEnumConstant() throws Throwable { doTest('\n'); } - - public void testMethodReturnType() throws Throwable { - doTest(); - } - - public void testMethodReturnTypeNoSpace() throws Throwable { - configureByFile(getTestName(false) + ".java"); - selectItem(myItems[0]); - checkResult() - } - - public void testEnumWithoutConstants() throws Throwable { - doTest(); - } - - public void testDoWhileMethodCall() throws Throwable { - doTest(); - } - - public void testSecondTypeParameterExtends() throws Throwable { - doTest(); - } - - public void testGetterWithExistingNonEmptyParameterList() throws Throwable { - doTest(); - } - - public void testNothingAfterNumericLiteral() throws Throwable { doAntiTest(); } - - public void testSpacesAroundEq() throws Throwable { doTest('='); } - - public void _testClassBeforeCast() throws Throwable { doTest '\n' } - - public void testNoAllClassesOnQualifiedReference() throws Throwable { - doAntiTest() - } - - public void testFinishClassNameWithDot() throws Throwable { - doTest('.') - } - - public void testFinishClassNameWithLParen() throws Throwable { - doTest('(') - } - - public void testSelectNoParameterSignature() throws Throwable { - configureByFile(getTestName(false) + ".java"); - final int parametersCount = ((PsiMethod)getLookup().getCurrentItem().getObject()).getParameterList().getParametersCount(); - assertEquals(0, parametersCount); - type '\n' - checkResult() - } - - public void testCompletionInsideClassLiteral() throws Throwable { - configureByFile(getTestName(false) + ".java"); - type('\n') - checkResult() - } - - public void testFieldNegation() throws Throwable { doTest('!');} - public void testDefaultInSwitch() throws Throwable { doTest()} - public void testBreakInSwitch() throws Throwable { doTest() } - - public void testSuperInConstructor() throws Throwable { - doTest(); - } - - public void testSuperInConstructorWithParams() throws Throwable { - doTest(); - } - - public void testSuperInMethod() throws Throwable { - doTest(); - } - - public void testSecondMethodParameterName() throws Throwable { - doTest(); - } - - public void testAnnotationAsUsualObject() throws Throwable { - doTest(); - } - - public void testAnnotationAsUsualObjectFromJavadoc() throws Throwable { - doTest(); - } - - public void testAnnotationAsUsualObjectInsideClass() throws Throwable { - doTest(); - } - - public void testAnnotationOnNothingParens() throws Throwable { - doTest(); - } - - public void testMultiResolveQualifier() throws Throwable { - doTest(); - } - - public void testSecondMethodParameter() throws Throwable { doTest(); } - public void testReturnInCase() throws Throwable { doTest(); } - public void testUnboxedConstantsInCase() throws Throwable { doTest(); } - - public void testAnnotationWithoutValueMethod() throws Throwable { - configureByFile(getTestName(false) + ".java"); - assertStringItems("bar", "foo"); - } - - public void testUnnecessaryMethodMerging() throws Throwable { - configureByFile(getTestName(false) + ".java"); - assertStringItems("fofoo", "fofoo"); - } - - public void testDontCancelPrefixOnTyping() throws Throwable { - configureByFile(getTestName(false) + ".java"); - type('~'); - assertNull(getLookup()); - checkResult() - } - - public void testAnnotationQualifiedName() throws Throwable { - doTest(); - } - - public void testClassNameGenerics() throws Throwable { - doTest('\n') - } - - public void testClassNameAnonymous() throws Throwable { - doTest('\n') - } - - public void testClassNameWithInner() throws Throwable { - configure() - assertStringItems 'Zzoo', 'Zzoo.Impl' - type '\n' - checkResult() - } - public void testClassNameWithInner2() throws Throwable { doTest() } - - public void testClassNameWithInstanceInner() throws Throwable { doTest('\n') } - - public void testDoubleFalse() throws Throwable { - configureByFile(getTestName(false) + ".java"); - assertStringItems("false", "fefefef", "finalize"); - } - - public void testSameNamedVariableInNestedClasses() throws Throwable { - doTest(); - assertNull(getLookup()); - } - - public void testHonorUnderscoreInPrefix() throws Throwable { - doTest(); - } - - public void testNoSemicolonAfterExistingParenthesesEspeciallyIfItsACast() throws Throwable { doTest(); } - public void testReturningTypeVariable() throws Throwable { doTest(); } - public void testReturningTypeVariable2() throws Throwable { doTest(); } - public void testReturningTypeVariable3() throws Throwable { doTest(); } - public void testImportInGenericType() throws Throwable { - configure() - myFixture.complete(CompletionType.BASIC, 2) - checkResult(); - } - - public void testCaseTailType() throws Throwable { doTest(); } - - def doPrimitiveTypeTest() { - configure() - checkResultByFile(getTestName(false) + ".java"); - assertTrue 'boolean' in myFixture.lookupElementStrings - } - - private def configure() { - configureByFile(getTestName(false) + ".java") - } - - public void testFinalInForLoop() throws Throwable { - configure() - assertStringItems 'final' - } - - public void testFinalInForLoop2() throws Throwable { - configure() - assertStringItems 'final', 'finalize' - } - - public void testOnlyClassesInExtends() throws Throwable { - configure() - assertStringItems 'Inner' - } - - public void testPrimitiveTypesInForLoop() throws Throwable { doPrimitiveTypeTest() } - public void testPrimitiveTypesInForLoop2() throws Throwable { doPrimitiveTypeTest() } - public void testPrimitiveTypesInForLoop3() throws Throwable { doPrimitiveTypeTest() } - public void testPrimitiveTypesInForLoop4() throws Throwable { doPrimitiveTypeTest() } - public void testPrimitiveTypesInForLoop5() throws Throwable { doPrimitiveTypeTest() } - public void testPrimitiveTypesInForLoop6() throws Throwable { doPrimitiveTypeTest() } - - public void testPrimitiveTypesInForLoopSpace() throws Throwable { - configure() - myFixture.type ' ' - checkResultByFile(getTestName(false) + "_after.java") - } - - public void testSecondInvocationToFillCommonPrefix() throws Throwable { - configure() - type('a'); - complete(); - assertStringItems("fai1", "fai2", "fai3"); - checkResult() - } - - public void testSuggestInaccessibleOnSecondInvocation() throws Throwable { - configure() - assertStringItems("_bar", "_goo"); - complete(); - assertStringItems("_bar", "_goo", "_foo"); - getLookup().setCurrentItem(getLookup().getItems().get(2)); - selectItem(lookup.items[2], Lookup.NORMAL_SELECT_CHAR) - checkResult() - } - - public void testNoCommonPrefixInsideIdentifier() throws Throwable { - final String path = getTestName(false) + ".java"; - configureByFile(path); - checkResultByFile(path); - assertStringItems("fai1", "fai2"); - } - - public void testProtectedInaccessibleOnSecondInvocation() throws Throwable { - myFixture.configureByFile(getTestName(false) + ".java"); - myFixture.complete(CompletionType.BASIC, 2); - checkResult() - } - - public void testPropertyReferencePrefix() throws Throwable { - myFixture.addFileToProject("test.properties", "foo.bar=Foo! Bar!").getVirtualFile(); - doAntiTest() - } - - private void doTest() throws Exception { - configure() - checkResult(); - } - - private void doTest(String finishChar) throws Exception { - configure() - type finishChar - checkResult(); - } - - private void doAntiTest() throws Exception { - configure() - checkResultByFile(getTestName(false) + ".java"); - assertEmpty(myItems); - assertNull(getLookup()); - } - - public void testSecondAnonymousClassParameter() throws Throwable { doTest(); } - - public void testSpaceAfterReturn() throws Throwable { - configure() - type '\n' - checkResult() - } - - private def checkResult() { - checkResultByFile(getTestName(false) + "_after.java") - } - - public void testIntersectionTypeMembers() throws Throwable { - configure() - assertStringItems "fooa", "foob" - } - - public void testCastInstanceofedQualifier() throws Throwable { doTest(); } - public void testCastComplexInstanceofedQualifier() throws Throwable { doTest(); } - - public void testCastTooComplexInstanceofedQualifier() throws Throwable { doAntiTest(); } - public void testDontCastInstanceofedQualifier() throws Throwable { doTest(); } - public void testQualifierCastingWithUnknownAssignments() throws Throwable { doTest(); } - public void testQualifierCastingBeforeLt() throws Throwable { doTest(); } - public void testNoReturnInTernary() throws Throwable { doTest(); } - - public void testOrAssignmentDfa() throws Throwable { doTest(); } - - public void testWildcardsInLookup() throws Exception { - configure() - assertNotNull(getLookup()); - type('*fz'); - final List list = getLookup().getItems(); - assertEquals("azzzfzzz", list.get(1).getLookupString()); - assertEquals("fzazzz", list.get(0).getLookupString()); - } - - public void testTabReplacesMethodNameWithLocalVariableName() throws Throwable { doTest('\t'); } - public void testMethodParameterAnnotationClass() throws Throwable { doTest(); } - public void testPrimitiveCastOverwrite() throws Throwable { doTest '\t' } - public void testClassReferenceInFor() throws Throwable { doTest ' ' } - public void testClassReferenceInFor2() throws Throwable { doTest ' ' } - public void testClassReferenceInFor3() throws Throwable { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE - try { - doTest ' ' - } - finally { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER - } - } - - public void testEnumConstantFromEnumMember() throws Throwable { doTest(); } - - public void testPrimitiveMethodParameter() throws Throwable { doTest(); } - - public void testNewExpectedClassParens() throws Throwable { doTest('\n'); } - - public void testQualifyInnerMembers() throws Throwable { doTest('\n') } - - public void testSuggestExpectedTypeMembers() throws Throwable { doTest('\n') } - public void testSuggestExpectedTypeMembersInCall() throws Throwable { doTest('\n') } - public void testExpectedTypesDotSelectsItem() throws Throwable { doTest('.') } - - public void testExpectedTypeMembersVersusStaticImports() throws Throwable { - configure() - assertStringItems('XFOO', 'XFOX') - } - - public void testDoubleExpectedTypeFactoryMethod() throws Throwable { - configure() - assertStringItems('Key', 'create', 'create') - assert renderElement(myItems[1]).itemText == 'Key.create' - assert renderElement(myItems[2]).itemText == 'Key.create' - } - - public void testSuggestExpectedTypeMembersNonImported() throws Throwable { - myFixture.addClass("package foo; public class Super { public static final Super FOO = null; }") - myFixture.addClass("package foo; public class Usage { public static void foo(Super s) {} }") - doTest('\n') - } - - public void testClassNameInIfBeforeIdentifier() throws Throwable { - myFixture.addClass("public class ABCDEFFFFF {}") - doTest('\n') - } - - public void testClassNameWithInnersTab() throws Throwable { doTest('\t') } - - public void testClassNameWithGenericsTab() throws Throwable {doTest('\t') } - public void testClassNameWithGenericsTab2() throws Throwable {doTest('\t') } - - public void testLiveTemplatePrefixTab() throws Throwable {doTest('\t') } - - public void testOnlyAnnotationsAfterAt() throws Throwable { doTest() } - - public void testOnlyExceptionsInCatch1() throws Exception { doTest() } - public void testOnlyExceptionsInCatch2() throws Exception { doTest() } - public void testOnlyExceptionsInCatch3() throws Exception { doTest() } - public void testOnlyExceptionsInCatch4() throws Exception { doTest() } - - public void testCommaAfterVariable() throws Throwable { doTest(',') } - - public void testClassAngleBracket() throws Throwable { doTest('<') } - public void testNoArgsMethodSpace() throws Throwable { doTest(' ') } - - public void testClassSquareBracket() throws Throwable { doTest('[') } - public void testPrimitiveSquareBracket() throws Throwable { doTest('[') } - public void testVariableSquareBracket() throws Throwable { doTest('[') } - public void testMethodSquareBracket() throws Throwable { doTest('[') } - - public void testMethodParameterTypeDot() throws Throwable { doAntiTest() } - public void testNewGenericClass() throws Throwable { doTest('\n') } - public void testNewGenericInterface() throws Throwable { doTest() } - public void testEnumPrivateFinal() throws Throwable { doTest() } - - public void testSwitchConstantsFromReferencedClass() throws Throwable { doTest('\n') } - - public void testUnfinishedMethodTypeParameter() throws Throwable { - configure() - assertStringItems("MyParameter", "MySecondParameter") - } - public void testUnfinishedMethodTypeParameter2() throws Throwable { - configure() - assertStringItems("MyParameter", "MySecondParameter") - } - - public void testSuperProtectedMethod() throws Throwable { - myFixture.addClass """package foo; - public class Bar { - protected void foo() { } - }""" - doTest() - } - - public void testTopLevelClassesFromPackaged() throws Throwable { - myFixture.addClass "public class Fooooo {}" - final text = "package foo; class Bar { Fooo }" - def file = myFixture.addFileToProject("foo/Bar.java", text) - myFixture.configureFromExistingVirtualFile file.virtualFile - assertEmpty myFixture.completeBasic() - myFixture.checkResult text - } - - public void testRightShift() throws Throwable { - configure() - assertStringItems("myField1", "myField2"); - } - - public void testAfterCommonPrefix() throws Throwable { - configure() - type 'eq' - assertStringItems("equals", "equalsIgnoreCase"); - complete() - assertStringItems("equals", "equalsIgnoreCase"); - type '(' - checkResult() - } - - public void testClassNameInsideIdentifierInIf() throws Throwable { - configure() - myFixture.complete(CompletionType.BASIC, 2) - type '\n' - checkResult() - } - - public void testKeywordSmartEnter() { - configure() - myFixture.performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT) - checkResult() - } - - public void testImportStringValue() throws Throwable { - myFixture.addClass("package foo; public class StringValue {}") - myFixture.addClass("package java.lang; class StringValue {}") - configure() - myFixture.complete(CompletionType.BASIC, 2) - type ' ' - checkResult() - } - - public void testPrimitiveArrayWithRBrace() throws Throwable { doTest '[' } - - public void testSuggestMembersOfStaticallyImportedClasses() throws Exception { - myFixture.addClass("""package foo; - public class Foo { - public static void foo() {} - public static void bar() {} - } - """) - doTest('\n') - } - - public void testSuggestMembersOfStaticallyImportedClassesUnqualifiedOnly() throws Exception { - def old = CodeInsightSettings.instance.SHOW_STATIC_AFTER_INSTANCE - CodeInsightSettings.instance.SHOW_STATIC_AFTER_INSTANCE = true - - try { - myFixture.addClass("""package foo; - public class Foo { - public static void foo() {} - public static void bar() {} - } - """) - configure() - assertOneElement(myFixture.getLookupElements()) - myFixture.type '\t' - checkResult() - } - finally { - CodeInsightSettings.instance.SHOW_STATIC_AFTER_INSTANCE = old - } - } - - public void testInstanceMagicMethod() throws Exception { doTest() } - - public void testNoDotOverwrite() throws Exception { doTest('.') } - - public void testStaticInnerExtendingOuter() throws Exception { doTest() } - public void testPrimitiveClass() throws Exception { doTest() } - public void testPrimitiveArrayClass() throws Exception { doTest() } - public void testPrimitiveArrayOnlyClass() throws Exception { doAntiTest() } - public void testPrimitiveArrayInAnno() throws Exception { doTest() } - - public void testSaxParserCommonPrefix() throws Exception { - myFixture.addClass("public class SAXParser {}") - myFixture.addClass("public class SAXParseException {}") - doTest() - } - - public void testNewClassAngleBracket() throws Exception { doTest('<') } - public void testNewClassAngleBracketExpected() throws Exception { doTest('<') } - public void testNewClassSquareBracket() throws Exception { doTest('[') } - - public void testMethodColon() throws Exception { doTest(':') } - public void testVariableColon() throws Exception { doTest(':') } - - public void testNoMethodsInParameterType() { - configure() - assertOrderedEquals myFixture.lookupElementStrings, "final", "float" - } - - public void testStaticallyImportedFieldsTwice() { - myFixture.addClass(""" - class Foo { - public static final int aZOO; - } - """) - myFixture.configureByText("a.java", """ - import static Foo.* - class Bar {{ - aZa - }} - """) - assertOneElement myFixture.completeBasic() - } - - public void testStatementKeywords() { - myFixture.configureByText("a.java", """ - class Bar {{ - xxx - }} - """) - myFixture.completeBasic() - final def strings = myFixture.lookupElementStrings - assertTrue 'if' in strings - assertTrue 'while' in strings - assertTrue 'do' in strings - assertTrue 'new' in strings - assertTrue 'try' in strings - - strings.remove 'new' - assertFalse 'new' in strings - } - - public void testExpressionKeywords() { - myFixture.configureByText("a.java", """ - class Bar {{ - foo(xxx) - }} - """) - myFixture.completeBasic() - final def strings = myFixture.lookupElementStrings - assertTrue 'new' in strings - } - - public void testImportAsterisk() { - myFixture.configureByText "a.java", "import java.lang." - myFixture.completeBasic() - myFixture.type '*\n' - myFixture.checkResult "import java.lang.*" - } - - public void testIntersectionTypesSOE() { - myFixture.configureByText("a.java", """ - import java.util.*; - import java.io.*; - class SOE { - public boolean setLocation(Iterable path) { - return true; - } - - public void compile(List classpath) { - setLocation(); - } - } - """) - myFixture.completeBasic() - myFixture.type '*\n' - myFixture.checkResult """ - import java.util.*; - import java.io.*; - class SOE { - public boolean setLocation(Iterable path) { - return true; - } - - public void compile(List classpath) { - setLocation(classpath); - } - } - """ - } - - public void testDontPreselectCaseInsensitivePrefixMatch() { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE - try { - myFixture.configureByText "a.java", "import java.io.*; class Foo {{ int fileSize; filx }}" - myFixture.completeBasic() - assert lookup.currentItem.lookupString == 'fileSize' - myFixture.type('e') - - assert lookup.items[0].lookupString == 'File' - assert lookup.items[1].lookupString == 'fileSize' - assert lookup.currentItem == lookup.items[1] - } - finally { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER - } - } - - public void testNoGenericsWhenChoosingWithParen() { doTest('Ma(') } - - public void testNoClosingWhenChoosingWithParenBeforeIdentifier() { doTest '(' } - - public void testPackageInMemberType() { doTest() } - - public void testClassNameDot() { doTest('.') } - - public void testClassNameDotBeforeCall() { - myFixture.addClass("package foo; public class FileInputStreamSmth {}") - myFixture.configureByFile(getTestName(false) + ".java") - PsiDocumentManager.getInstance(project).commitAllDocuments() - type '\b' - PsiDocumentManager.getInstance(project).commitAllDocuments() - myFixture.completeBasic() - assert lookup - type '.' - checkResult() - } - - public void testNoReturnAfterDot() { - configure() - assert !('return' in myFixture.lookupElementStrings) - } - - public void testDuplicateExpectedTypeInTypeArgumentList() { - configure() - def items = myFixture.lookupElements.findAll { it.lookupString == 'String' } - assert items.size() == 1 - assert LookupElementPresentation.renderElement(items[0]).tailText?.contains('java.lang') - } - - public void testSameSignature() { - configure() - myFixture.assertPreferredCompletionItems(0, 's', 's, file', 's, file, a') - lookup.setCurrentItem(lookup.items[2]) - myFixture.type('\n') - checkResult() - } - - public void testNoParenthesesAroundCallQualifier() { doTest() } - - public void testAllAssertClassesMethods() { - myFixture.addClass 'package foo; public class Assert { public static boolean foo() {} }' - myFixture.addClass 'package bar; public class Assert { public static boolean bar() {} }' - configure() - assert myFixture.lookupElementStrings == ['Assert.bar', 'Assert.foo'] - myFixture.type '\n' - checkResult() - } - - public void testCastVisually() { - configure() - def p = LookupElementPresentation.renderElement(myFixture.lookupElements[0]) - assert p.itemText == 'getValue' - assert p.itemTextBold - assert p.typeText == 'Foo' - } - - public void testSuggestEmptySet() { - configure() - assert 'emptySet' == myFixture.lookupElementStrings[0] - type '\n' - checkResult() - } - - public void testSuggestAllTypeArguments() { - configure() - assert 'String, String' == lookup.items[1].lookupString - lookup.currentItem = lookup.items[1] - type '\n' - checkResult() - - } - - public void testListArrayListCast() { doTest('\n') } - public void testInterfaceImplementationNoCast() { doTest() } - public void testStaticallyImportedMethodsBeforeExpression() { doTest('\n') } - public void testInnerChainedReturnType() { doTest() } - public void testOverwriteGenericsAfterNew() { doTest('\n') } - - private CommonCodeStyleSettings getCodeStyleSettings() { - return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE); - } - - public void testCompatibleInterfacesCast() { - configure() - assert myFixture.lookupElementStrings.containsAll(['foo', 'bar']) - } - - -} +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.completion; + + +import com.intellij.JavaTestUtil +import com.intellij.codeInsight.CodeInsightSettings +import com.intellij.codeInsight.lookup.Lookup +import com.intellij.codeInsight.lookup.LookupElement +import com.intellij.codeInsight.lookup.LookupElementPresentation +import com.intellij.codeInsight.lookup.LookupManager +import com.intellij.lang.java.JavaLanguage +import com.intellij.openapi.actionSystem.IdeActions +import com.intellij.openapi.fileTypes.StdFileTypes +import com.intellij.psi.codeStyle.CodeStyleSettingsManager +import com.intellij.psi.codeStyle.CommonCodeStyleSettings +import com.intellij.psi.* +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher + +public class NormalCompletionTest extends LightFixtureCompletionTestCase { + @Override + protected String getBasePath() { + return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/normal/"; + } + + @Override + protected void setUp() { + super.setUp() + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + } + + public void testSimple() throws Exception { + configureByFile("Simple.java"); + assertStringItems("_local1", "_local2", "_field", "_method", "_baseField", "_baseMethod"); + } + + public void testDontCompleteFieldsAndMethodsInReferenceCodeFragment() throws Throwable { + final String text = CommonClassNames.JAVA_LANG_OBJECT + "."; + PsiFile file = JavaCodeFragmentFactory.getInstance(project).createReferenceCodeFragment(text, null, true, true); + myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); + complete(); + myFixture.checkResult(text); + assertEmpty(myItems); + } + + public void testNoPackagesInExpressionCodeFragment() throws Throwable { + final String text = "jav"; + PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment(text, null, null, true); + myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); + complete(); + myFixture.checkResult(text); + assertEmpty(myItems); + } + + public void testSubPackagesInExpressionCodeFragment() throws Throwable { + PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment("java.la", null, null, true); + myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); + complete(); + myFixture.checkResult("java.lang."); + assertNull(myItems); + } + + public void testPrimitivesInTypeCodeFragmentWithParameterListContext() throws Throwable { + def clazz = myFixture.addClass("class Foo { void foo(int a) {} }") + + PsiFile file = JavaCodeFragmentFactory.getInstance(project).createTypeCodeFragment("b", clazz.methods[0].parameterList, true); + myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); + complete(); + assertStringItems('boolean', 'byte') + } + + public void testQualifierCastingInExpressionCodeFragment() throws Throwable { + final ctxText = "class Bar {{ Object o; o=null }}" + final ctxFile = createLightFile(StdFileTypes.JAVA, ctxText) + final context = ctxFile.findElementAt(ctxText.indexOf("o=")) + assert context + + PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment("o instanceof String && o.subst", context, null, true); + myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); + complete(); + myFixture.checkResult("o instanceof String && ((String) o).substring()"); + assertNull(myItems); + } + + public void testCastToPrimitive1() throws Exception { + configureByFile("CastToPrimitive1.java"); + + for (final LookupElement item : myItems) { + if (item.getLookupString().equals("int")) return; + } + assertTrue(false); + } + + public void testCastToPrimitive2() throws Exception { + configureByFile("CastToPrimitive2.java"); + + for (final LookupElement item : myItems) { + if (item.getLookupString().equals("int")) return; + } + assertTrue(false); + } + + public void testCastToPrimitive3() throws Exception { + configureByFile("CastToPrimitive3.java"); + + for (final LookupElement item : myItems) { + if (item.getLookupString().equals("int")) return; + } + assertTrue(false); + } + + public void testWriteInInvokeLater() throws Exception { + configureByFile("WriteInInvokeLater.java"); + } + + public void testQualifiedNew1() throws Exception { + configure() + assertStringItems "IInner", "Inner" + } + + public void testQualifiedNew2() throws Exception { + configure() + assertStringItems "AnInner", "Inner" + } + + public void testKeywordsInName() throws Exception { + doTest 'a\n' + } + + public void testSimpleVariable() throws Exception { doTest() } + + public void testMethodItemPresentation() { + configure() + LookupElementPresentation presentation = renderElement(myItems[0]) + assert "equals" == presentation.itemText + assert "(Object anObject)" == presentation.tailText + assert "boolean" == presentation.typeText + + assert !presentation.tailGrayed + assert presentation.itemTextBold + } + + private LookupElementPresentation renderElement(LookupElement element) { + def presentation = new LookupElementPresentation() + element.renderElement(presentation) + return presentation + } + + public void testMethodItemPresentationGenerics() { + configure() + LookupElementPresentation presentation = renderElement(myItems[0]) + assert "add" == presentation.itemText + assert "(String o)" == presentation.tailText + assert "boolean" == presentation.typeText + + assert !presentation.tailGrayed + assert presentation.itemTextBold + } + + public void testPreferLongerNamesOption() throws Exception { + configureByFile("PreferLongerNamesOption.java"); + + assertEquals(3, myItems.length); + assertEquals("abcdEfghIjk", myItems[0].getLookupString()); + assertEquals("efghIjk", myItems[1].getLookupString()); + assertEquals("ijk", myItems[2].getLookupString()); + + LookupManager.getInstance(getProject()).hideActiveLookup(); + + CodeStyleSettingsManager.getSettings(getProject()).PREFER_LONGER_NAMES = false; + try{ + configureByFile("PreferLongerNamesOption.java"); + + assertEquals(3, myItems.length); + assertEquals("ijk", myItems[0].getLookupString()); + assertEquals("efghIjk", myItems[1].getLookupString()); + assertEquals("abcdEfghIjk", myItems[2].getLookupString()); + } + finally{ + CodeStyleSettingsManager.getSettings(getProject()).PREFER_LONGER_NAMES = true; + } + } + + public void testSCR7208() throws Exception { + configureByFile("SCR7208.java"); + } + + public void testProtectedFromSuper() throws Exception { + configureByFile("ProtectedFromSuper.java"); + Arrays.sort(myItems); + assertTrue("Exception not found", Arrays.binarySearch(myItems, "xxx") > 0); + } + + public void testBeforeInitialization() throws Exception { + configureByFile("BeforeInitialization.java"); + assertNotNull(myItems); + assertTrue(myItems.length > 0); + } + + public void testProtectedFromSuper2() throws Exception { + + configureByFile("ProtectedFromSuper.java"); + Arrays.sort(myItems); + assertTrue("Exception not found", Arrays.binarySearch(myItems, "xxx") > 0); + } + + public void testClassLiteralInArrayAnnoInitializer() throws Throwable { doTest(); } + public void testClassLiteralInArrayAnnoInitializer2() throws Throwable { doTest(); } + + public void testReferenceParameters() throws Exception { + configureByFile("ReferenceParameters.java"); + assertNotNull(myItems); + assertEquals(myItems.length, 2); + assertEquals(myItems[0].getLookupString(), "AAAA"); + assertEquals(myItems[1].getLookupString(), "AAAB"); + } + + public void testConstructorName1() throws Exception{ + final CodeInsightSettings settings = CodeInsightSettings.getInstance(); + final boolean autocomplete_on_code_completion = settings.AUTOCOMPLETE_ON_CODE_COMPLETION; + settings.AUTOCOMPLETE_ON_CODE_COMPLETION = false; + configureByFile("ConstructorName1.java"); + assertNotNull(myItems); + boolean failed = true; + for (final LookupElement item : myItems) { + if (item.getLookupString().equals("ABCDE")) { + failed = false; + } + } + assertFalse(failed); + settings.AUTOCOMPLETE_ON_CODE_COMPLETION = autocomplete_on_code_completion; + } + + public void testConstructorName2() throws Exception{ + final CodeInsightSettings settings = CodeInsightSettings.getInstance(); + final boolean autocomplete_on_code_completion = settings.AUTOCOMPLETE_ON_CODE_COMPLETION; + settings.AUTOCOMPLETE_ON_CODE_COMPLETION = false; + configureByFile("ConstructorName2.java"); + assertNotNull(myItems); + boolean failed = true; + for (final LookupElement item : myItems) { + if (item.getLookupString().equals("ABCDE")) { + failed = false; + } + } + assertFalse(failed); + settings.AUTOCOMPLETE_ON_CODE_COMPLETION = autocomplete_on_code_completion; + } + + public void testObjectsInThrowsBlock() throws Exception { + configureByFile("InThrowsCompletion.java"); + assert "C" in myFixture.lookupElementStrings + assert !("B" in myFixture.lookupElementStrings) + } + + public void testAfterInstanceof() throws Exception { + configureByFile("AfterInstanceof.java"); + assert "A" in myFixture.lookupElementStrings + } + + public void testAfterCast1() throws Exception { + configureByFile("AfterCast1.java"); + + assertNotNull(myItems); + assertEquals(2, myItems.length); + } + + public void testAfterCast2() throws Exception { + configureByFile("AfterCast2.java"); + checkResultByFile("AfterCast2-result.java"); + } + + public void testMethodCallForTwoLevelSelection() throws Exception { + configureByFile("MethodLookup.java"); + assertEquals(2, myItems.length); + } + + public void testMethodCallBeforeAnotherStatementWithParen() throws Exception { + configureByFile("MethodLookup2.java"); + checkResultByFile("MethodLookup2_After.java"); + } + + public void testMethodCallBeforeAnotherStatementWithParen2() throws Exception { + codeStyleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true; + configureByFile("MethodLookup2.java"); + checkResultByFile("MethodLookup2_After2.java"); + } + + public void testSwitchEnumLabel() throws Exception { + configureByFile("SwitchEnumLabel.java"); + assertEquals(3, myItems.length); + } + + public void testMethodInAnnotation() throws Exception { + configureByFile("Annotation.java"); + checkResultByFile("Annotation_after.java"); + } + + public void testMethodInAnnotation2() throws Exception { + configureByFile("Annotation2.java"); + checkResultByFile("Annotation2_after.java"); + } + + public void testMethodInAnnotation3() throws Exception { + configureByFile("Annotation3.java"); + checkResultByFile("Annotation3_after.java"); + } + + public void testMethodInAnnotation5() throws Exception { + configureByFile("Annotation5.java"); + checkResultByFile("Annotation5_after.java"); + } + + public void testMethodInAnnotation7() throws Exception { + configureByFile("Annotation7.java"); + selectItem(myItems[0]); + checkResultByFile("Annotation7_after.java"); + } + + public void testEnumInAnnotation() throws Exception { + configureByFile("Annotation4.java"); + checkResultByFile("Annotation4_after.java"); + } + + public void testSecondAttribute() throws Exception { + configureByFile("Annotation6.java"); + checkResultByFile("Annotation6_after.java"); + } + + public void testIDEADEV6408() throws Exception { + configureByFile("IDEADEV6408.java"); + assertStringItems "boolean", "byte" + } + + public void testMethodWithLeftParTailType() throws Exception { + configureByFile("MethodWithLeftParTailType.java"); + type('('); + checkResultByFile("MethodWithLeftParTailType_after.java"); + + configureByFile("MethodWithLeftParTailType2.java"); + type('('); + checkResultByFile("MethodWithLeftParTailType2_after.java"); + } + + public void testMethodWithLeftParTailTypeNoPairBrace() throws Exception { + final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET; + CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false; + + try { + configureByFile(getTestName(false) + ".java"); + type('('); + checkResult() + } + finally { + CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old; + } + } + + public void testMethodWithLeftParTailTypeNoPairBrace2() throws Exception { + final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET; + CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false; + + try { + //no tail type should work the normal way + configureByFile("MethodWithLeftParTailTypeNoPairBrace.java"); + selectItem(myItems[0]); + checkResultByFile("MethodWithLeftParTailTypeNoPairBrace_after2.java"); + } + finally { + CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old; + } + } + + public void testMethodNoPairBrace() throws Exception { + final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET; + CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false; + + try { + doTest '\n' + } + finally { + CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old; + } + } + + public void testExcessSpaceInTypeCast() throws Throwable { + configure() + selectItem(myItems[0]); + checkResult() + } + + public void testFieldType() throws Throwable { doTest(); } + + public void testPackageInAnnoParam() throws Throwable { + doTest(); + } + + public void testAnonymousTypeParameter() throws Throwable { doTest(); } + + public void testClassLiteralInAnnoParam() throws Throwable { + doTest(); + } + + public void testNoForceBraces() { + codeStyleSettings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS + doTest() + } + + public void testExcludeStringBuffer() throws Throwable { + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = [StringBuffer.name] as String[] + try { + doAntiTest() + } + finally { + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] + } + } + + public void testExcludeInstanceInnerClasses() throws Throwable { + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ['foo'] + myFixture.addClass 'package foo; public class Outer { public class Inner {} }' + myFixture.addClass 'package bar; public class Inner {}' + try { + configure() + assert 'bar.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName + assert myFixture.lookupElementStrings == ['Inner'] + } + finally { + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] + } + } + + public void testExcludedInstanceInnerClassCreation() throws Throwable { + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ['foo'] + myFixture.addClass 'package foo; public class Outer { public class Inner {} }' + myFixture.addClass 'package bar; public class Inner {}' + try { + configure() + assert 'foo.Outer.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName + assert myFixture.lookupElementStrings == ['Inner'] + } + finally { + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] + } + } + + public void testExcludedInstanceInnerClassQualifiedReference() throws Throwable { + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ['foo'] + myFixture.addClass 'package foo; public class Outer { public class Inner {} }' + myFixture.addClass 'package bar; public class Inner {}' + try { + configure() + assert 'foo.Outer.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName + assert myFixture.lookupElementStrings == ['Inner'] + } + finally { + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] + } + } + + public void testAtUnderClass() throws Throwable { + doTest(); + } + + public void testLocalClassName() throws Throwable { doTest(); } + public void testAssigningFieldForTheFirstTime() throws Throwable { doTest(); } + + public void testClassTypeParameters() throws Throwable { + configure() + assert 'K' in myFixture.lookupElementStrings + } + + public void testClassTypeParametersGenericBounds() throws Throwable { + configure() + assert 'K' in myFixture.lookupElementStrings + } + + public void testLocalClassTwice() throws Throwable { + configure() + assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo' + } + + public void testLocalTopLevelConflict() throws Throwable { + configure() + assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo' + } + + public void testFinalBeforeMethodCall() throws Throwable { + configure() + assertStringItems 'final', 'finalize' + } + public void testPrivateInAnonymous() throws Throwable { doTest() } + + public void testMethodParenthesesSpaces() throws Throwable { + codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true + doTest(); + } + + public void testMethodParenthesesSpacesArgs() throws Throwable { + codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true + doTest(); + } + + public void testAtUnderClassNoModifiers() throws Throwable { + doTest(); + } + + public void testBreakInIfCondition() throws Throwable { doTest(); } + public void testAccessStaticViaInstance() throws Throwable { doTest(); } + + public void testAccessStaticViaInstanceSecond() throws Throwable { + configure() + myFixture.complete(CompletionType.BASIC, 2) + checkResult() + } + + public void testContinueLabel() throws Throwable { doTest(); } + + public void testAnonymousProcess() { + myFixture.addClass 'package java.lang; public class Process {}' + myFixture.addClass ''' +import java.util.*; +public class Process {} +interface Pred { boolean predicate(A elem); } +public class ListUtils { + public static List filter(List list, Pred pred) {} +} +''' + configure() + type '\n' + checkResult() + } + + public void testNoThisInComment() throws Throwable { doAntiTest() } + public void testIncNull() throws Throwable { doAntiTest() } + + public void testLastExpressionInFor() throws Throwable { doTest(); } + + public void testUndoCommonPrefixOnHide() throws Throwable {//actually don't undo + configureByFile(getTestName(false) + ".java"); + checkResult() + LookupManager.getInstance(getProject()).hideActiveLookup(); + checkResult() + } + + public void testOnlyKeywordsInsideSwitch() throws Throwable { + configureByFile(getTestName(false) + ".java"); + assertStringItems("case", "default"); + } + + public void testBooleanLiterals() throws Throwable { + doTest(); + } + + public void testDoubleBooleanInParameter() throws Throwable { + configure() + assertStringItems("boolean", "byte") + } + + public void testDoubleConstant() throws Throwable { + configure() + assertStringItems("XFOO") + } + + public void testNotOnlyKeywordsInsideSwitch() throws Throwable { + doTest(); + } + + public void testChainedCallOnNextLine() throws Throwable { + configureByFile(getTestName(false) + ".java"); + selectItem(myItems[0]); + checkResult() + } + + public void testFinishWithDot() throws Throwable { + configureByFile(getTestName(false) + ".java"); + type('.'); + checkResult() + } + + public void testEnclosingThis() throws Throwable { doTest(); } + + public void testSeamlessConstant() throws Throwable { + configureByFile(getTestName(false) + ".java"); + selectItem(myItems[0]); + checkResult() + } + + public void testDefaultAnnoParam() throws Throwable { doTest(); } + + public void testSpaceAfterLookupString() throws Throwable { + configureByFile(getTestName(false) + ".java"); + type(' '); + assertNull(getLookup()); + checkResult() + } + + public void testNoSpaceInParensWithoutParams() throws Throwable { + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; + try { + doTest(); + } + finally { + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false; + } + } + + public void testTwoSpacesInParensWithParams() throws Throwable { + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; + doTest(); + } + + public void testFillCommonPrefixOnSecondCompletion() throws Throwable { + configureByFile(getTestName(false) + ".java"); + type('g'); + complete(); + checkResult() + assertStringItems("getBar", "getFoo", "getClass"); + } + + public void testQualifierAsPackage() throws Throwable { + configureByFile(getTestName(false) + ".java"); + selectItem(myItems[0]); + checkResult() + } + + public void testQualifierAsPackage2() throws Throwable { + doTest(); + } + + public void testQualifierAsPackage3() throws Throwable { + doTest(); + } + + public void testPreselectEditorSelection() { + configure() + assert lookup.currentItem != myFixture.lookupElements[0] + assert 'finalize' == lookup.currentItem.lookupString + } + + public void testNoMethodsInNonStaticImports() { + configure() + assertStringItems("*") + } + + public void testMembersInStaticImports() { doTest() } + + public void testPackageNamedVariableBeforeAssignment() throws Throwable { + doTest(); + } + + public void testFieldWithCastingCaret() throws Throwable { doTest(); } + + public void testInnerEnumConstant() throws Throwable { doTest('\n'); } + + public void testMethodReturnType() throws Throwable { + doTest(); + } + + public void testMethodReturnTypeNoSpace() throws Throwable { + configureByFile(getTestName(false) + ".java"); + selectItem(myItems[0]); + checkResult() + } + + public void testEnumWithoutConstants() throws Throwable { + doTest(); + } + + public void testDoWhileMethodCall() throws Throwable { + doTest(); + } + + public void testSecondTypeParameterExtends() throws Throwable { + doTest(); + } + + public void testGetterWithExistingNonEmptyParameterList() throws Throwable { + doTest(); + } + + public void testNothingAfterNumericLiteral() throws Throwable { doAntiTest(); } + + public void testSpacesAroundEq() throws Throwable { doTest('='); } + + public void _testClassBeforeCast() throws Throwable { doTest '\n' } + + public void testNoAllClassesOnQualifiedReference() throws Throwable { + doAntiTest() + } + + public void testFinishClassNameWithDot() throws Throwable { + doTest('.') + } + + public void testFinishClassNameWithLParen() throws Throwable { + doTest('(') + } + + public void testSelectNoParameterSignature() throws Throwable { + configureByFile(getTestName(false) + ".java"); + final int parametersCount = ((PsiMethod)getLookup().getCurrentItem().getObject()).getParameterList().getParametersCount(); + assertEquals(0, parametersCount); + type '\n' + checkResult() + } + + public void testCompletionInsideClassLiteral() throws Throwable { + configureByFile(getTestName(false) + ".java"); + type('\n') + checkResult() + } + + public void testFieldNegation() throws Throwable { doTest('!');} + public void testDefaultInSwitch() throws Throwable { doTest()} + public void testBreakInSwitch() throws Throwable { doTest() } + + public void testSuperInConstructor() throws Throwable { + doTest(); + } + + public void testSuperInConstructorWithParams() throws Throwable { + doTest(); + } + + public void testSuperInMethod() throws Throwable { + doTest(); + } + + public void testSecondMethodParameterName() throws Throwable { + doTest(); + } + + public void testAnnotationAsUsualObject() throws Throwable { + doTest(); + } + + public void testAnnotationAsUsualObjectFromJavadoc() throws Throwable { + doTest(); + } + + public void testAnnotationAsUsualObjectInsideClass() throws Throwable { + doTest(); + } + + public void testAnnotationOnNothingParens() throws Throwable { + doTest(); + } + + public void testMultiResolveQualifier() throws Throwable { + doTest(); + } + + public void testSecondMethodParameter() throws Throwable { doTest(); } + public void testReturnInCase() throws Throwable { doTest(); } + public void testUnboxedConstantsInCase() throws Throwable { doTest(); } + + public void testAnnotationWithoutValueMethod() throws Throwable { + configureByFile(getTestName(false) + ".java"); + assertStringItems("bar", "foo"); + } + + public void testUnnecessaryMethodMerging() throws Throwable { + configureByFile(getTestName(false) + ".java"); + assertStringItems("fofoo", "fofoo"); + } + + public void testDontCancelPrefixOnTyping() throws Throwable { + configureByFile(getTestName(false) + ".java"); + type('~'); + assertNull(getLookup()); + checkResult() + } + + public void testAnnotationQualifiedName() throws Throwable { + doTest(); + } + + public void testClassNameGenerics() throws Throwable { + doTest('\n') + } + + public void testClassNameAnonymous() throws Throwable { + doTest('\n') + } + + public void testClassNameWithInner() throws Throwable { + configure() + assertStringItems 'Zzoo', 'Zzoo.Impl' + type '\n' + checkResult() + } + public void testClassNameWithInner2() throws Throwable { doTest() } + + public void testClassNameWithInstanceInner() throws Throwable { doTest('\n') } + + public void testDoubleFalse() throws Throwable { + configureByFile(getTestName(false) + ".java"); + assertStringItems("false", "fefefef", "finalize"); + } + + public void testSameNamedVariableInNestedClasses() throws Throwable { + doTest(); + assertNull(getLookup()); + } + + public void testHonorUnderscoreInPrefix() throws Throwable { + doTest(); + } + + public void testNoSemicolonAfterExistingParenthesesEspeciallyIfItsACast() throws Throwable { doTest(); } + public void testReturningTypeVariable() throws Throwable { doTest(); } + public void testReturningTypeVariable2() throws Throwable { doTest(); } + public void testReturningTypeVariable3() throws Throwable { doTest(); } + public void testImportInGenericType() throws Throwable { + configure() + myFixture.complete(CompletionType.BASIC, 2) + checkResult(); + } + + public void testCaseTailType() throws Throwable { doTest(); } + + def doPrimitiveTypeTest() { + configure() + checkResultByFile(getTestName(false) + ".java"); + assertTrue 'boolean' in myFixture.lookupElementStrings + } + + private def configure() { + configureByFile(getTestName(false) + ".java") + } + + public void testFinalInForLoop() throws Throwable { + configure() + assertStringItems 'final' + } + + public void testFinalInForLoop2() throws Throwable { + configure() + assertStringItems 'final', 'finalize' + } + + public void testOnlyClassesInExtends() throws Throwable { + configure() + assertStringItems 'Inner' + } + + public void testPrimitiveTypesInForLoop() throws Throwable { doPrimitiveTypeTest() } + public void testPrimitiveTypesInForLoop2() throws Throwable { doPrimitiveTypeTest() } + public void testPrimitiveTypesInForLoop3() throws Throwable { doPrimitiveTypeTest() } + public void testPrimitiveTypesInForLoop4() throws Throwable { doPrimitiveTypeTest() } + public void testPrimitiveTypesInForLoop5() throws Throwable { doPrimitiveTypeTest() } + public void testPrimitiveTypesInForLoop6() throws Throwable { doPrimitiveTypeTest() } + + public void testPrimitiveTypesInForLoopSpace() throws Throwable { + configure() + myFixture.type ' ' + checkResultByFile(getTestName(false) + "_after.java") + } + + public void testSecondInvocationToFillCommonPrefix() throws Throwable { + configure() + type('a'); + complete(); + assertStringItems("fai1", "fai2", "fai3"); + checkResult() + } + + public void testSuggestInaccessibleOnSecondInvocation() throws Throwable { + configure() + assertStringItems("_bar", "_goo"); + complete(); + assertStringItems("_bar", "_goo", "_foo"); + getLookup().setCurrentItem(getLookup().getItems().get(2)); + selectItem(lookup.items[2], Lookup.NORMAL_SELECT_CHAR) + checkResult() + } + + public void testNoCommonPrefixInsideIdentifier() throws Throwable { + final String path = getTestName(false) + ".java"; + configureByFile(path); + checkResultByFile(path); + assertStringItems("fai1", "fai2"); + } + + public void testProtectedInaccessibleOnSecondInvocation() throws Throwable { + myFixture.configureByFile(getTestName(false) + ".java"); + myFixture.complete(CompletionType.BASIC, 2); + checkResult() + } + + public void testPropertyReferencePrefix() throws Throwable { + myFixture.addFileToProject("test.properties", "foo.bar=Foo! Bar!").getVirtualFile(); + doAntiTest() + } + + private void doTest() throws Exception { + configure() + checkResult(); + } + + private void doTest(String finishChar) throws Exception { + configure() + type finishChar + checkResult(); + } + + private void doAntiTest() throws Exception { + configure() + checkResultByFile(getTestName(false) + ".java"); + assertEmpty(myItems); + assertNull(getLookup()); + } + + public void testSecondAnonymousClassParameter() throws Throwable { doTest(); } + + public void testSpaceAfterReturn() throws Throwable { + configure() + type '\n' + checkResult() + } + + private def checkResult() { + checkResultByFile(getTestName(false) + "_after.java") + } + + public void testIntersectionTypeMembers() throws Throwable { + configure() + assertStringItems "fooa", "foob" + } + + public void testCastInstanceofedQualifier() throws Throwable { doTest(); } + public void testCastComplexInstanceofedQualifier() throws Throwable { doTest(); } + + public void testCastTooComplexInstanceofedQualifier() throws Throwable { doAntiTest(); } + public void testDontCastInstanceofedQualifier() throws Throwable { doTest(); } + public void testQualifierCastingWithUnknownAssignments() throws Throwable { doTest(); } + public void testQualifierCastingBeforeLt() throws Throwable { doTest(); } + public void testNoReturnInTernary() throws Throwable { doTest(); } + + public void testOrAssignmentDfa() throws Throwable { doTest(); } + + public void testWildcardsInLookup() throws Exception { + configure() + assertNotNull(getLookup()); + type('*fz'); + final List list = getLookup().getItems(); + assertEquals("azzzfzzz", list.get(1).getLookupString()); + assertEquals("fzazzz", list.get(0).getLookupString()); + } + + public void testTabReplacesMethodNameWithLocalVariableName() throws Throwable { doTest('\t'); } + public void testMethodParameterAnnotationClass() throws Throwable { doTest(); } + public void testPrimitiveCastOverwrite() throws Throwable { doTest '\t' } + public void testClassReferenceInFor() throws Throwable { doTest ' ' } + public void testClassReferenceInFor2() throws Throwable { doTest ' ' } + public void testClassReferenceInFor3() throws Throwable { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE + try { + doTest ' ' + } + finally { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER + } + } + + public void testEnumConstantFromEnumMember() throws Throwable { doTest(); } + + public void testPrimitiveMethodParameter() throws Throwable { doTest(); } + + public void testNewExpectedClassParens() throws Throwable { doTest('\n'); } + + public void testQualifyInnerMembers() throws Throwable { doTest('\n') } + + public void testSuggestExpectedTypeMembers() throws Throwable { doTest('\n') } + public void testSuggestExpectedTypeMembersInCall() throws Throwable { doTest('\n') } + public void testExpectedTypesDotSelectsItem() throws Throwable { doTest('.') } + + public void testExpectedTypeMembersVersusStaticImports() throws Throwable { + configure() + assertStringItems('XFOO', 'XFOX') + } + + public void testDoubleExpectedTypeFactoryMethod() throws Throwable { + configure() + assertStringItems('Key', 'create', 'create') + assert renderElement(myItems[1]).itemText == 'Key.create' + assert renderElement(myItems[2]).itemText == 'Key.create' + } + + public void testSuggestExpectedTypeMembersNonImported() throws Throwable { + myFixture.addClass("package foo; public class Super { public static final Super FOO = null; }") + myFixture.addClass("package foo; public class Usage { public static void foo(Super s) {} }") + doTest('\n') + } + + public void testClassNameInIfBeforeIdentifier() throws Throwable { + myFixture.addClass("public class ABCDEFFFFF {}") + doTest('\n') + } + + public void testClassNameWithInnersTab() throws Throwable { doTest('\t') } + + public void testClassNameWithGenericsTab() throws Throwable {doTest('\t') } + public void testClassNameWithGenericsTab2() throws Throwable {doTest('\t') } + + public void testLiveTemplatePrefixTab() throws Throwable {doTest('\t') } + + public void testOnlyAnnotationsAfterAt() throws Throwable { doTest() } + + public void testOnlyExceptionsInCatch1() throws Exception { doTest() } + public void testOnlyExceptionsInCatch2() throws Exception { doTest() } + public void testOnlyExceptionsInCatch3() throws Exception { doTest() } + public void testOnlyExceptionsInCatch4() throws Exception { doTest() } + + public void testCommaAfterVariable() throws Throwable { doTest(',') } + + public void testClassAngleBracket() throws Throwable { doTest('<') } + public void testNoArgsMethodSpace() throws Throwable { doTest(' ') } + + public void testClassSquareBracket() throws Throwable { doTest('[') } + public void testPrimitiveSquareBracket() throws Throwable { doTest('[') } + public void testVariableSquareBracket() throws Throwable { doTest('[') } + public void testMethodSquareBracket() throws Throwable { doTest('[') } + + public void testMethodParameterTypeDot() throws Throwable { doAntiTest() } + public void testNewGenericClass() throws Throwable { doTest('\n') } + public void testNewGenericInterface() throws Throwable { doTest() } + public void testEnumPrivateFinal() throws Throwable { doTest() } + + public void testSwitchConstantsFromReferencedClass() throws Throwable { doTest('\n') } + + public void testUnfinishedMethodTypeParameter() throws Throwable { + configure() + assertStringItems("MyParameter", "MySecondParameter") + } + public void testUnfinishedMethodTypeParameter2() throws Throwable { + configure() + assertStringItems("MyParameter", "MySecondParameter") + } + + public void testSuperProtectedMethod() throws Throwable { + myFixture.addClass """package foo; + public class Bar { + protected void foo() { } + }""" + doTest() + } + + public void testTopLevelClassesFromPackaged() throws Throwable { + myFixture.addClass "public class Fooooo {}" + final text = "package foo; class Bar { Fooo }" + def file = myFixture.addFileToProject("foo/Bar.java", text) + myFixture.configureFromExistingVirtualFile file.virtualFile + assertEmpty myFixture.completeBasic() + myFixture.checkResult text + } + + public void testRightShift() throws Throwable { + configure() + assertStringItems("myField1", "myField2"); + } + + public void testAfterCommonPrefix() throws Throwable { + configure() + type 'eq' + assertStringItems("equals", "equalsIgnoreCase"); + complete() + assertStringItems("equals", "equalsIgnoreCase"); + type '(' + checkResult() + } + + public void testClassNameInsideIdentifierInIf() throws Throwable { + configure() + myFixture.complete(CompletionType.BASIC, 2) + type '\n' + checkResult() + } + + public void testKeywordSmartEnter() { + configure() + myFixture.performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT) + checkResult() + } + + public void testImportStringValue() throws Throwable { + myFixture.addClass("package foo; public class StringValue {}") + myFixture.addClass("package java.lang; class StringValue {}") + configure() + myFixture.complete(CompletionType.BASIC, 2) + type ' ' + checkResult() + } + + public void testPrimitiveArrayWithRBrace() throws Throwable { doTest '[' } + + public void testSuggestMembersOfStaticallyImportedClasses() throws Exception { + myFixture.addClass("""package foo; + public class Foo { + public static void foo() {} + public static void bar() {} + } + """) + doTest('\n') + } + + public void testSuggestMembersOfStaticallyImportedClassesUnqualifiedOnly() throws Exception { + def old = CodeInsightSettings.instance.SHOW_STATIC_AFTER_INSTANCE + CodeInsightSettings.instance.SHOW_STATIC_AFTER_INSTANCE = true + + try { + myFixture.addClass("""package foo; + public class Foo { + public static void foo() {} + public static void bar() {} + } + """) + configure() + assertOneElement(myFixture.getLookupElements()) + myFixture.type '\t' + checkResult() + } + finally { + CodeInsightSettings.instance.SHOW_STATIC_AFTER_INSTANCE = old + } + } + + public void testInstanceMagicMethod() throws Exception { doTest() } + + public void testNoDotOverwrite() throws Exception { doTest('.') } + + public void testStaticInnerExtendingOuter() throws Exception { doTest() } + public void testPrimitiveClass() throws Exception { doTest() } + public void testPrimitiveArrayClass() throws Exception { doTest() } + public void testPrimitiveArrayOnlyClass() throws Exception { doAntiTest() } + public void testPrimitiveArrayInAnno() throws Exception { doTest() } + + public void testSaxParserCommonPrefix() throws Exception { + myFixture.addClass("public class SAXParser {}") + myFixture.addClass("public class SAXParseException {}") + doTest() + } + + public void testNewClassAngleBracket() throws Exception { doTest('<') } + public void testNewClassAngleBracketExpected() throws Exception { doTest('<') } + public void testNewClassSquareBracket() throws Exception { doTest('[') } + + public void testMethodColon() throws Exception { doTest(':') } + public void testVariableColon() throws Exception { doTest(':') } + + public void testNoMethodsInParameterType() { + configure() + assertOrderedEquals myFixture.lookupElementStrings, "final", "float" + } + + public void testStaticallyImportedFieldsTwice() { + myFixture.addClass(""" + class Foo { + public static final int aZOO; + } + """) + myFixture.configureByText("a.java", """ + import static Foo.* + class Bar {{ + aZa + }} + """) + assertOneElement myFixture.completeBasic() + } + + public void testStatementKeywords() { + myFixture.configureByText("a.java", """ + class Bar {{ + xxx + }} + """) + myFixture.completeBasic() + final def strings = myFixture.lookupElementStrings + assertTrue 'if' in strings + assertTrue 'while' in strings + assertTrue 'do' in strings + assertTrue 'new' in strings + assertTrue 'try' in strings + + strings.remove 'new' + assertFalse 'new' in strings + } + + public void testExpressionKeywords() { + myFixture.configureByText("a.java", """ + class Bar {{ + foo(xxx) + }} + """) + myFixture.completeBasic() + final def strings = myFixture.lookupElementStrings + assertTrue 'new' in strings + } + + public void testImportAsterisk() { + myFixture.configureByText "a.java", "import java.lang." + myFixture.completeBasic() + myFixture.type '*\n' + myFixture.checkResult "import java.lang.*" + } + + public void testIntersectionTypesSOE() { + myFixture.configureByText("a.java", """ + import java.util.*; + import java.io.*; + class SOE { + public boolean setLocation(Iterable path) { + return true; + } + + public void compile(List classpath) { + setLocation(); + } + } + """) + myFixture.completeBasic() + myFixture.type '*\n' + myFixture.checkResult """ + import java.util.*; + import java.io.*; + class SOE { + public boolean setLocation(Iterable path) { + return true; + } + + public void compile(List classpath) { + setLocation(classpath); + } + } + """ + } + + public void testDontPreselectCaseInsensitivePrefixMatch() { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE + try { + myFixture.configureByText "a.java", "import java.io.*; class Foo {{ int fileSize; filx }}" + myFixture.completeBasic() + assert lookup.currentItem.lookupString == 'fileSize' + myFixture.type('e') + + assert lookup.items[0].lookupString == 'File' + assert lookup.items[1].lookupString == 'fileSize' + assert lookup.currentItem == lookup.items[1] + } + finally { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER + } + } + + public void testNoGenericsWhenChoosingWithParen() { doTest('Ma(') } + + public void testNoClosingWhenChoosingWithParenBeforeIdentifier() { doTest '(' } + + public void testPackageInMemberType() { doTest() } + + public void testClassNameDot() { doTest('.') } + + public void testClassNameDotBeforeCall() { + myFixture.addClass("package foo; public class FileInputStreamSmth {}") + myFixture.configureByFile(getTestName(false) + ".java") + PsiDocumentManager.getInstance(project).commitAllDocuments() + type '\b' + PsiDocumentManager.getInstance(project).commitAllDocuments() + myFixture.completeBasic() + assert lookup + type '.' + checkResult() + } + + public void testNoReturnAfterDot() { + configure() + assert !('return' in myFixture.lookupElementStrings) + } + + public void testDuplicateExpectedTypeInTypeArgumentList() { + configure() + def items = myFixture.lookupElements.findAll { it.lookupString == 'String' } + assert items.size() == 1 + assert LookupElementPresentation.renderElement(items[0]).tailText?.contains('java.lang') + } + + public void testSameSignature() { + configure() + myFixture.assertPreferredCompletionItems(0, 's', 's, file', 's, file, a') + lookup.setCurrentItem(lookup.items[2]) + myFixture.type('\n') + checkResult() + } + + public void testNoParenthesesAroundCallQualifier() { doTest() } + + public void testAllAssertClassesMethods() { + myFixture.addClass 'package foo; public class Assert { public static boolean foo() {} }' + myFixture.addClass 'package bar; public class Assert { public static boolean bar() {} }' + configure() + assert myFixture.lookupElementStrings == ['Assert.bar', 'Assert.foo'] + myFixture.type '\n' + checkResult() + } + + public void testCastVisually() { + configure() + def p = LookupElementPresentation.renderElement(myFixture.lookupElements[0]) + assert p.itemText == 'getValue' + assert p.itemTextBold + assert p.typeText == 'Foo' + } + + public void testSuggestEmptySet() { + configure() + assert 'emptySet' == myFixture.lookupElementStrings[0] + type '\n' + checkResult() + } + + public void testSuggestAllTypeArguments() { + configure() + assert 'String, String' == lookup.items[1].lookupString + lookup.currentItem = lookup.items[1] + type '\n' + checkResult() + + } + + public void testListArrayListCast() { doTest('\n') } + public void testInterfaceImplementationNoCast() { doTest() } + public void testStaticallyImportedMethodsBeforeExpression() { doTest('\n') } + public void testInnerChainedReturnType() { doTest() } + public void testOverwriteGenericsAfterNew() { doTest('\n') } + + private CommonCodeStyleSettings getCodeStyleSettings() { + return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE); + } + + public void testCompatibleInterfacesCast() { + configure() + assert myFixture.lookupElementStrings.containsAll(['foo', 'bar']) + } + + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java index 2e8c686948d0..f1095de8d88c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java @@ -2,6 +2,7 @@ package com.intellij.codeInsight.completion; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; import com.intellij.codeInsight.lookup.*; import com.intellij.codeInsight.lookup.impl.LookupImpl; import com.intellij.testFramework.PlatformTestUtil; @@ -16,6 +17,12 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase { setType(CompletionType.SMART); } + @Override + protected void setUp() throws Exception { + super.setUp(); + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + } + @Override protected String getTestDataPath() { return JavaTestUtil.getJavaTestDataPath(); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index 08b6d28444e3..7ea43c60e33d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -2,6 +2,7 @@ package com.intellij.codeInsight.completion; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementPresentation; @@ -21,6 +22,11 @@ import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.util.containers.ContainerUtil; public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + } @Override protected String getBasePath() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy index 1e5e49d69efb..1b2b1c43ca41 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.groovy @@ -5,10 +5,17 @@ import com.intellij.JavaTestUtil import com.intellij.ide.highlighter.JavaFileType import com.intellij.psi.codeStyle.CodeStyleSettings import com.intellij.psi.codeStyle.CodeStyleSettingsManager +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher public class VariablesCompletionTest extends LightFixtureCompletionTestCase { public static final String FILE_PREFIX = "/codeInsight/completion/variables/"; + @Override + protected void setUp() { + super.setUp() + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + } + @Override protected String getBasePath() { return JavaTestUtil.getRelativeJavaTestDataPath(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java index 23826b5d835e..aa1d75788fac 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CamelHumpMatcher.java @@ -1,92 +1,108 @@ - -package com.intellij.codeInsight.completion.impl; - -import com.intellij.codeInsight.CodeInsightSettings; -import com.intellij.codeInsight.completion.PrefixMatcher; -import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.util.registry.Registry; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.codeStyle.MinusculeMatcher; -import com.intellij.psi.codeStyle.NameUtil; -import org.jetbrains.annotations.NotNull; - -/** - * @author peter -*/ -public class CamelHumpMatcher extends PrefixMatcher { - private final MinusculeMatcher myMatcher; - private final boolean myCaseSensitive; - - public CamelHumpMatcher(@NotNull final String prefix) { - this(prefix, true); - } - - public CamelHumpMatcher(String prefix, boolean caseSensitive) { - super(prefix); - myCaseSensitive = caseSensitive; - myMatcher = createMatcher(myCaseSensitive); - } - - @Override - public boolean isStartMatch(String name) { - return myMatcher.isStartMatch(name); - } - - public boolean prefixMatches(@NotNull final String name) { - return myMatcher.matches(name); - } - - public boolean prefixMatches(@NotNull final LookupElement element) { - return prefixMatchersInternal(element, !element.isCaseSensitive()); - } - - private boolean prefixMatchersInternal(final LookupElement element, final boolean itemCaseInsensitive) { - for (final String name : element.getAllLookupStrings()) { - if (itemCaseInsensitive && StringUtil.startsWithIgnoreCase(name, myPrefix) || prefixMatches(name)) { - return true; - } - if (itemCaseInsensitive && CodeInsightSettings.ALL != CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) { - if (createMatcher(false).matches(name)) { - return true; - } - } - } - return false; - } - - @NotNull - public PrefixMatcher cloneWithPrefix(@NotNull final String prefix) { - return new CamelHumpMatcher(prefix, myCaseSensitive); - } - - private MinusculeMatcher createMatcher(final boolean caseSensitive) { - String prefix = applyMiddleMatching(myPrefix); - - if (!caseSensitive) { - return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE); - } - - switch (CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) { - case CodeInsightSettings.NONE: - return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE); - case CodeInsightSettings.FIRST_LETTER: - return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.FIRST_LETTER); - default: - return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.ALL); - } - } - - public static String applyMiddleMatching(String prefix) { - if (Registry.is("ide.completion.middle.matching") && !prefix.isEmpty() && !ApplicationManager.getApplication().isUnitTestMode()) { - return "*" + StringUtil.replace(prefix, ".", ". ").trim(); - } - return prefix; - } - - @Override - public String toString() { - return myPrefix; - } - -} + +package com.intellij.codeInsight.completion.impl; + +import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.codeInsight.completion.PrefixMatcher; +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.codeStyle.MinusculeMatcher; +import com.intellij.psi.codeStyle.NameUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; + +/** + * @author peter +*/ +public class CamelHumpMatcher extends PrefixMatcher { + private final MinusculeMatcher myMatcher; + private final boolean myCaseSensitive; + private static boolean ourForceStartMatching; + + + public CamelHumpMatcher(@NotNull final String prefix) { + this(prefix, true); + } + + public CamelHumpMatcher(String prefix, boolean caseSensitive) { + super(prefix); + myCaseSensitive = caseSensitive; + myMatcher = createMatcher(myCaseSensitive); + } + + @Override + public boolean isStartMatch(String name) { + return myMatcher.isStartMatch(name); + } + + public boolean prefixMatches(@NotNull final String name) { + return myMatcher.matches(name); + } + + public boolean prefixMatches(@NotNull final LookupElement element) { + return prefixMatchersInternal(element, !element.isCaseSensitive()); + } + + private boolean prefixMatchersInternal(final LookupElement element, final boolean itemCaseInsensitive) { + for (final String name : element.getAllLookupStrings()) { + if (itemCaseInsensitive && StringUtil.startsWithIgnoreCase(name, myPrefix) || prefixMatches(name)) { + return true; + } + if (itemCaseInsensitive && CodeInsightSettings.ALL != CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) { + if (createMatcher(false).matches(name)) { + return true; + } + } + } + return false; + } + + @NotNull + public PrefixMatcher cloneWithPrefix(@NotNull final String prefix) { + return new CamelHumpMatcher(prefix, myCaseSensitive); + } + + private MinusculeMatcher createMatcher(final boolean caseSensitive) { + String prefix = applyMiddleMatching(myPrefix); + + if (!caseSensitive) { + return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE); + } + + switch (CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) { + case CodeInsightSettings.NONE: + return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE); + case CodeInsightSettings.FIRST_LETTER: + return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.FIRST_LETTER); + default: + return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.ALL); + } + } + + public static String applyMiddleMatching(String prefix) { + if (Registry.is("ide.completion.middle.matching") && !prefix.isEmpty() && !ourForceStartMatching) { + return "*" + StringUtil.replace(prefix, ".", ". ").trim(); + } + return prefix; + } + + @Override + public String toString() { + return myPrefix; + } + + @TestOnly + public static void forceStartMatching(Disposable parent) { + ourForceStartMatching = true; + Disposer.register(parent, new Disposable() { + @Override + public void dispose() { + //noinspection AssignmentToStaticFieldFromInstanceMethod + ourForceStartMatching = false; + } + }); + } + +} diff --git a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidAnimatorDomTest.java b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidAnimatorDomTest.java index a74fc7bc66c6..05ceb48d4432 100644 --- a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidAnimatorDomTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidAnimatorDomTest.java @@ -17,6 +17,7 @@ package org.jetbrains.android.dom; import com.android.sdklib.SdkConstants; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; /** * @author Eugene.Kudelevsky @@ -46,6 +47,7 @@ public class AndroidAnimatorDomTest extends AndroidDomTest { } public void testTagNames() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); toTestCompletion("tn.xml", "tn_after.xml"); } diff --git a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java index 537ae9ad76c0..d478c81d768c 100644 --- a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java @@ -2,6 +2,7 @@ package org.jetbrains.android.dom; import com.android.sdklib.SdkConstants; import com.intellij.codeInsight.TargetElementUtilBase; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.command.WriteCommandAction; @@ -27,6 +28,7 @@ public class AndroidLayoutDomTest extends AndroidDomTest { @Override public void setUp() throws Exception { super.setUp(); + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); myFixture.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML, SdkConstants.FN_ANDROID_MANIFEST_XML); // copy mock fragment, because it is not included to old android.jar diff --git a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidManifestDomTest.java b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidManifestDomTest.java index 877c73d8c318..3bcc72b161d1 100644 --- a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidManifestDomTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidManifestDomTest.java @@ -1,6 +1,7 @@ package org.jetbrains.android.dom; import com.android.sdklib.SdkConstants; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; import org.jetbrains.android.inspections.AndroidElementNotAllowedInspection; import org.jetbrains.android.inspections.AndroidUnknownAttributeInspection; @@ -22,6 +23,7 @@ public class AndroidManifestDomTest extends AndroidDomTest { } public void testAttributeNameCompletion2() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); doTestCompletionVariants("an2.xml", "debuggable", "description"); } @@ -115,6 +117,7 @@ public class AndroidManifestDomTest extends AndroidDomTest { } public void testActivityCompletion3() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); copyFileToProject("MyActivity.java", "src/p1/p2/MyActivity.java"); copyFileToProject("MyActivity1.java", "src/p1/p2/p3/MyActivity1.java"); doTestCompletion(false); diff --git a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidValueResourcesTest.java b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidValueResourcesTest.java index 21ddd55bd6da..3ace24c5d90c 100644 --- a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidValueResourcesTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidValueResourcesTest.java @@ -17,6 +17,7 @@ package org.jetbrains.android.dom; import com.android.sdklib.SdkConstants; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.command.WriteCommandAction; @@ -81,6 +82,7 @@ public class AndroidValueResourcesTest extends AndroidDomTest { } public void testAttrFormatCompletion() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); toTestCompletion("attrs1.xml", "attrs1_after.xml"); } diff --git a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidXmlResourcesDomTest.java b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidXmlResourcesDomTest.java index 2e42b3715ccc..9563ba6c8b14 100644 --- a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidXmlResourcesDomTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidXmlResourcesDomTest.java @@ -17,6 +17,7 @@ package org.jetbrains.android.dom; import com.android.sdklib.SdkConstants; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; /** * Created by IntelliJ IDEA. @@ -46,6 +47,7 @@ public class AndroidXmlResourcesDomTest extends AndroidDomTest { } public void testPreferenceChildrenCompletion() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); toTestCompletion("pref2.xml", "pref2_after.xml"); } diff --git a/plugins/android/testSrc/org/jetbrains/android/intentions/AndroidAddStringResourceActionTest.java b/plugins/android/testSrc/org/jetbrains/android/intentions/AndroidAddStringResourceActionTest.java index 64528f23d692..bf44147c8a1f 100644 --- a/plugins/android/testSrc/org/jetbrains/android/intentions/AndroidAddStringResourceActionTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/intentions/AndroidAddStringResourceActionTest.java @@ -1,5 +1,6 @@ package org.jetbrains.android.intentions; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; import com.intellij.codeInsight.template.TemplateManager; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.openapi.actionSystem.IdeActions; @@ -36,6 +37,7 @@ public class AndroidAddStringResourceActionTest extends AndroidTestCase { } public void test1() throws IOException { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); doTest(); } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/CompletionTestBase.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/CompletionTestBase.java index bc4e7fa68c33..8b1285e1e872 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/CompletionTestBase.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/CompletionTestBase.java @@ -1,87 +1,89 @@ -package org.jetbrains.plugins.groovy.completion; - -import com.intellij.codeInsight.CodeInsightSettings; -import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.codeInsight.lookup.LookupManager; -import com.intellij.codeInsight.lookup.impl.LookupImpl; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiMember; -import com.intellij.psi.PsiPackage; -import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; -import org.jetbrains.plugins.groovy.util.TestUtils; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * @deprecated use {@link com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase} - * author ven - */ -public abstract class CompletionTestBase extends JavaCodeInsightFixtureTestCase { - - protected void doTest() { - doTest(""); - } - protected void doTest(String directory) { - final List stringList = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test"); - if (directory.length()!=0) directory += "/"; - final String fileName = directory + getTestName(true) + "." + getExtension(); - myFixture.addFileToProject(fileName, stringList.get(0)); - myFixture.configureByFile(fileName); - - boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX; - CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = false; - CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false; - - - String result = ""; - try { - myFixture.completeBasic(); - - final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myFixture.getEditor()); - if (lookup != null) { - List items = lookup.getItems(); - if (!addReferenceVariants()) { - items = ContainerUtil.findAll(items, new Condition() { - @Override - public boolean value(LookupElement lookupElement) { - final Object o = lookupElement.getObject(); - return !(o instanceof PsiMember) && !(o instanceof GrVariable) && !(o instanceof GroovyResolveResult) && !(o instanceof PsiPackage); - } - }); - } - Collections.sort(items, new Comparator() { - @Override - public int compare(LookupElement o1, LookupElement o2) { - return o1.getLookupString().compareTo(o2.getLookupString()); - } - }); - result = ""; - for (LookupElement item : items) { - result = result + "\n" + item.getLookupString(); - } - result = result.trim(); - LookupManager.getInstance(myFixture.getProject()).hideActiveLookup(); - } - - } - finally { - CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = true; - CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = old; - } - assertEquals(StringUtil.trimEnd(stringList.get(1), "\n"), result); - } - - protected String getExtension() { - return "groovy"; - } - - protected boolean addReferenceVariants() { - return true; - } -} +package org.jetbrains.plugins.groovy.completion; + +import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.LookupManager; +import com.intellij.codeInsight.lookup.impl.LookupImpl; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiMember; +import com.intellij.psi.PsiPackage; +import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; +import org.jetbrains.plugins.groovy.util.TestUtils; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +/** + * @deprecated use {@link com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase} + * author ven + */ +public abstract class CompletionTestBase extends JavaCodeInsightFixtureTestCase { + + protected void doTest() { + doTest(""); + } + protected void doTest(String directory) { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + final List stringList = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test"); + if (directory.length()!=0) directory += "/"; + final String fileName = directory + getTestName(true) + "." + getExtension(); + myFixture.addFileToProject(fileName, stringList.get(0)); + myFixture.configureByFile(fileName); + + boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX; + CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = false; + CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false; + + + String result = ""; + try { + myFixture.completeBasic(); + + final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myFixture.getEditor()); + if (lookup != null) { + List items = lookup.getItems(); + if (!addReferenceVariants()) { + items = ContainerUtil.findAll(items, new Condition() { + @Override + public boolean value(LookupElement lookupElement) { + final Object o = lookupElement.getObject(); + return !(o instanceof PsiMember) && !(o instanceof GrVariable) && !(o instanceof GroovyResolveResult) && !(o instanceof PsiPackage); + } + }); + } + Collections.sort(items, new Comparator() { + @Override + public int compare(LookupElement o1, LookupElement o2) { + return o1.getLookupString().compareTo(o2.getLookupString()); + } + }); + result = ""; + for (LookupElement item : items) { + result = result + "\n" + item.getLookupString(); + } + result = result.trim(); + LookupManager.getInstance(myFixture.getProject()).hideActiveLookup(); + } + + } + finally { + CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = true; + CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = old; + } + assertEquals(StringUtil.trimEnd(stringList.get(1), "\n"), result); + } + + protected String getExtension() { + return "groovy"; + } + + protected boolean addReferenceVariants() { + return true; + } +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GrCompletionWithLibraryTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GrCompletionWithLibraryTest.groovy index 1c6f897345d6..7b373d233536 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GrCompletionWithLibraryTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GrCompletionWithLibraryTest.groovy @@ -26,6 +26,7 @@ import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor import org.jetbrains.annotations.NotNull import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher /** * @author Maxim.Medvedev @@ -41,6 +42,12 @@ class GrCompletionWithLibraryTest extends GroovyCompletionTestBase { } }; + @Override + protected void setUp() { + super.setUp() + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + } + @NotNull @Override protected LightProjectDescriptor getProjectDescriptor() { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyCompletionTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyCompletionTest.groovy index d6f6f56011ae..bda9e191aa08 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyCompletionTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovyCompletionTest.groovy @@ -1,1390 +1,1397 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.plugins.groovy.completion; - - -import com.intellij.codeInsight.CodeInsightSettings -import com.intellij.codeInsight.completion.CompletionType -import com.intellij.codeInsight.lookup.LookupElement -import com.intellij.codeInsight.lookup.LookupElementPresentation -import com.intellij.psi.codeStyle.CodeStyleSettingsManager -import org.jetbrains.plugins.groovy.GroovyFileType -import org.jetbrains.plugins.groovy.formatter.GroovyCodeStyleSettings -import org.jetbrains.plugins.groovy.util.TestUtils - -/** - * @author Maxim.Medvedev - */ -public class GroovyCompletionTest extends GroovyCompletionTestBase { - @Override - protected String getBasePath() { - return TestUtils.testDataPath + "groovy/completion/"; - } - - @Override - protected void tearDown() { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER - super.tearDown() - } - - public void testFinishMethodWithLParen() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "getBar", "getClass", "getFoo"); - myFixture.type('('); - myFixture.checkResultByFile(getTestName(false) + "_after.groovy"); - } - - public void testNamedParametersForApplication() { - doVariantableTest("abx", "aby"); - } - - public void testNamedParametersForMethodCall() { - doVariantableTest("abx", "aby"); - } - - public void testNamedParameters1() { - doVariantableTest("abx", "aby"); - } - - public void testNamedParameters2() { - doVariantableTest("abx", "aby"); - } - - public void testNamedParametersInMap1() { - doVariantableTest("abx", "aby"); - } - - public void testNamedParametersInMap2() { - doVariantableTest("abx", "aby"); - } - - public void testNamedParametersInSecondMap1() { - doVariantableTest(); - } - - public void testNamedParametersInSecondMap2() { - doVariantableTest(); - } - - public void testNamedParametersExcludeExisted() { - doVariantableTest("abx", "aby"); - } - - public void testNamedParametersExcludeExisted2() { - doVariantableTest("abx", "aby", "abz"); - } - - public void testNamedParametersExcludeExistedMap() { - doVariantableTest("abx", "aby"); - } - - public void testNamedParametersForNotMap() { - doBasicTest(); - } - - public void testNamedParametersForConstructorCall() { - doVariantableTest("hahaha", "hohoho", "hashCode"); - } - - public void testUnfinishedMethodTypeParameter() { - doVariantableTest("MyParameter", "MySecondParameter"); - } - - public void testUnfinishedMethodTypeParameter2() { - doVariantableTest("MyParameter", "MySecondParameter"); - } - - public void testInstanceofHelpsDetermineType() { - doBasicTest(); - } - - public void testInstanceofHelpsDetermineTypeInBinaryAnd() { doBasicTest() } - public void testInstanceofHelpsDetermineTypeInBinaryOr() { doBasicTest() } - - public void testNotInstanceofDoesntHelpDetermineType() { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); - } - - public void testNotInstanceofDoesntHelpDetermineType2() { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); - } - - public void testTypeParameterCompletion() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "put", "putAll"); - } - - public void testCatchClauseParameter() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "getCause", "getClass"); - } - - public void testFieldSuggestedOnce1() { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); - assertNull(myFixture.getLookupElements()); - } - - public void testFieldSuggestedOnce2() { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); - assertNull(myFixture.getLookupElements()); - } - - public void testFieldSuggestedOnce3() { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); - assertNull(myFixture.getLookupElements()); - } - - public void testFieldSuggestedOnce4() { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); - assertNull(myFixture.getLookupElements()); - } - - public void testFieldSuggestedOnce5() { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); - assertNull(myFixture.getLookupElements()); - } - - public void testFieldSuggestedInMethodCall() { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + "_after.groovy"); - } - - public void testMethodParameterNoSpace() { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + "_after.groovy"); - } - - public void testGroovyDocParameter() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "xx", "xy"); - } - - public void testInnerClassExtendsImplementsCompletion() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "extends", "implements"); - } - - public void testInnerClassCompletion() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "Inner1", "Inner2"); - } - - public void testQualifiedThisCompletion() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "foo1", "foo2"); - } - - public void testQualifiedSuperCompletion() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "foo1", "foo2"); - } - - public void testThisKeywordCompletionAfterClassName1() { - doBasicTest(); - } - - public void testThisKeywordCompletionAfterClassName2() { - doBasicTest(); - } - - public void testWhileInstanceof() { doBasicTest() } - - public void testCompletionInParameterListInClosableBlock() { doBasicTest(); } - public void testCompletionInParameterListInClosableBlock3() { doBasicTest(); } - - public void testCompletionInParameterListInClosableBlock2() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "aDouble"); - } - - public void testStaticMemberFromInstanceContext() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "var1", "var2"); - } - - public void testInstanceMemberFromStaticContext() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "var3", "var4"); - } - - public void testTypeCompletionInVariableDeclaration1() { - doBasicTest(); - } - - public void testTypeCompletionInVariableDeclaration2() { - doBasicTest(); - } - - public void testTypeCompletionInParameter() { - doBasicTest(); - } - - public void testGStringConcatenationCompletion() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "substring", "substring", "subSequence"); - } - - public void testPropertyWithSecondUpperLetter() { - myFixture.testCompletionVariants(getTestName(false) + ".groovy", "geteMail", "getePost"); - } - - public void testInferredVariableType() { - myFixture.configureByText "a.groovy", "def foo = 'xxx'; fo" - def presentation = new LookupElementPresentation() - myFixture.completeBasic()[0].renderElement(presentation) - assert presentation.itemText == 'foo' - assert presentation.typeText == 'String' - } - - public void testSubstitutedMethodType() { - myFixture.configureByText "a.groovy", "new HashMap().putx" - def presentation = new LookupElementPresentation() - myFixture.completeBasic()[0].renderElement(presentation) - assert presentation.itemText == 'put' - assert presentation.tailText == '(String key, Integer value)' - assert presentation.typeText == 'Integer' - } - - public void testIntCompletionInPlusMethod() {doBasicTest();} - public void testIntCompletionInGenericParameter() {doBasicTest();} - - public void testWhenSiblingIsStaticallyImported_Method() { - myFixture.addFileToProject "foo/Foo.groovy", """package foo - class Foo { - static def abcMethod() {} - static def defMethod() {} - } - """ - - myFixture.configureByText("a.groovy", """ - import static foo.Foo.abcMethod - - abcMethod() - defM - """) - myFixture.completeBasic() - myFixture.checkResult """ - import static foo.Foo.abcMethod - import static foo.Foo.defMethod - - abcMethod() - defMethod() - """ - } - - public void testWhenSiblingIsStaticallyImported_Field() { - myFixture.addFileToProject "foo/Foo.groovy", """package foo - class Foo { - static def abcField = 4 - static def defField = 2 - } - """ - - myFixture.configureByText("a.groovy", """ - import static foo.Foo.abcField - - println abcField - defF - """) - myFixture.completeBasic() - myFixture.checkResult """ - import static foo.Foo.abcField - import static foo.Foo.defField - - println abcField - defField - """ - } - - public void testCompletionNamedArgumentWithoutSpace() { - def settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(GroovyCodeStyleSettings.class) - settings.SPACE_IN_NAMED_ARGUMENT = false - - try { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ - class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg11) } - } - """) - myFixture.completeBasic() - myFixture.checkResult """ - class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg111:) } - } - """ - } - finally { - settings.SPACE_IN_NAMED_ARGUMENT = true - } - } - - public void testCompletionNamedArgument1() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg111: 1, arg: 2, arg333: 3) } -} -""") - myFixture.completeBasic() - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg111: 1, arg222: 2, arg333: 3) } -} -""" - } - - public void testCompletionNamedArgument2() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m arg111: 1, arg: 2, arg333: 3 } -} -""") - myFixture.completeBasic() - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m arg111: 1, arg222: 2, arg333: 3 } -} -""" - } - - public void testCompletionNamedArgument3() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m arg1 } -} -""") - myFixture.completeBasic() - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m arg111: } -} -""" - } - - public void testCompletionNamedArgument4() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m (arg1 zzz) } -} -""") - myFixture.completeBasic() - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m (arg111: , zzz) } -} -""" - } - - public void testCompletionNamedArgument5() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m (arg1, { - out << "asdasdas" - } ) } -} -""") - myFixture.completeBasic() - - myFixture.checkResult(""" -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m (arg111: , { - out << "asdasdas" - } ) } -} -""") - } - - public void testCompletionNamedArgument6() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m([arg1])} -} -""") - myFixture.completeBasic() - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m([arg111: ])} -} -""" - } - - public void testCompletionNamedArgument7() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg1)} -} -""") - myFixture.completeBasic() - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg111: )} -} -""" - } - - public void testCompletionNamedArgument8() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg1,)} -} -""") - myFixture.completeBasic() - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg111: ,)} -} -""" - } - - public void testCompletionNamedArgumentWithDD() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg)} -} -""") - myFixture.completeBasic() - myFixture.type(':') - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg111: )} -} -""" - } - - public void testCompletionNamedArgumentReplace() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg222: 'a')} -} -""") - myFixture.completeBasic() - myFixture.type("1\t") - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg111: 'a')} -} -""" - } - - public void testCompletionNamedArgumentWithSpace() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg)} -} -""") - myFixture.completeBasic() - myFixture.type(' ') - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { m(arg111: )} -} -""" - } - - public void testCompletionNamedArgumentWithNewLine1() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { - m(arg - arg222: 222, - ) - } -} -""") - myFixture.completeBasic() - myFixture.type(' ') - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { - m(arg111: , - arg222: 222, - ) - } -} -""" - } - - public void testCompletionNamedArgumentWithNewLine2() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { - m(arg, - arg222: 222, - ) - } -} -""") - myFixture.completeBasic() - myFixture.type(':') - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { - m(arg111: , - arg222: 222, - ) - } -} -""" - } - - public void testCompletionNamedArgumentWithNewLine4() { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { - m(arg - , arg222: 222, - arg333: 333, - ) - } -} -""") - myFixture.completeBasic() - - myFixture.checkResult """ -class A { - public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } - { - m(arg111: - , arg222: 222, - arg333: 333, - ) - } -} -""" - } - - public void testSpreadOperator() { - doVariantableTest("foo1", "foo2") - } - - public void testGrvy945() { - def file = myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """class MyCategory { - static def plus(MyCategory t, MyCat) { - } -}""") - LookupElement[] lookupElements = myFixture.completeBasic() - assertNull(lookupElements) - - assertEquals """class MyCategory { - static def plus(MyCategory t, MyCategory) { - } -}""", file.text - } - - void configure(String text) { - myFixture.configureByText("a.groovy", text) - } - - public void testGenericsAfterNew() { - configure "List l = new ArrLi" - myFixture.completeBasic() - myFixture.type '\n' - myFixture.checkResult "List l = new ArrayList()" - } - - public void testAfterNewWithInner() { - myFixture.addClass """class Zzoo { - static class Impl {} - }""" - configure "Zzoo l = new Zz" - myFixture.completeBasic() - myFixture.type '\n' - myFixture.checkResult "Zzoo l = new Zzoo()" - } - - public void testNothingAfterIntegerLiteral() { - configure "2f" - assertEmpty myFixture.completeBasic() - } - - public void testPackagedContainingClassNameAfterStatic() { - myFixture.configureFromExistingVirtualFile(myFixture.addFileToProject("foo/cls.groovy", """ - package foo - class Zzzzzzz { - static Zzz - } - """).virtualFile) - myFixture.completeBasic() - assert myFixture.editor.document.text.contains("static Zzzzzzz") - } - - public void testDontCompleteSubpackageOfImplicitlyImported() { - myFixture.addFileToProject "A.groovy", """ -in""" - myFixture.testCompletionVariants "A.groovy", "int", "interface" //don't complete 'instrument' from 'java.lang' - } - - - public void testEatingThisReference() { - configure "def x = []; x. this" - myFixture.completeBasic() - myFixture.type 'ad\t' - myFixture.checkResult "def x = []; x.add() this" - } - - public void testEatingClosingParenthesis() { - checkCompletion """ -def xxxx = [] -def xxxy = [] -foo((xx):2) -""", '\t', """ -def xxxx = [] -def xxxy = [] -foo((xxxx):2) -""" - } - - public void testDontAddStaticImportSecondTime() { - configure """import static java.lang.String.format -form""" - - myFixture.completeBasic() - myFixture.checkResult """import static java.lang.String.format -format()""" - } - - public void testImportAsterisk() { - myFixture.configureByText "a.groovy", "import java.lang." - myFixture.completeBasic() - myFixture.type '*\n' - myFixture.checkResult "import java.lang.*" - } - - public void testNoDotsInImport() { - myFixture.configureByText "a.groovy", "import java." - myFixture.completeBasic() - myFixture.type 'lan\n' - myFixture.checkResult "import java.lang" - } - - public void testInvalidScriptClass() { - myFixture.addFileToProject("b.groovy", "//comment") - myFixture.configureByText "a.groovy", "def b" - myFixture.completeBasic() - myFixture.checkResult "def b" - } - - public void testSpacesAroundEq() { - myFixture.configureByText "a.groovy", "int xxx, xxy; xx" - myFixture.completeBasic() - myFixture.type '=' - myFixture.checkResult "int xxx, xxy; xxx = " - } - - public void testOnlyAnnotationsAfterAt() { - myFixture.addClass "class AbcdClass {}; @interface AbcdXAnno {}" - myFixture.configureByText "a.groovy", "@Abcd class A {}" - myFixture.completeBasic() - assert myFixture.lookupElementStrings[0] == 'AbcdXAnno' - } - - public void testOnlyAnnotationsAfterAtInMethodParameters() { - myFixture.addClass "class AbcdClass {}; @interface AbcdAnno {}" - myFixture.configureByText "a.groovy", "def foo(@Abcd ) {}" - myFixture.completeBasic() - assert myFixture.lookupElementStrings[0] == 'AbcdAnno' - } - - public void testNoCompletionInClassBodyComments() { - myFixture.configureByText "a.groovy", "class Foo { /* protec */ }" - assertEmpty(myFixture.completeBasic()) - } - - public void testNoCompletionInCodeBlockComments() { - myFixture.configureByText "a.groovy", "def Foo() { /* whil */ }" - assertEmpty(myFixture.completeBasic()) - } - - public void testParenthesesForExpectedClassTypeRegardlessInners() { - myFixture.addClass "class Fooooo { interface Bar {} }" - myFixture.configureByText "a.groovy", "Fooooo f = new Foo" - myFixture.completeBasic() - assert myFixture.lookupElementStrings == ['Fooooo', 'Fooooo.Bar'] - myFixture.type '\n' - myFixture.checkResult "Fooooo f = new Fooooo()" - } - - public void testParenthesesForUnexpectedClassTypeRegardingInners() { - myFixture.addClass "class Fooooo { interface Bar {} }" - myFixture.configureByText "a.groovy", "Fooooo.Bar f = new Foo" - myFixture.completeBasic() - assert myFixture.lookupElementStrings == ['Fooooo', 'Fooooo.Bar'] - myFixture.type '\n' - myFixture.checkResult "Fooooo.Bar f = new Fooooo()" - } - - public void testOnlyExceptionsInCatch() { - myFixture.addClass "package foo; public class AbcdClass {}; public class AbcdException extends Throwable {}" - myFixture.configureByText "a.groovy", "try {} catch (Abcd" - myFixture.completeBasic() - myFixture.type('\n') - myFixture.checkResult """import foo.AbcdException - -try {} catch (AbcdException""" - } - - public void testOnlyExceptionsInCatch2() { - myFixture.addClass "class AbcdClass {}; class AbcdException extends Throwable {}" - myFixture.configureByText "a.groovy", "try {} catch (Abcd e) {}" - myFixture.completeBasic() - assert myFixture.lookupElementStrings[0] == 'AbcdException' - myFixture.type('\n') - myFixture.checkResult "try {} catch (AbcdException e) {}" - } - - public void testTopLevelClassesFromPackaged() { - myFixture.addClass "public class Fooooo {}" - final text = "package foo; class Bar { Fooo }" - def file = myFixture.addFileToProject("foo/Bar.groovy", text) - myFixture.configureFromExistingVirtualFile file.virtualFile - assertEmpty myFixture.completeBasic() - myFixture.checkResult text - } - - public void testLocalVarOverlaysField() { - myFixture.configureByText "a.groovy", """ -class A { - def myVar = 2 - - def foo() { - def myVar = 3 - print myVa - } -}""" - myFixture.completeBasic() - - myFixture.checkResult """ -class A { - def myVar = 2 - - def foo() { - def myVar = 3 - print myVar - } -}""" - - } - - public void testParenthesesInMethodCompletion() { - myFixture.configureByText "a.groovy", """ -def foo(def a) {2} -return fo""" - myFixture.completeBasic() - myFixture.checkResult """ -def foo(def a) {2} -return foo()""" - } - - public void testFinishClassNameWithSquareBracket() { - myFixture.addClass("class AbcdClass {}; class AbcdeClass {}") - checkCompletion("Abcd", '[', "AbcdClass[]") - } - - public void testFinishClassNameWithSquareBracketAfterNew() { - myFixture.addClass("class AbcdClass {}; class AbcdeClass {}") - checkCompletion("new Abcd", '[', "new AbcdClass[]") - } - - public void testFinishMethodNameWithSquareBracket() { - myFixture.addClass("""class AbcdClass { - static int[] foo(int x){} - static int[] fobar(){} - }""") - checkCompletion("AbcdClass.fo", '[', "AbcdClass.fobar()[]") - } - - public void testFinishVariableNameWithSquareBracket() { - checkCompletion("int[] fooo, foobar; foo", '[', "int[] fooo, foobar; foobar[]") - } - - public void testFinishClassNameWithLt() { - myFixture.addClass("class AbcdClass {}; class AbcdeClass {}") - checkCompletion("Abcd", '<', "AbcdClass<>") - } - - public void testFinishClassNameWithLtAfterNew() { - myFixture.addClass("class AbcdClass {}; class AbcdeClass {}") - checkCompletion("new Abcd", '<', "new AbcdClass<>()") - } - - public void testMapKeysUsedInFile() { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE - doVariantableTest 'foo1', 'foo3', 'foo4', 'Foo5', 'Foo7' - } - - public void testNoClassesAsMapKeys() { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE - doVariantableTest() - } - - public void testNamedArgsUsedInFile() { - myFixture.configureByFile(getTestName(false) + ".groovy"); - doVariantableTest 'false', 'foo2', 'float', 'foo1', 'foo3', 'foo4', 'foo5' - } - - public void testSuggestMembersOfExpectedType() { - myFixture.addClass("enum Foo { aaaaaaaaaaaaaaaaaaaaaa, bbbbbb }") - checkCompletion("Foo f = aaaaaaaa", '\n', "Foo f = Foo.aaaaaaaaaaaaaaaaaaaaaa") - } - - public void testFieldTypeAfterModifier() { - myFixture.addClass("package bar; public class Fooooooooooo { }") - checkCompletion ''' -class A { - private Foooo -}''', '\n', '''import bar.Fooooooooooo - -class A { - private Fooooooooooo -}''' - } - - public void testSuperClassProperty() { - checkSingleItemCompletion """ -class A { def foooooooooooo } - -class B extends A { - def bar() { - foooo - } -} -""", """ -class A { def foooooooooooo } - -class B extends A { - def bar() { - foooooooooooo - } -} -""" - } - - public void testDoubleSpace() { - checkCompletion "assex", ' ', 'assert x' - } - - public void testPreferInstanceof() { - caseSensitiveNone() - - configure ''' -class Fopppp { - def foo() { - assert x ins - } -} -class Instantiation {} -''' - myFixture.completeBasic() - assertEquals 'instanceof', myFixture.lookupElementStrings[0] - } - - public void testForFinal() { - assert doContainsTest('final', ''' -class Fopppp { - def foo() { - for(fin - } -} -''') - } - - public void testExcludeStringBuffer() { - assert doContainsTest('StringBuffer', 'StringBufff') - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = [StringBuffer.name] as String[] - try { - assert !doContainsTest('StringBuffer', 'StringBufff') - } - finally { - CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] - } - } - - private doContainsTest(String itemToCheck, String text) { - myFixture.configureByText "a.groovy", text - - final LookupElement[] completion = myFixture.completeBasic() - return completion.find {println it.lookupString;itemToCheck == it.lookupString} - } - - public void testWordCompletionInLiterals() { - checkSingleItemCompletion('def foo = "fo"', 'def foo = "foo"') - } - public void testWordCompletionInLiterals2() { - checkSingleItemCompletion(''' -println "abcd" -"a" -''', ''' -println "abcd" -"abcd" -''') - } - - public void testWordCompletionInComments() { - checkSingleItemCompletion(''' -println "abcd" -// a" -''', ''' -println "abcd" -// abcd" -''') - } - - public void testNoModifiersAfterDef() { - checkSingleItemCompletion 'def priv', 'def priv' - } - - public void testIfSpace() { checkCompletion 'int iff; if', ' ', "int iff; if " } - - public void testIfParenthesis() { checkCompletion 'int iff; if', '(', "int iff; if ()" } - - public void testEnumPropertyType() { - checkSingleItemCompletion 'enum Foo {a,b; static List>', "enum Foo {a,b; static List>" - } - - public void testEnumPropertyType2() { - checkSingleItemCompletion 'enum Foo {a,b; static List', "enum Foo {a,b; static List" - } - - public void testShowAccessor() { - assertNotNull doContainsTest("getFoo", """ -class MyClass { - def foo -} - -def a = new MyClass() -a.g -""") - } - - public void testContinue() { - assertNotNull doContainsTest("continue", """ -def conti = 4 -while(true) { - if (tst) cont -}""") - - } - - public void testPreferParametersToClasses() { - caseSensitiveNone() - - myFixture.configureByText "a.groovy", "def foo(stryng) { println str }" - myFixture.completeBasic() - assertEquals 'stryng', myFixture.lookupElementStrings[0] - } - - private def caseSensitiveNone() { - CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE - } - - public void testFieldVsPackage() { - myFixture.addFileToProject 'aaa/bbb/Foo.groovy', 'package aaa.bbb; class Foo{}' - def file = myFixture.addFileToProject('aaa/bar.groovy', ''' -package aaa - -import aaa.* - -class X { - def bbb = 'text' - - def foo() { - bbb.toString() - } -} -''') - myFixture.configureFromExistingVirtualFile file.virtualFile - myFixture.completeBasic() - assertFalse(myFixture.lookupElementStrings.contains('Foo')) - } - - public void testFieldVsPackage2() { - myFixture.addFileToProject 'aaa/bbb/Foo.groovy', 'package aaa.bbb; class Foo{}' - def file = myFixture.addFileToProject('aaa/bar.groovy', ''' -package aaa - -import aaa.* - -class X { - def bbb = 'text' - - def foo() { - bbb. - } -} -''') - myFixture.configureFromExistingVirtualFile file.virtualFile - myFixture.completeBasic() - assertFalse(myFixture.lookupElementStrings.contains('Foo')) - } - - public void testClassNameBeforeParentheses(){ - doBasicTest() - } - - public void testNewClassGenerics() { - checkSingleItemCompletion 'new ArrayLi', 'new ArrayList<>()' - } - - public void testInnerClassStart() { - checkSingleItemCompletion 'class Foo { cl }', 'class Foo { class }' - } - - public void testPropertyBeforeAccessor() { - doVariantableTest 'soSe', 'setSoSe' - } - - public void testSortOrder0() { - doVariantableTest 'se', 'setProperty', 'setMetaClass', 'setSe' - } - - public void testPrimitiveCastOverwrite() { - checkCompletion 'byte v1 = (byte) 0', '\t', 'byte v1 = (byte) 0' - } - - public void testInitializerMatters() { - myFixture.configureByText("a.groovy", "class Foo {{ String fx = getFoo(); }; String getFoo() {}; }"); - myFixture.completeBasic() - assertOrderedEquals(myFixture.lookupElementStrings, ["foo"]) - } - - public void testFieldInitializerMatters() { - myFixture.configureByText("a.groovy", "class Foo { String fx = getFoo(); String getFoo() {}; }"); - myFixture.completeBasic() - assertOrderedEquals(myFixture.lookupElementStrings, ["foo"]) - } - - public void testAccessStaticViaInstanceSecond() { - myFixture.configureByText("a.groovy", """ -public class KeyVO { - { this.fox } - static void foo() {} -} -"""); - myFixture.complete(CompletionType.BASIC, 1) - assert !myFixture.lookupElementStrings - myFixture.complete(CompletionType.BASIC, 2) - assertOrderedEquals(myFixture.lookupElementStrings, ["foo"]) - } - - public void testNoRepeatingModifiers() { - myFixture.configureByText 'a.groovy', 'class A { public static }' - myFixture.completeBasic() - assert !('public' in myFixture.lookupElementStrings) - assert !('static' in myFixture.lookupElementStrings) - assert 'final' in myFixture.lookupElementStrings - } - - public void testSpaceTail() { - checkCompletion 'class A ArrayList {}', ' ', 'class A extends ArrayList {}' - checkCompletion 'class A ArrayList {}', '\n', 'class A extends ArrayList {}' - checkSingleItemCompletion 'class Foo impl {}', 'class Foo implements {}' - } - - public void testAmbiguousClassQualifier() { - myFixture.addClass("package foo; public class Util { public static void foo() {} }") - myFixture.addClass("package bar; public class Util { public static void bar() {} }") - myFixture.configureByText 'a.groovy', 'Util.' - myFixture.completeBasic() - assertOrderedEquals myFixture.lookupElementStrings[0..1] , ['Util.bar', 'Util.foo'] - - def presentation = LookupElementPresentation.renderElement(myFixture.lookupElements[0]) - assertEquals 'Util.bar', presentation.itemText - assertEquals '() (bar)', presentation.tailText - assert !presentation.tailGrayed - - myFixture.type 'f\n' - myFixture.checkResult '''import foo.Util - -Util.foo()''' - } - - public void testUseDescendantStaticImport() { doBasicTest() } - - public void testPreferInterfacesInImplements() { - myFixture.addClass('interface FooIntf {}') - myFixture.addClass('class FooClass {}') - doVariantableTest('FooIntf', 'FooClass') - } - - public void testPropertyChain() { doBasicTest() } - - public void testMethodPointer() { - doBasicTest('''\ -class Base { - def prefixMethod(){} - def prefixField -} - -new Base().&prefix''', '''\ -class Base { - def prefixMethod(){} - def prefixField -} - -new Base().&prefixMethod''') - } - - private void doBasicTest(String before, String after) { - myFixture.configureByText('_a.groovy', before) - myFixture.completeBasic() - assertNull(myFixture.lookupElements) - myFixture.checkResult(after) - } - - public void testFieldPointer() { - doBasicTest '''\ -class Base { - def prefixMethod(){} - def prefixField -} - -new Base().@prefix''', '''\ -class Base { - def prefixMethod(){} - def prefixField -} - -new Base().@prefixField''' - } - - public void testPrivateFieldOnSecondInvocation() { - myFixture.configureByText('_a.groovy', '''\ -class Base { - private int field1 -} - -new Base().fiex''') - myFixture.complete(CompletionType.BASIC, 2) - assert myFixture.lookupElementStrings == ['field1'] - } - - public void testForIn() { - assert doContainsTest('in', 'for (int i i') - assert doContainsTest('in', 'for (i i') - } - - public void testReturnInVoidMethod() { - doBasicTest('''\ -void foo() { - retur -} -''', '''\ -void foo() { - return -} -''') - } - - public void testReturnInNotVoidMethod() { - doBasicTest('''\ -String foo() { - retur -} -''', '''\ -String foo() { - return -} -''') - } - - void testInferArgumentTypeFromMethod1() { - doBasicTest('''\ -def bar(String s) {} - -def foo(Integer a) { - bar(a) - a.subSequen() -} -''', '''\ -def bar(String s) {} - -def foo(Integer a) { - bar(a) - a.subSequence() -} -''') - } - - void testInferArgumentTypeFromMethod2() { - doBasicTest('''\ -def bar(String s) {} - -def foo(Integer a) { - while(true) { - bar(a) - a.subSequen() - } -} -''', '''\ -def bar(String s) {} - -def foo(Integer a) { - while(true) { - bar(a) - a.subSequence() - } -} -''') - } - - void testInferArgumentTypeFromMethod3() { - doBasicTest('''\ -def bar(String s) {} - -def foo(Integer a) { - bar(a) - print a - a.subSequen() -} -''', '''\ -def bar(String s) {} - -def foo(Integer a) { - bar(a) - print a - a.subSequence() -} -''') - } - - void testInferArgumentTypeFromMethod4() { - doBasicTest('''\ -def bar(String s) {} - -def foo(Integer a) { - while(true) { - bar(a) - print a - a.subSequen() - } -} -''', '''\ -def bar(String s) {} - -def foo(Integer a) { - while(true) { - bar(a) - print a - a.subSequence() - } -} -''') - } - - void testSuperExtendsInTypeParams() { - myFixture.configureByText("_.groovy", '''\ -def foo(List)'''); - myFixture.complete(CompletionType.BASIC); - assertOrderedEquals(myFixture.lookupElementStrings, "extends", "super"); - } - - void testSuperExtendsInTypeParams2() { - myFixture.configureByText("_.groovy", '''\ -def foo(List> list)'''); - myFixture.complete(CompletionType.BASIC); - assertOrderedEquals(myFixture.lookupElementStrings, "extends", "super"); - } - - void testMapDontCompleteProperties() { - myFixture.configureByText("_.groovy", '''\ -def map = [1:2] -print map.metc -'''); - myFixture.complete(CompletionType.BASIC); - assertEmpty myFixture.getLookupElements() - } - - void testAnnotationCompletion0() { - myFixture.configureByText('_.groovy', '''\ -@interface A { - String fooo() -} - -@A(foo) -def bar(){}''') - myFixture.complete(CompletionType.BASIC) - myFixture.checkResult('''\ -@interface A { - String fooo() -} - -@A(fooo = ) -def bar(){}''') - } - - void testAnnotationCompletion1() { - myFixture.configureByText('_.groovy', '''\ -@interface A { - String fooo() -} - -def abcde() {} - -@A(abc) -def bar(){}''') - myFixture.complete(CompletionType.BASIC) - myFixture.checkResult('''\ -@interface A { - String fooo() -} - -def abcde() {} - -@A(abcde()) -def bar(){}''') - } - - void testAnnotationCompletion2() { - myFixture.configureByText('_.groovy', '''\ -@interface A { - String fooo() - String fooo1() -} - -@A(foo = 'a') -def bar(){}''') - myFixture.complete(CompletionType.BASIC) - assertOrderedEquals(myFixture.lookupElementStrings, ['fooo', 'fooo1']) - } - +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.plugins.groovy.completion; + + +import com.intellij.codeInsight.CodeInsightSettings +import com.intellij.codeInsight.completion.CompletionType +import com.intellij.codeInsight.lookup.LookupElement +import com.intellij.codeInsight.lookup.LookupElementPresentation +import com.intellij.psi.codeStyle.CodeStyleSettingsManager +import org.jetbrains.plugins.groovy.GroovyFileType +import org.jetbrains.plugins.groovy.formatter.GroovyCodeStyleSettings +import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher + +/** + * @author Maxim.Medvedev + */ +public class GroovyCompletionTest extends GroovyCompletionTestBase { + @Override + protected String getBasePath() { + return TestUtils.testDataPath + "groovy/completion/"; + } + + @Override + protected void setUp() { + super.setUp() + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + } + + @Override + protected void tearDown() { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER + super.tearDown() + } + + public void testFinishMethodWithLParen() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "getBar", "getClass", "getFoo"); + myFixture.type('('); + myFixture.checkResultByFile(getTestName(false) + "_after.groovy"); + } + + public void testNamedParametersForApplication() { + doVariantableTest("abx", "aby"); + } + + public void testNamedParametersForMethodCall() { + doVariantableTest("abx", "aby"); + } + + public void testNamedParameters1() { + doVariantableTest("abx", "aby"); + } + + public void testNamedParameters2() { + doVariantableTest("abx", "aby"); + } + + public void testNamedParametersInMap1() { + doVariantableTest("abx", "aby"); + } + + public void testNamedParametersInMap2() { + doVariantableTest("abx", "aby"); + } + + public void testNamedParametersInSecondMap1() { + doVariantableTest(); + } + + public void testNamedParametersInSecondMap2() { + doVariantableTest(); + } + + public void testNamedParametersExcludeExisted() { + doVariantableTest("abx", "aby"); + } + + public void testNamedParametersExcludeExisted2() { + doVariantableTest("abx", "aby", "abz"); + } + + public void testNamedParametersExcludeExistedMap() { + doVariantableTest("abx", "aby"); + } + + public void testNamedParametersForNotMap() { + doBasicTest(); + } + + public void testNamedParametersForConstructorCall() { + doVariantableTest("hahaha", "hohoho", "hashCode"); + } + + public void testUnfinishedMethodTypeParameter() { + doVariantableTest("MyParameter", "MySecondParameter"); + } + + public void testUnfinishedMethodTypeParameter2() { + doVariantableTest("MyParameter", "MySecondParameter"); + } + + public void testInstanceofHelpsDetermineType() { + doBasicTest(); + } + + public void testInstanceofHelpsDetermineTypeInBinaryAnd() { doBasicTest() } + public void testInstanceofHelpsDetermineTypeInBinaryOr() { doBasicTest() } + + public void testNotInstanceofDoesntHelpDetermineType() { + myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); + } + + public void testNotInstanceofDoesntHelpDetermineType2() { + myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); + } + + public void testTypeParameterCompletion() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "put", "putAll"); + } + + public void testCatchClauseParameter() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "getCause", "getClass"); + } + + public void testFieldSuggestedOnce1() { + myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); + assertNull(myFixture.getLookupElements()); + } + + public void testFieldSuggestedOnce2() { + myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); + assertNull(myFixture.getLookupElements()); + } + + public void testFieldSuggestedOnce3() { + myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); + assertNull(myFixture.getLookupElements()); + } + + public void testFieldSuggestedOnce4() { + myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); + assertNull(myFixture.getLookupElements()); + } + + public void testFieldSuggestedOnce5() { + myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + ".groovy"); + assertNull(myFixture.getLookupElements()); + } + + public void testFieldSuggestedInMethodCall() { + myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + "_after.groovy"); + } + + public void testMethodParameterNoSpace() { + myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + "_after.groovy"); + } + + public void testGroovyDocParameter() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "xx", "xy"); + } + + public void testInnerClassExtendsImplementsCompletion() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "extends", "implements"); + } + + public void testInnerClassCompletion() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "Inner1", "Inner2"); + } + + public void testQualifiedThisCompletion() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "foo1", "foo2"); + } + + public void testQualifiedSuperCompletion() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "foo1", "foo2"); + } + + public void testThisKeywordCompletionAfterClassName1() { + doBasicTest(); + } + + public void testThisKeywordCompletionAfterClassName2() { + doBasicTest(); + } + + public void testWhileInstanceof() { doBasicTest() } + + public void testCompletionInParameterListInClosableBlock() { doBasicTest(); } + public void testCompletionInParameterListInClosableBlock3() { doBasicTest(); } + + public void testCompletionInParameterListInClosableBlock2() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "aDouble"); + } + + public void testStaticMemberFromInstanceContext() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "var1", "var2"); + } + + public void testInstanceMemberFromStaticContext() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "var3", "var4"); + } + + public void testTypeCompletionInVariableDeclaration1() { + doBasicTest(); + } + + public void testTypeCompletionInVariableDeclaration2() { + doBasicTest(); + } + + public void testTypeCompletionInParameter() { + doBasicTest(); + } + + public void testGStringConcatenationCompletion() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "substring", "substring", "subSequence"); + } + + public void testPropertyWithSecondUpperLetter() { + myFixture.testCompletionVariants(getTestName(false) + ".groovy", "geteMail", "getePost"); + } + + public void testInferredVariableType() { + myFixture.configureByText "a.groovy", "def foo = 'xxx'; fo" + def presentation = new LookupElementPresentation() + myFixture.completeBasic()[0].renderElement(presentation) + assert presentation.itemText == 'foo' + assert presentation.typeText == 'String' + } + + public void testSubstitutedMethodType() { + myFixture.configureByText "a.groovy", "new HashMap().putx" + def presentation = new LookupElementPresentation() + myFixture.completeBasic()[0].renderElement(presentation) + assert presentation.itemText == 'put' + assert presentation.tailText == '(String key, Integer value)' + assert presentation.typeText == 'Integer' + } + + public void testIntCompletionInPlusMethod() {doBasicTest();} + public void testIntCompletionInGenericParameter() {doBasicTest();} + + public void testWhenSiblingIsStaticallyImported_Method() { + myFixture.addFileToProject "foo/Foo.groovy", """package foo + class Foo { + static def abcMethod() {} + static def defMethod() {} + } + """ + + myFixture.configureByText("a.groovy", """ + import static foo.Foo.abcMethod + + abcMethod() + defM + """) + myFixture.completeBasic() + myFixture.checkResult """ + import static foo.Foo.abcMethod + import static foo.Foo.defMethod + + abcMethod() + defMethod() + """ + } + + public void testWhenSiblingIsStaticallyImported_Field() { + myFixture.addFileToProject "foo/Foo.groovy", """package foo + class Foo { + static def abcField = 4 + static def defField = 2 + } + """ + + myFixture.configureByText("a.groovy", """ + import static foo.Foo.abcField + + println abcField + defF + """) + myFixture.completeBasic() + myFixture.checkResult """ + import static foo.Foo.abcField + import static foo.Foo.defField + + println abcField + defField + """ + } + + public void testCompletionNamedArgumentWithoutSpace() { + def settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(GroovyCodeStyleSettings.class) + settings.SPACE_IN_NAMED_ARGUMENT = false + + try { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ + class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg11) } + } + """) + myFixture.completeBasic() + myFixture.checkResult """ + class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg111:) } + } + """ + } + finally { + settings.SPACE_IN_NAMED_ARGUMENT = true + } + } + + public void testCompletionNamedArgument1() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg111: 1, arg: 2, arg333: 3) } +} +""") + myFixture.completeBasic() + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg111: 1, arg222: 2, arg333: 3) } +} +""" + } + + public void testCompletionNamedArgument2() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m arg111: 1, arg: 2, arg333: 3 } +} +""") + myFixture.completeBasic() + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m arg111: 1, arg222: 2, arg333: 3 } +} +""" + } + + public void testCompletionNamedArgument3() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m arg1 } +} +""") + myFixture.completeBasic() + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m arg111: } +} +""" + } + + public void testCompletionNamedArgument4() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m (arg1 zzz) } +} +""") + myFixture.completeBasic() + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m (arg111: , zzz) } +} +""" + } + + public void testCompletionNamedArgument5() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m (arg1, { + out << "asdasdas" + } ) } +} +""") + myFixture.completeBasic() + + myFixture.checkResult(""" +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m (arg111: , { + out << "asdasdas" + } ) } +} +""") + } + + public void testCompletionNamedArgument6() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m([arg1])} +} +""") + myFixture.completeBasic() + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m([arg111: ])} +} +""" + } + + public void testCompletionNamedArgument7() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg1)} +} +""") + myFixture.completeBasic() + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg111: )} +} +""" + } + + public void testCompletionNamedArgument8() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg1,)} +} +""") + myFixture.completeBasic() + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg111: ,)} +} +""" + } + + public void testCompletionNamedArgumentWithDD() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg)} +} +""") + myFixture.completeBasic() + myFixture.type(':') + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg111: )} +} +""" + } + + public void testCompletionNamedArgumentReplace() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg222: 'a')} +} +""") + myFixture.completeBasic() + myFixture.type("1\t") + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg111: 'a')} +} +""" + } + + public void testCompletionNamedArgumentWithSpace() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg)} +} +""") + myFixture.completeBasic() + myFixture.type(' ') + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { m(arg111: )} +} +""" + } + + public void testCompletionNamedArgumentWithNewLine1() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { + m(arg + arg222: 222, + ) + } +} +""") + myFixture.completeBasic() + myFixture.type(' ') + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { + m(arg111: , + arg222: 222, + ) + } +} +""" + } + + public void testCompletionNamedArgumentWithNewLine2() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { + m(arg, + arg222: 222, + ) + } +} +""") + myFixture.completeBasic() + myFixture.type(':') + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { + m(arg111: , + arg222: 222, + ) + } +} +""" + } + + public void testCompletionNamedArgumentWithNewLine4() { + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { + m(arg + , arg222: 222, + arg333: 333, + ) + } +} +""") + myFixture.completeBasic() + + myFixture.checkResult """ +class A { + public int m(arg) { return arg.arg111 + arg.arg222 + arg.arg333; } + { + m(arg111: + , arg222: 222, + arg333: 333, + ) + } +} +""" + } + + public void testSpreadOperator() { + doVariantableTest("foo1", "foo2") + } + + public void testGrvy945() { + def file = myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, """class MyCategory { + static def plus(MyCategory t, MyCat) { + } +}""") + LookupElement[] lookupElements = myFixture.completeBasic() + assertNull(lookupElements) + + assertEquals """class MyCategory { + static def plus(MyCategory t, MyCategory) { + } +}""", file.text + } + + void configure(String text) { + myFixture.configureByText("a.groovy", text) + } + + public void testGenericsAfterNew() { + configure "List l = new ArrLi" + myFixture.completeBasic() + myFixture.type '\n' + myFixture.checkResult "List l = new ArrayList()" + } + + public void testAfterNewWithInner() { + myFixture.addClass """class Zzoo { + static class Impl {} + }""" + configure "Zzoo l = new Zz" + myFixture.completeBasic() + myFixture.type '\n' + myFixture.checkResult "Zzoo l = new Zzoo()" + } + + public void testNothingAfterIntegerLiteral() { + configure "2f" + assertEmpty myFixture.completeBasic() + } + + public void testPackagedContainingClassNameAfterStatic() { + myFixture.configureFromExistingVirtualFile(myFixture.addFileToProject("foo/cls.groovy", """ + package foo + class Zzzzzzz { + static Zzz + } + """).virtualFile) + myFixture.completeBasic() + assert myFixture.editor.document.text.contains("static Zzzzzzz") + } + + public void testDontCompleteSubpackageOfImplicitlyImported() { + myFixture.addFileToProject "A.groovy", """ +in""" + myFixture.testCompletionVariants "A.groovy", "int", "interface" //don't complete 'instrument' from 'java.lang' + } + + + public void testEatingThisReference() { + configure "def x = []; x. this" + myFixture.completeBasic() + myFixture.type 'ad\t' + myFixture.checkResult "def x = []; x.add() this" + } + + public void testEatingClosingParenthesis() { + checkCompletion """ +def xxxx = [] +def xxxy = [] +foo((xx):2) +""", '\t', """ +def xxxx = [] +def xxxy = [] +foo((xxxx):2) +""" + } + + public void testDontAddStaticImportSecondTime() { + configure """import static java.lang.String.format +form""" + + myFixture.completeBasic() + myFixture.checkResult """import static java.lang.String.format +format()""" + } + + public void testImportAsterisk() { + myFixture.configureByText "a.groovy", "import java.lang." + myFixture.completeBasic() + myFixture.type '*\n' + myFixture.checkResult "import java.lang.*" + } + + public void testNoDotsInImport() { + myFixture.configureByText "a.groovy", "import java." + myFixture.completeBasic() + myFixture.type 'lan\n' + myFixture.checkResult "import java.lang" + } + + public void testInvalidScriptClass() { + myFixture.addFileToProject("b.groovy", "//comment") + myFixture.configureByText "a.groovy", "def b" + myFixture.completeBasic() + myFixture.checkResult "def b" + } + + public void testSpacesAroundEq() { + myFixture.configureByText "a.groovy", "int xxx, xxy; xx" + myFixture.completeBasic() + myFixture.type '=' + myFixture.checkResult "int xxx, xxy; xxx = " + } + + public void testOnlyAnnotationsAfterAt() { + myFixture.addClass "class AbcdClass {}; @interface AbcdXAnno {}" + myFixture.configureByText "a.groovy", "@Abcd class A {}" + myFixture.completeBasic() + assert myFixture.lookupElementStrings[0] == 'AbcdXAnno' + } + + public void testOnlyAnnotationsAfterAtInMethodParameters() { + myFixture.addClass "class AbcdClass {}; @interface AbcdAnno {}" + myFixture.configureByText "a.groovy", "def foo(@Abcd ) {}" + myFixture.completeBasic() + assert myFixture.lookupElementStrings[0] == 'AbcdAnno' + } + + public void testNoCompletionInClassBodyComments() { + myFixture.configureByText "a.groovy", "class Foo { /* protec */ }" + assertEmpty(myFixture.completeBasic()) + } + + public void testNoCompletionInCodeBlockComments() { + myFixture.configureByText "a.groovy", "def Foo() { /* whil */ }" + assertEmpty(myFixture.completeBasic()) + } + + public void testParenthesesForExpectedClassTypeRegardlessInners() { + myFixture.addClass "class Fooooo { interface Bar {} }" + myFixture.configureByText "a.groovy", "Fooooo f = new Foo" + myFixture.completeBasic() + assert myFixture.lookupElementStrings == ['Fooooo', 'Fooooo.Bar'] + myFixture.type '\n' + myFixture.checkResult "Fooooo f = new Fooooo()" + } + + public void testParenthesesForUnexpectedClassTypeRegardingInners() { + myFixture.addClass "class Fooooo { interface Bar {} }" + myFixture.configureByText "a.groovy", "Fooooo.Bar f = new Foo" + myFixture.completeBasic() + assert myFixture.lookupElementStrings == ['Fooooo', 'Fooooo.Bar'] + myFixture.type '\n' + myFixture.checkResult "Fooooo.Bar f = new Fooooo()" + } + + public void testOnlyExceptionsInCatch() { + myFixture.addClass "package foo; public class AbcdClass {}; public class AbcdException extends Throwable {}" + myFixture.configureByText "a.groovy", "try {} catch (Abcd" + myFixture.completeBasic() + myFixture.type('\n') + myFixture.checkResult """import foo.AbcdException + +try {} catch (AbcdException""" + } + + public void testOnlyExceptionsInCatch2() { + myFixture.addClass "class AbcdClass {}; class AbcdException extends Throwable {}" + myFixture.configureByText "a.groovy", "try {} catch (Abcd e) {}" + myFixture.completeBasic() + assert myFixture.lookupElementStrings[0] == 'AbcdException' + myFixture.type('\n') + myFixture.checkResult "try {} catch (AbcdException e) {}" + } + + public void testTopLevelClassesFromPackaged() { + myFixture.addClass "public class Fooooo {}" + final text = "package foo; class Bar { Fooo }" + def file = myFixture.addFileToProject("foo/Bar.groovy", text) + myFixture.configureFromExistingVirtualFile file.virtualFile + assertEmpty myFixture.completeBasic() + myFixture.checkResult text + } + + public void testLocalVarOverlaysField() { + myFixture.configureByText "a.groovy", """ +class A { + def myVar = 2 + + def foo() { + def myVar = 3 + print myVa + } +}""" + myFixture.completeBasic() + + myFixture.checkResult """ +class A { + def myVar = 2 + + def foo() { + def myVar = 3 + print myVar + } +}""" + + } + + public void testParenthesesInMethodCompletion() { + myFixture.configureByText "a.groovy", """ +def foo(def a) {2} +return fo""" + myFixture.completeBasic() + myFixture.checkResult """ +def foo(def a) {2} +return foo()""" + } + + public void testFinishClassNameWithSquareBracket() { + myFixture.addClass("class AbcdClass {}; class AbcdeClass {}") + checkCompletion("Abcd", '[', "AbcdClass[]") + } + + public void testFinishClassNameWithSquareBracketAfterNew() { + myFixture.addClass("class AbcdClass {}; class AbcdeClass {}") + checkCompletion("new Abcd", '[', "new AbcdClass[]") + } + + public void testFinishMethodNameWithSquareBracket() { + myFixture.addClass("""class AbcdClass { + static int[] foo(int x){} + static int[] fobar(){} + }""") + checkCompletion("AbcdClass.fo", '[', "AbcdClass.fobar()[]") + } + + public void testFinishVariableNameWithSquareBracket() { + checkCompletion("int[] fooo, foobar; foo", '[', "int[] fooo, foobar; foobar[]") + } + + public void testFinishClassNameWithLt() { + myFixture.addClass("class AbcdClass {}; class AbcdeClass {}") + checkCompletion("Abcd", '<', "AbcdClass<>") + } + + public void testFinishClassNameWithLtAfterNew() { + myFixture.addClass("class AbcdClass {}; class AbcdeClass {}") + checkCompletion("new Abcd", '<', "new AbcdClass<>()") + } + + public void testMapKeysUsedInFile() { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE + doVariantableTest 'foo1', 'foo3', 'foo4', 'Foo5', 'Foo7' + } + + public void testNoClassesAsMapKeys() { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE + doVariantableTest() + } + + public void testNamedArgsUsedInFile() { + myFixture.configureByFile(getTestName(false) + ".groovy"); + doVariantableTest 'false', 'foo2', 'float', 'foo1', 'foo3', 'foo4', 'foo5' + } + + public void testSuggestMembersOfExpectedType() { + myFixture.addClass("enum Foo { aaaaaaaaaaaaaaaaaaaaaa, bbbbbb }") + checkCompletion("Foo f = aaaaaaaa", '\n', "Foo f = Foo.aaaaaaaaaaaaaaaaaaaaaa") + } + + public void testFieldTypeAfterModifier() { + myFixture.addClass("package bar; public class Fooooooooooo { }") + checkCompletion ''' +class A { + private Foooo +}''', '\n', '''import bar.Fooooooooooo + +class A { + private Fooooooooooo +}''' + } + + public void testSuperClassProperty() { + checkSingleItemCompletion """ +class A { def foooooooooooo } + +class B extends A { + def bar() { + foooo + } +} +""", """ +class A { def foooooooooooo } + +class B extends A { + def bar() { + foooooooooooo + } +} +""" + } + + public void testDoubleSpace() { + checkCompletion "assex", ' ', 'assert x' + } + + public void testPreferInstanceof() { + caseSensitiveNone() + + configure ''' +class Fopppp { + def foo() { + assert x ins + } +} +class Instantiation {} +''' + myFixture.completeBasic() + assertEquals 'instanceof', myFixture.lookupElementStrings[0] + } + + public void testForFinal() { + assert doContainsTest('final', ''' +class Fopppp { + def foo() { + for(fin + } +} +''') + } + + public void testExcludeStringBuffer() { + assert doContainsTest('StringBuffer', 'StringBufff') + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = [StringBuffer.name] as String[] + try { + assert !doContainsTest('StringBuffer', 'StringBufff') + } + finally { + CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0] + } + } + + private doContainsTest(String itemToCheck, String text) { + myFixture.configureByText "a.groovy", text + + final LookupElement[] completion = myFixture.completeBasic() + return completion.find {println it.lookupString;itemToCheck == it.lookupString} + } + + public void testWordCompletionInLiterals() { + checkSingleItemCompletion('def foo = "fo"', 'def foo = "foo"') + } + public void testWordCompletionInLiterals2() { + checkSingleItemCompletion(''' +println "abcd" +"a" +''', ''' +println "abcd" +"abcd" +''') + } + + public void testWordCompletionInComments() { + checkSingleItemCompletion(''' +println "abcd" +// a" +''', ''' +println "abcd" +// abcd" +''') + } + + public void testNoModifiersAfterDef() { + checkSingleItemCompletion 'def priv', 'def priv' + } + + public void testIfSpace() { checkCompletion 'int iff; if', ' ', "int iff; if " } + + public void testIfParenthesis() { checkCompletion 'int iff; if', '(', "int iff; if ()" } + + public void testEnumPropertyType() { + checkSingleItemCompletion 'enum Foo {a,b; static List>', "enum Foo {a,b; static List>" + } + + public void testEnumPropertyType2() { + checkSingleItemCompletion 'enum Foo {a,b; static List', "enum Foo {a,b; static List" + } + + public void testShowAccessor() { + assertNotNull doContainsTest("getFoo", """ +class MyClass { + def foo +} + +def a = new MyClass() +a.g +""") + } + + public void testContinue() { + assertNotNull doContainsTest("continue", """ +def conti = 4 +while(true) { + if (tst) cont +}""") + + } + + public void testPreferParametersToClasses() { + caseSensitiveNone() + + myFixture.configureByText "a.groovy", "def foo(stryng) { println str }" + myFixture.completeBasic() + assertEquals 'stryng', myFixture.lookupElementStrings[0] + } + + private def caseSensitiveNone() { + CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE + } + + public void testFieldVsPackage() { + myFixture.addFileToProject 'aaa/bbb/Foo.groovy', 'package aaa.bbb; class Foo{}' + def file = myFixture.addFileToProject('aaa/bar.groovy', ''' +package aaa + +import aaa.* + +class X { + def bbb = 'text' + + def foo() { + bbb.toString() + } +} +''') + myFixture.configureFromExistingVirtualFile file.virtualFile + myFixture.completeBasic() + assertFalse(myFixture.lookupElementStrings.contains('Foo')) + } + + public void testFieldVsPackage2() { + myFixture.addFileToProject 'aaa/bbb/Foo.groovy', 'package aaa.bbb; class Foo{}' + def file = myFixture.addFileToProject('aaa/bar.groovy', ''' +package aaa + +import aaa.* + +class X { + def bbb = 'text' + + def foo() { + bbb. + } +} +''') + myFixture.configureFromExistingVirtualFile file.virtualFile + myFixture.completeBasic() + assertFalse(myFixture.lookupElementStrings.contains('Foo')) + } + + public void testClassNameBeforeParentheses(){ + doBasicTest() + } + + public void testNewClassGenerics() { + checkSingleItemCompletion 'new ArrayLi', 'new ArrayList<>()' + } + + public void testInnerClassStart() { + checkSingleItemCompletion 'class Foo { cl }', 'class Foo { class }' + } + + public void testPropertyBeforeAccessor() { + doVariantableTest 'soSe', 'setSoSe' + } + + public void testSortOrder0() { + doVariantableTest 'se', 'setProperty', 'setMetaClass', 'setSe' + } + + public void testPrimitiveCastOverwrite() { + checkCompletion 'byte v1 = (byte) 0', '\t', 'byte v1 = (byte) 0' + } + + public void testInitializerMatters() { + myFixture.configureByText("a.groovy", "class Foo {{ String fx = getFoo(); }; String getFoo() {}; }"); + myFixture.completeBasic() + assertOrderedEquals(myFixture.lookupElementStrings, ["foo"]) + } + + public void testFieldInitializerMatters() { + myFixture.configureByText("a.groovy", "class Foo { String fx = getFoo(); String getFoo() {}; }"); + myFixture.completeBasic() + assertOrderedEquals(myFixture.lookupElementStrings, ["foo"]) + } + + public void testAccessStaticViaInstanceSecond() { + myFixture.configureByText("a.groovy", """ +public class KeyVO { + { this.fox } + static void foo() {} +} +"""); + myFixture.complete(CompletionType.BASIC, 1) + assert !myFixture.lookupElementStrings + myFixture.complete(CompletionType.BASIC, 2) + assertOrderedEquals(myFixture.lookupElementStrings, ["foo"]) + } + + public void testNoRepeatingModifiers() { + myFixture.configureByText 'a.groovy', 'class A { public static }' + myFixture.completeBasic() + assert !('public' in myFixture.lookupElementStrings) + assert !('static' in myFixture.lookupElementStrings) + assert 'final' in myFixture.lookupElementStrings + } + + public void testSpaceTail() { + checkCompletion 'class A ArrayList {}', ' ', 'class A extends ArrayList {}' + checkCompletion 'class A ArrayList {}', '\n', 'class A extends ArrayList {}' + checkSingleItemCompletion 'class Foo impl {}', 'class Foo implements {}' + } + + public void testAmbiguousClassQualifier() { + myFixture.addClass("package foo; public class Util { public static void foo() {} }") + myFixture.addClass("package bar; public class Util { public static void bar() {} }") + myFixture.configureByText 'a.groovy', 'Util.' + myFixture.completeBasic() + assertOrderedEquals myFixture.lookupElementStrings[0..1] , ['Util.bar', 'Util.foo'] + + def presentation = LookupElementPresentation.renderElement(myFixture.lookupElements[0]) + assertEquals 'Util.bar', presentation.itemText + assertEquals '() (bar)', presentation.tailText + assert !presentation.tailGrayed + + myFixture.type 'f\n' + myFixture.checkResult '''import foo.Util + +Util.foo()''' + } + + public void testUseDescendantStaticImport() { doBasicTest() } + + public void testPreferInterfacesInImplements() { + myFixture.addClass('interface FooIntf {}') + myFixture.addClass('class FooClass {}') + doVariantableTest('FooIntf', 'FooClass') + } + + public void testPropertyChain() { doBasicTest() } + + public void testMethodPointer() { + doBasicTest('''\ +class Base { + def prefixMethod(){} + def prefixField +} + +new Base().&prefix''', '''\ +class Base { + def prefixMethod(){} + def prefixField +} + +new Base().&prefixMethod''') + } + + private void doBasicTest(String before, String after) { + myFixture.configureByText('_a.groovy', before) + myFixture.completeBasic() + assertNull(myFixture.lookupElements) + myFixture.checkResult(after) + } + + public void testFieldPointer() { + doBasicTest '''\ +class Base { + def prefixMethod(){} + def prefixField +} + +new Base().@prefix''', '''\ +class Base { + def prefixMethod(){} + def prefixField +} + +new Base().@prefixField''' + } + + public void testPrivateFieldOnSecondInvocation() { + myFixture.configureByText('_a.groovy', '''\ +class Base { + private int field1 +} + +new Base().fiex''') + myFixture.complete(CompletionType.BASIC, 2) + assert myFixture.lookupElementStrings == ['field1'] + } + + public void testForIn() { + assert doContainsTest('in', 'for (int i i') + assert doContainsTest('in', 'for (i i') + } + + public void testReturnInVoidMethod() { + doBasicTest('''\ +void foo() { + retur +} +''', '''\ +void foo() { + return +} +''') + } + + public void testReturnInNotVoidMethod() { + doBasicTest('''\ +String foo() { + retur +} +''', '''\ +String foo() { + return +} +''') + } + + void testInferArgumentTypeFromMethod1() { + doBasicTest('''\ +def bar(String s) {} + +def foo(Integer a) { + bar(a) + a.subSequen() +} +''', '''\ +def bar(String s) {} + +def foo(Integer a) { + bar(a) + a.subSequence() +} +''') + } + + void testInferArgumentTypeFromMethod2() { + doBasicTest('''\ +def bar(String s) {} + +def foo(Integer a) { + while(true) { + bar(a) + a.subSequen() + } +} +''', '''\ +def bar(String s) {} + +def foo(Integer a) { + while(true) { + bar(a) + a.subSequence() + } +} +''') + } + + void testInferArgumentTypeFromMethod3() { + doBasicTest('''\ +def bar(String s) {} + +def foo(Integer a) { + bar(a) + print a + a.subSequen() +} +''', '''\ +def bar(String s) {} + +def foo(Integer a) { + bar(a) + print a + a.subSequence() +} +''') + } + + void testInferArgumentTypeFromMethod4() { + doBasicTest('''\ +def bar(String s) {} + +def foo(Integer a) { + while(true) { + bar(a) + print a + a.subSequen() + } +} +''', '''\ +def bar(String s) {} + +def foo(Integer a) { + while(true) { + bar(a) + print a + a.subSequence() + } +} +''') + } + + void testSuperExtendsInTypeParams() { + myFixture.configureByText("_.groovy", '''\ +def foo(List)'''); + myFixture.complete(CompletionType.BASIC); + assertOrderedEquals(myFixture.lookupElementStrings, "extends", "super"); + } + + void testSuperExtendsInTypeParams2() { + myFixture.configureByText("_.groovy", '''\ +def foo(List> list)'''); + myFixture.complete(CompletionType.BASIC); + assertOrderedEquals(myFixture.lookupElementStrings, "extends", "super"); + } + + void testMapDontCompleteProperties() { + myFixture.configureByText("_.groovy", '''\ +def map = [1:2] +print map.metc +'''); + myFixture.complete(CompletionType.BASIC); + assertEmpty myFixture.getLookupElements() + } + + void testAnnotationCompletion0() { + myFixture.configureByText('_.groovy', '''\ +@interface A { + String fooo() +} + +@A(foo) +def bar(){}''') + myFixture.complete(CompletionType.BASIC) + myFixture.checkResult('''\ +@interface A { + String fooo() +} + +@A(fooo = ) +def bar(){}''') + } + + void testAnnotationCompletion1() { + myFixture.configureByText('_.groovy', '''\ +@interface A { + String fooo() +} + +def abcde() {} + +@A(abc) +def bar(){}''') + myFixture.complete(CompletionType.BASIC) + myFixture.checkResult('''\ +@interface A { + String fooo() +} + +def abcde() {} + +@A(abcde()) +def bar(){}''') + } + + void testAnnotationCompletion2() { + myFixture.configureByText('_.groovy', '''\ +@interface A { + String fooo() + String fooo1() +} + +@A(foo = 'a') +def bar(){}''') + myFixture.complete(CompletionType.BASIC) + assertOrderedEquals(myFixture.lookupElementStrings, ['fooo', 'fooo1']) + } + } \ No newline at end of file diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovySmartCompletionTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovySmartCompletionTest.groovy index 8e9fab456631..ce910a9b8dda 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovySmartCompletionTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/GroovySmartCompletionTest.groovy @@ -20,6 +20,7 @@ package org.jetbrains.plugins.groovy.completion; import com.intellij.codeInsight.completion.CompletionType import com.intellij.codeInsight.completion.StaticallyImportable import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher /** * @author peter @@ -79,7 +80,7 @@ public class GroovySmartCompletionTest extends GroovyCompletionTestBase { public void testSmartCastCompletionWithoutRParenth() {doSmartTest();} public void testSmartCastCompletionWithRParenth() {doSmartTest();} - public void testDontCompletePrivateMembers() {doSmartCompletion "foo1", "foo2"} + public void testDontCompletePrivateMembers() {CamelHumpMatcher.forceStartMatching(getTestRootDisposable());doSmartCompletion "foo1", "foo2"} public void testEnumMembersInAssignment() {doSmartCompletion "IN_STOCK", "NOWHERE", "ORDERED" } public void testEnumMembersInAssignmentInsideEnum() {doSmartCompletion "IN_STOCK", "NOWHERE", "ORDERED", "next", "previous" } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyDslTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyDslTest.groovy index 6883801d519d..590ccc92ba00 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyDslTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyDslTest.groovy @@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection import org.jetbrains.plugins.groovy.lang.documentation.GroovyDocumentationProvider import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher /** * @author peter @@ -60,10 +61,6 @@ public class GroovyDslTest extends LightCodeInsightFixtureTestCase { myFixture.testCompletion(getTestName(false) + ".gdsl", getTestName(false) + "_after.gdsl") } - public void doPlainTest() throws Throwable { - myFixture.testCompletion(getTestName(false) + ".groovy", getTestName(false) + "_after.groovy") - } - public void testCompleteTopLevel() throws Throwable { myFixture.configureByText 'a.gdsl', '' myFixture.completeBasic() @@ -132,6 +129,7 @@ public class GroovyDslTest extends LightCodeInsightFixtureTestCase { } public void testClassContext() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); doCustomTest( """ def ctx = context(scope: classScope(name: /.*WsSecurityConfig/)) @@ -161,6 +159,7 @@ public class MyCategory { } public void testPathRegexp() { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); addGdsl "contributor(pathRegexp: '.*aaa.*') { property name:'fffooo', type:'int' }" myFixture.configureFromExistingVirtualFile myFixture.addFileToProject("aaa/foo.groovy", "fffx").virtualFile @@ -173,6 +172,7 @@ public class MyCategory { } public void testNamedParameters() { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); addGdsl '''contribute(currentType(String.name)) { method name:'foo', type:void, params:[:], namedParams:[ parameter(name:'param1', type:String), @@ -185,6 +185,7 @@ public class MyCategory { } public void testNamedParametersGroovyConvention() { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); addGdsl '''contribute(currentType(String.name)) { method name:'foo', type:void, params:[args:[ parameter(name:'param1', type:String, doc:'My doc'), diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyTransformationsTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyTransformationsTest.groovy index 0228220fa5ea..1fb463067af9 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyTransformationsTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/dsl/GroovyTransformationsTest.groovy @@ -9,6 +9,7 @@ import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.plugins.groovy.util.TestUtils import org.jetbrains.annotations.NotNull +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher /** * @author ilyas @@ -20,6 +21,12 @@ class GroovyTransformationsTest extends LightCodeInsightFixtureTestCase { } } + @Override + protected void setUp() { + super.setUp() + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + } + @Override protected String getBasePath() { TestUtils.getTestDataPath() + "groovy/dsl/transform" diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy index 8ff9b61f7e00..41962a72610a 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/GantReferenceCompletionTest.groovy @@ -29,8 +29,9 @@ import org.jetbrains.annotations.NotNull import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GroovyUntypedAccessInspection import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher - /** +/** * @author ilyas */ public class GantReferenceCompletionTest extends LightCodeInsightFixtureTestCase { @@ -57,6 +58,7 @@ public class GantReferenceCompletionTest extends LightCodeInsightFixtureTestCase } public void testDep() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); checkVariants """ target(aaa: "") { dep @@ -79,6 +81,7 @@ target(aaa: "") { } public void testInclude() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); checkVariants "inc", "includeTool", "includeTargets" } @@ -130,6 +133,7 @@ ant.zip { } public void testTagsInsideTagsInGantTarget() throws Exception { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); checkVariants """ target(aaa: "") { zip { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/StandaloneGantTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/StandaloneGantTest.groovy index f2ed344973a7..f55bbd8f9a1c 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/StandaloneGantTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/gant/StandaloneGantTest.groovy @@ -15,6 +15,7 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.annotations.NotNull import org.jetbrains.plugins.groovy.util.SdkHomeConfigurable.SdkHomeBean import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher /** * @author peter @@ -60,6 +61,7 @@ public class StandaloneGantTest extends LightCodeInsightFixtureTestCase { } public void testDep() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); checkVariants """ target(aaa: "") { dep diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyMapAttributeTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyMapAttributeTest.groovy index a828d6e60c09..c0b974accd43 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyMapAttributeTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyMapAttributeTest.groovy @@ -21,6 +21,7 @@ import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilit import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyUncheckedAssignmentOfMemberOfRawTypeInspection import com.intellij.testFramework.LightProjectDescriptor import org.jetbrains.plugins.groovy.completion.GrCompletionWithLibraryTest +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher /** * @author Sergey Evdokimov @@ -238,6 +239,7 @@ class Aaa { } public void testConstructorInJavaClass() { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); myFixture.addFileToProject("Ccc.java", """ public class Ccc { private String sss1 diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestBase.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestBase.java index 1890e1029872..8e6588c5f2ae 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestBase.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestBase.java @@ -64,6 +64,7 @@ public abstract class TestBase extends UsefulTestCase { protected void tearDown() throws Exception { myFixture.tearDown(); myFixture = null; + super.tearDown(); } protected String getTestFileName() { diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.java index 557fc13cfa0b..11fc06f2cb5a 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.java @@ -15,13 +15,17 @@ */ package org.intellij.lang.xpath; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; + public class XPath2CompletionTest extends TestBase { public void testCastInsert() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); doXPathCompletion(); } public void testTreatInsert() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); doXPathCompletion(); } diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathCompletionTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathCompletionTest.java index 4a4ebaad41bc..1719b0438024 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathCompletionTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathCompletionTest.java @@ -15,9 +15,16 @@ */ package org.intellij.lang.xpath; -public class XPathCompletionTest extends TestBase { +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; - public void testAxis() throws Throwable { +public class XPathCompletionTest extends TestBase { + @Override + protected void setUp() throws Exception { + super.setUp(); + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + } + + public void testAxis() throws Throwable { doXPathCompletion("ancestor", "ancestor-or-self", "attribute"); } diff --git a/xml/relaxng/test/org/intellij/plugins/relaxNG/RncCompletionTest.java b/xml/relaxng/test/org/intellij/plugins/relaxNG/RncCompletionTest.java index 971b3da695f7..fe552d07fdcb 100644 --- a/xml/relaxng/test/org/intellij/plugins/relaxNG/RncCompletionTest.java +++ b/xml/relaxng/test/org/intellij/plugins/relaxNG/RncCompletionTest.java @@ -16,6 +16,7 @@ package org.intellij.plugins.relaxNG; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; import org.intellij.plugins.testUtil.CopyFile; /** @@ -24,6 +25,12 @@ import org.intellij.plugins.testUtil.CopyFile; * Date: 22.08.2007 */ public class RncCompletionTest extends HighlightingTestBase { + @Override + protected void setUp() throws Exception { + super.setUp(); + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); + } + public String getTestDataPath() { return "completion/rnc"; } diff --git a/xml/relaxng/test/org/intellij/plugins/relaxNG/RngCompletionTest.java b/xml/relaxng/test/org/intellij/plugins/relaxNG/RngCompletionTest.java index 1eeeec1fd16d..82a674451ef1 100644 --- a/xml/relaxng/test/org/intellij/plugins/relaxNG/RngCompletionTest.java +++ b/xml/relaxng/test/org/intellij/plugins/relaxNG/RngCompletionTest.java @@ -16,6 +16,7 @@ package org.intellij.plugins.relaxNG; +import com.intellij.codeInsight.completion.impl.CamelHumpMatcher; import org.intellij.plugins.testUtil.CopyFile; /** @@ -42,6 +43,7 @@ public class RngCompletionTest extends HighlightingTestBase { } public void testCompleteRef4() throws Throwable { + CamelHumpMatcher.forceStartMatching(getTestRootDisposable()); doTestCompletion("complete-ref-4", "rng"); } }