2 * Copyright 2000-2011 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.codeInsight.completion;
19 import com.intellij.JavaTestUtil
20 import com.intellij.codeInsight.CodeInsightSettings
21 import com.intellij.codeInsight.lookup.Lookup
22 import com.intellij.codeInsight.lookup.LookupElement
23 import com.intellij.codeInsight.lookup.LookupElementPresentation
24 import com.intellij.codeInsight.lookup.LookupManager
25 import com.intellij.openapi.actionSystem.IdeActions
26 import com.intellij.openapi.command.WriteCommandAction
27 import com.intellij.openapi.fileTypes.StdFileTypes
28 import com.intellij.psi.codeStyle.CodeStyleSettings
29 import com.intellij.psi.codeStyle.CodeStyleSettingsManager
30 import com.intellij.psi.*
32 public class NormalCompletionTest extends LightFixtureCompletionTestCase {
34 protected String getBasePath() {
35 return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/normal/";
38 public void testSimple() throws Exception {
39 configureByFile("Simple.java");
40 assertStringItems("_local1", "_local2", "_field", "_method", "_baseField", "_baseMethod");
43 public void testDontCompleteFieldsAndMethodsInReferenceCodeFragment() throws Throwable {
44 final String text = CommonClassNames.JAVA_LANG_OBJECT + ".<caret>";
45 PsiFile file = JavaCodeFragmentFactory.getInstance(project).createReferenceCodeFragment(text, null, true, true);
46 myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
48 myFixture.checkResult(text);
52 public void testNoPackagesInExpressionCodeFragment() throws Throwable {
53 final String text = "jav<caret>";
54 PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment(text, null, null, true);
55 myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
57 myFixture.checkResult(text);
61 public void testSubPackagesInExpressionCodeFragment() throws Throwable {
62 PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment("java.la<caret>", null, null, true);
63 myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
65 myFixture.checkResult("java.lang.<caret>");
69 public void testPrimitivesInTypeCodeFragmentWithParameterListContext() throws Throwable {
70 def clazz = myFixture.addClass("class Foo { void foo(int a) {} }")
72 PsiFile file = JavaCodeFragmentFactory.getInstance(project).createTypeCodeFragment("b<caret>", clazz.methods[0].parameterList, true);
73 myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
75 assertStringItems('boolean', 'byte')
78 public void testQualifierCastingInExpressionCodeFragment() throws Throwable {
79 final ctxText = "class Bar {{ Object o; o=null }}"
80 final ctxFile = createLightFile(StdFileTypes.JAVA, ctxText)
81 final context = ctxFile.findElementAt(ctxText.indexOf("o="))
84 PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment("o instanceof String && o.subst<caret>", context, null, true);
85 myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
87 myFixture.checkResult("o instanceof String && ((String) o).substring(<caret>)");
91 public void testCastToPrimitive1() throws Exception {
92 configureByFile("CastToPrimitive1.java");
94 for (final LookupElement item : myItems) {
95 if (item.getLookupString().equals("int")) return;
100 public void testCastToPrimitive2() throws Exception {
101 configureByFile("CastToPrimitive2.java");
103 for (final LookupElement item : myItems) {
104 if (item.getLookupString().equals("int")) return;
109 public void testCastToPrimitive3() throws Exception {
110 configureByFile("CastToPrimitive3.java");
112 for (final LookupElement item : myItems) {
113 if (item.getLookupString().equals("int")) return;
118 public void testWriteInInvokeLater() throws Exception {
119 configureByFile("WriteInInvokeLater.java");
122 public void testQualifiedNew1() throws Exception {
124 assertStringItems "IInner", "Inner"
127 public void testQualifiedNew2() throws Exception {
129 assertStringItems "AnInner", "Inner"
132 public void testKeywordsInName() throws Exception {
136 public void testSimpleVariable() throws Exception { doTest() }
138 public void testMethodItemPresentation() {
140 LookupElementPresentation presentation = renderElement(myItems[0])
141 assert "equals" == presentation.itemText
142 assert "(Object anObject)" == presentation.tailText
143 assert "boolean" == presentation.typeText
145 assert !presentation.tailGrayed
146 assert presentation.itemTextBold
149 private LookupElementPresentation renderElement(LookupElement element) {
150 def presentation = new LookupElementPresentation()
151 element.renderElement(presentation)
155 public void testMethodItemPresentationGenerics() {
157 LookupElementPresentation presentation = renderElement(myItems[0])
158 assert "add" == presentation.itemText
159 assert "(String o)" == presentation.tailText
160 assert "boolean" == presentation.typeText
162 assert !presentation.tailGrayed
163 assert presentation.itemTextBold
166 public void testPreferLongerNamesOption() throws Exception {
167 configureByFile("PreferLongerNamesOption.java");
169 assertEquals(3, myItems.length);
170 assertEquals("abcdEfghIjk", myItems[0].getLookupString());
171 assertEquals("efghIjk", myItems[1].getLookupString());
172 assertEquals("ijk", myItems[2].getLookupString());
174 LookupManager.getInstance(getProject()).hideActiveLookup();
176 CodeStyleSettingsManager.getSettings(getProject()).PREFER_LONGER_NAMES = false;
178 configureByFile("PreferLongerNamesOption.java");
180 assertEquals(3, myItems.length);
181 assertEquals("ijk", myItems[0].getLookupString());
182 assertEquals("efghIjk", myItems[1].getLookupString());
183 assertEquals("abcdEfghIjk", myItems[2].getLookupString());
186 CodeStyleSettingsManager.getSettings(getProject()).PREFER_LONGER_NAMES = true;
190 public void testSCR7208() throws Exception {
191 configureByFile("SCR7208.java");
194 public void testProtectedFromSuper() throws Exception {
195 configureByFile("ProtectedFromSuper.java");
196 Arrays.sort(myItems);
197 assertTrue("Exception not found", Arrays.binarySearch(myItems, "xxx") > 0);
200 public void testBeforeInitialization() throws Exception {
201 configureByFile("BeforeInitialization.java");
202 assertNotNull(myItems);
203 assertTrue(myItems.length > 0);
206 public void testProtectedFromSuper2() throws Exception {
208 configureByFile("ProtectedFromSuper.java");
209 Arrays.sort(myItems);
210 assertTrue("Exception not found", Arrays.binarySearch(myItems, "xxx") > 0);
213 public void testClassLiteralInArrayAnnoInitializer() throws Throwable { doTest(); }
214 public void testClassLiteralInArrayAnnoInitializer2() throws Throwable { doTest(); }
216 public void testReferenceParameters() throws Exception {
217 configureByFile("ReferenceParameters.java");
218 assertNotNull(myItems);
219 assertEquals(myItems.length, 2);
220 assertEquals(myItems[0].getLookupString(), "AAAA");
221 assertEquals(myItems[1].getLookupString(), "AAAB");
224 public void testConstructorName1() throws Exception{
225 final CodeInsightSettings settings = CodeInsightSettings.getInstance();
226 final boolean autocomplete_on_code_completion = settings.AUTOCOMPLETE_ON_CODE_COMPLETION;
227 settings.AUTOCOMPLETE_ON_CODE_COMPLETION = false;
228 configureByFile("ConstructorName1.java");
229 assertNotNull(myItems);
230 boolean failed = true;
231 for (final LookupElement item : myItems) {
232 if (item.getLookupString().equals("ABCDE")) {
237 settings.AUTOCOMPLETE_ON_CODE_COMPLETION = autocomplete_on_code_completion;
240 public void testConstructorName2() throws Exception{
241 final CodeInsightSettings settings = CodeInsightSettings.getInstance();
242 final boolean autocomplete_on_code_completion = settings.AUTOCOMPLETE_ON_CODE_COMPLETION;
243 settings.AUTOCOMPLETE_ON_CODE_COMPLETION = false;
244 configureByFile("ConstructorName2.java");
245 assertNotNull(myItems);
246 boolean failed = true;
247 for (final LookupElement item : myItems) {
248 if (item.getLookupString().equals("ABCDE")) {
253 settings.AUTOCOMPLETE_ON_CODE_COMPLETION = autocomplete_on_code_completion;
256 public void testObjectsInThrowsBlock() throws Exception {
257 configureByFile("InThrowsCompletion.java");
258 assert "C" in myFixture.lookupElementStrings
259 assert !("B" in myFixture.lookupElementStrings)
262 public void testAfterInstanceof() throws Exception {
263 configureByFile("AfterInstanceof.java");
264 assert "A" in myFixture.lookupElementStrings
267 public void testAfterCast1() throws Exception {
268 configureByFile("AfterCast1.java");
270 assertNotNull(myItems);
271 assertEquals(2, myItems.length);
274 public void testAfterCast2() throws Exception {
275 configureByFile("AfterCast2.java");
276 checkResultByFile("AfterCast2-result.java");
279 public void testMethodCallForTwoLevelSelection() throws Exception {
280 configureByFile("MethodLookup.java");
281 assertEquals(2, myItems.length);
284 public void testMethodCallBeforeAnotherStatementWithParen() throws Exception {
285 configureByFile("MethodLookup2.java");
286 checkResultByFile("MethodLookup2_After.java");
289 public void testMethodCallBeforeAnotherStatementWithParen2() throws Exception {
290 CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
291 boolean oldvalue = settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE;
292 settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
293 configureByFile("MethodLookup2.java");
294 checkResultByFile("MethodLookup2_After2.java");
295 settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = oldvalue;
298 public void testSwitchEnumLabel() throws Exception {
299 configureByFile("SwitchEnumLabel.java");
300 assertEquals(3, myItems.length);
303 public void testMethodInAnnotation() throws Exception {
304 configureByFile("Annotation.java");
305 checkResultByFile("Annotation_after.java");
308 public void testMethodInAnnotation2() throws Exception {
309 configureByFile("Annotation2.java");
310 checkResultByFile("Annotation2_after.java");
313 public void testMethodInAnnotation3() throws Exception {
314 configureByFile("Annotation3.java");
315 checkResultByFile("Annotation3_after.java");
318 public void testMethodInAnnotation5() throws Exception {
319 configureByFile("Annotation5.java");
320 checkResultByFile("Annotation5_after.java");
323 public void testMethodInAnnotation7() throws Exception {
324 configureByFile("Annotation7.java");
325 selectItem(myItems[0]);
326 checkResultByFile("Annotation7_after.java");
329 public void testEnumInAnnotation() throws Exception {
330 configureByFile("Annotation4.java");
331 checkResultByFile("Annotation4_after.java");
334 public void testSecondAttribute() throws Exception {
335 configureByFile("Annotation6.java");
336 checkResultByFile("Annotation6_after.java");
339 public void testIDEADEV6408() throws Exception {
340 configureByFile("IDEADEV6408.java");
341 assertStringItems "boolean", "byte"
344 public void testMethodWithLeftParTailType() throws Exception {
345 configureByFile("MethodWithLeftParTailType.java");
347 checkResultByFile("MethodWithLeftParTailType_after.java");
349 configureByFile("MethodWithLeftParTailType2.java");
351 checkResultByFile("MethodWithLeftParTailType2_after.java");
354 public void testMethodWithLeftParTailTypeNoPairBrace() throws Exception {
355 final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET;
356 CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false;
359 configureByFile(getTestName(false) + ".java");
364 CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old;
368 public void testMethodWithLeftParTailTypeNoPairBrace2() throws Exception {
369 final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET;
370 CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false;
373 //no tail type should work the normal way
374 configureByFile("MethodWithLeftParTailTypeNoPairBrace.java");
375 selectItem(myItems[0]);
376 checkResultByFile("MethodWithLeftParTailTypeNoPairBrace_after2.java");
379 CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old;
383 public void testMethodNoPairBrace() throws Exception {
384 final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET;
385 CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false;
391 CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old;
395 public void testExcessSpaceInTypeCast() throws Throwable {
397 selectItem(myItems[0]);
401 public void testFieldType() throws Throwable { doTest(); }
403 public void testPackageInAnnoParam() throws Throwable {
407 public void testClassLiteralInAnnoParam() throws Throwable {
411 public void testExcludeStringBuffer() throws Throwable {
412 CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = [StringBuffer.name] as String[]
417 CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0]
421 public void testExcludeInstanceInnerClasses() throws Throwable {
422 CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ['foo']
423 myFixture.addClass 'package foo; public class Outer { public class Inner {} }'
424 myFixture.addClass 'package bar; public class Inner {}'
427 assert 'bar.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName
428 assert myFixture.lookupElementStrings == ['Inner']
431 CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0]
435 public void testExcludedInstanceInnerClassCreation() throws Throwable {
436 CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ['foo']
437 myFixture.addClass 'package foo; public class Outer { public class Inner {} }'
438 myFixture.addClass 'package bar; public class Inner {}'
441 assert 'foo.Outer.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName
442 assert myFixture.lookupElementStrings == ['Inner']
445 CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0]
449 public void testExcludedInstanceInnerClassQualifiedReference() throws Throwable {
450 CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ['foo']
451 myFixture.addClass 'package foo; public class Outer { public class Inner {} }'
452 myFixture.addClass 'package bar; public class Inner {}'
455 assert 'foo.Outer.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName
456 assert myFixture.lookupElementStrings == ['Inner']
459 CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[0]
463 public void testAtUnderClass() throws Throwable {
467 public void testLocalClassName() throws Throwable { doTest(); }
468 public void testAssigningFieldForTheFirstTime() throws Throwable { doTest(); }
470 public void testClassTypeParameters() throws Throwable {
472 assert 'K' in myFixture.lookupElementStrings
475 public void testClassTypeParametersGenericBounds() throws Throwable {
477 assert 'K' in myFixture.lookupElementStrings
480 public void testLocalClassTwice() throws Throwable {
482 assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo'
485 public void testLocalTopLevelConflict() throws Throwable {
487 assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo'
490 public void testFinalBeforeMethodCall() throws Throwable {
492 assertStringItems 'final', 'finalize'
494 public void testPrivateInAnonymous() throws Throwable { doTest() }
496 public void testMethodParenthesesSpaces() throws Throwable {
497 final settings = CodeStyleSettingsManager.getSettings(getProject())
498 settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
499 settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
503 public void testMethodParenthesesSpacesArgs() throws Throwable {
504 final settings = CodeStyleSettingsManager.getSettings(getProject())
505 settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
506 settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
510 public void testAtUnderClassNoModifiers() throws Throwable {
514 public void testBreakInIfCondition() throws Throwable { doTest(); }
515 public void testAccessStaticViaInstance() throws Throwable { doTest(); }
517 public void testAccessStaticViaInstanceSecond() throws Throwable {
519 myFixture.complete(CompletionType.BASIC, 2)
523 public void testContinueLabel() throws Throwable { doTest(); }
525 public void testAnonymousProcess() {
526 myFixture.addClass 'package java.lang; public class Process {}'
527 myFixture.addClass '''
529 public class Process {}
530 interface Pred <A> { boolean predicate(A elem); }
531 public class ListUtils {
532 public static <A> List<A> filter(List<A> list, Pred<A> pred) {}
540 public void testNoThisInComment() throws Throwable { doAntiTest() }
542 public void testLastExpressionInFor() throws Throwable { doTest(); }
544 public void testUndoCommonPrefixOnHide() throws Throwable {//actually don't undo
545 configureByFile(getTestName(false) + ".java");
547 LookupManager.getInstance(getProject()).hideActiveLookup();
551 public void testOnlyKeywordsInsideSwitch() throws Throwable {
552 configureByFile(getTestName(false) + ".java");
553 assertStringItems("case", "default");
556 public void testBooleanLiterals() throws Throwable {
560 public void testDoubleBooleanInParameter() throws Throwable {
562 assertStringItems("boolean", "byte")
565 public void testDoubleConstant() throws Throwable {
567 assertStringItems("FOO", "Float")
570 public void testNotOnlyKeywordsInsideSwitch() throws Throwable {
574 public void testChainedCallOnNextLine() throws Throwable {
575 configureByFile(getTestName(false) + ".java");
576 selectItem(myItems[0]);
580 public void testFinishWithDot() throws Throwable {
581 configureByFile(getTestName(false) + ".java");
586 public void testEnclosingThis() throws Throwable { doTest(); }
588 public void testSeamlessConstant() throws Throwable {
589 configureByFile(getTestName(false) + ".java");
590 selectItem(myItems[0]);
594 public void testDefaultAnnoParam() throws Throwable { doTest(); }
596 public void testSpaceAfterLookupString() throws Throwable {
597 configureByFile(getTestName(false) + ".java");
599 assertNull(getLookup());
603 public void testNoSpaceInParensWithoutParams() throws Throwable {
604 CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
609 CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
613 public void testTwoSpacesInParensWithParams() throws Throwable {
614 CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
619 CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
623 public void testFillCommonPrefixOnSecondCompletion() throws Throwable {
624 configureByFile(getTestName(false) + ".java");
628 assertStringItems("getBar", "getFoo", "getClass");
631 public void testQualifierAsPackage() throws Throwable {
632 configureByFile(getTestName(false) + ".java");
633 selectItem(myItems[0]);
637 public void testQualifierAsPackage2() throws Throwable {
641 public void testQualifierAsPackage3() throws Throwable {
645 public void testPackageNamedVariableBeforeAssignment() throws Throwable {
649 public void testFieldWithCastingCaret() throws Throwable { doTest(); }
651 public void testInnerEnumConstant() throws Throwable { doTest('\n'); }
653 public void testMethodReturnType() throws Throwable {
657 public void testMethodReturnTypeNoSpace() throws Throwable {
658 configureByFile(getTestName(false) + ".java");
659 selectItem(myItems[0]);
663 public void testEnumWithoutConstants() throws Throwable {
667 public void testDoWhileMethodCall() throws Throwable {
671 public void testSecondTypeParameterExtends() throws Throwable {
675 public void testGetterWithExistingNonEmptyParameterList() throws Throwable {
679 public void testNothingAfterNumericLiteral() throws Throwable { doAntiTest(); }
681 public void testSpacesAroundEq() throws Throwable { doTest('='); }
683 public void _testClassBeforeCast() throws Throwable { doTest '\n' }
685 public void testNoAllClassesOnQualifiedReference() throws Throwable {
686 configureByFile(getTestName(false) + ".java");
687 assertEmpty(myItems);
688 checkResultByFile(getTestName(false) + ".java");
691 public void testFinishClassNameWithDot() throws Throwable {
692 configureByFile(getTestName(false) + ".java");
697 public void testFinishClassNameWithLParen() throws Throwable {
698 configureByFile(getTestName(false) + ".java");
703 public void testSelectNoParameterSignature() throws Throwable {
704 configureByFile(getTestName(false) + ".java");
705 final int parametersCount = ((PsiMethod)getLookup().getCurrentItem().getObject()).getParameterList().getParametersCount();
706 assertEquals(0, parametersCount);
711 public void testCompletionInsideClassLiteral() throws Throwable {
712 configureByFile(getTestName(false) + ".java");
713 new WriteCommandAction.Simple(getProject(), new PsiFile[0]) {
715 protected void run() throws Throwable {
716 getLookup().finishLookup(Lookup.NORMAL_SELECT_CHAR);
718 }.execute().throwException();
722 public void testFieldNegation() throws Throwable { doTest('!');}
723 public void testDefaultInSwitch() throws Throwable { doTest()}
724 public void testBreakInSwitch() throws Throwable { doTest() }
726 public void testSuperInConstructor() throws Throwable {
730 public void testSuperInConstructorWithParams() throws Throwable {
734 public void testSuperInMethod() throws Throwable {
738 public void testSecondMethodParameterName() throws Throwable {
742 public void testAnnotationAsUsualObject() throws Throwable {
746 public void testAnnotationAsUsualObjectFromJavadoc() throws Throwable {
750 public void testAnnotationAsUsualObjectInsideClass() throws Throwable {
754 public void testAnnotationOnNothingParens() throws Throwable {
758 public void testMultiResolveQualifier() throws Throwable {
762 public void testSecondMethodParameter() throws Throwable { doTest(); }
763 public void testReturnInCase() throws Throwable { doTest(); }
765 public void testAnnotationWithoutValueMethod() throws Throwable {
766 configureByFile(getTestName(false) + ".java");
767 assertStringItems("bar", "foo");
770 public void testUnnecessaryMethodMerging() throws Throwable {
771 configureByFile(getTestName(false) + ".java");
772 assertStringItems("fofoo", "fofoo");
775 public void testDontCancelPrefixOnTyping() throws Throwable {
776 configureByFile(getTestName(false) + ".java");
778 assertNull(getLookup());
782 public void testAnnotationQualifiedName() throws Throwable {
786 public void testClassNameGenerics() throws Throwable {
792 public void testClassNameAnonymous() throws Throwable {
798 public void testClassNameWithInner() throws Throwable { doTest() }
799 public void testClassNameWithInner2() throws Throwable { doTest() }
801 public void testClassNameWithInstanceInner() throws Throwable { doTest('\n') }
803 public void testDoubleFalse() throws Throwable {
804 configureByFile(getTestName(false) + ".java");
805 assertStringItems("false", "fefefef", "finalize");
808 public void testSameNamedVariableInNestedClasses() throws Throwable {
810 assertNull(getLookup());
813 public void testHonorUnderscoreInPrefix() throws Throwable {
817 public void testNoSemicolonAfterExistingParenthesesEspeciallyIfItsACast() throws Throwable { doTest(); }
818 public void testReturningTypeVariable() throws Throwable { doTest(); }
819 public void testReturningTypeVariable2() throws Throwable { doTest(); }
820 public void testReturningTypeVariable3() throws Throwable { doTest(); }
821 public void testImportInGenericType() throws Throwable {
823 myFixture.complete(CompletionType.BASIC, 2)
827 public void testCaseTailType() throws Throwable { doTest(); }
829 def doPrimitiveTypeTest() {
831 checkResultByFile(getTestName(false) + ".java");
832 assertTrue 'boolean' in myFixture.lookupElementStrings
835 private def configure() {
836 configureByFile(getTestName(false) + ".java")
839 public void testFinalInForLoop() throws Throwable {
841 assertStringItems 'final'
844 public void testFinalInForLoop2() throws Throwable {
846 assertStringItems 'final', 'finalize'
849 public void testOnlyClassesInExtends() throws Throwable {
851 assertStringItems 'Inner'
854 public void testPrimitiveTypesInForLoop() throws Throwable { doPrimitiveTypeTest() }
855 public void testPrimitiveTypesInForLoop2() throws Throwable { doPrimitiveTypeTest() }
856 public void testPrimitiveTypesInForLoop3() throws Throwable { doPrimitiveTypeTest() }
857 public void testPrimitiveTypesInForLoop4() throws Throwable { doPrimitiveTypeTest() }
858 public void testPrimitiveTypesInForLoop5() throws Throwable { doPrimitiveTypeTest() }
859 public void testPrimitiveTypesInForLoop6() throws Throwable { doPrimitiveTypeTest() }
861 public void testPrimitiveTypesInForLoopSpace() throws Throwable {
864 checkResultByFile(getTestName(false) + "_after.java")
867 public void testSecondInvocationToFillCommonPrefix() throws Throwable {
871 assertStringItems("fai1", "fai2", "fai3");
875 public void testSuggestInaccessibleOnSecondInvocation() throws Throwable {
877 assertStringItems("_bar", "_goo");
879 assertStringItems("_bar", "_goo", "_foo");
880 getLookup().setCurrentItem(getLookup().getItems().get(2));
881 selectItem(lookup.items[2], Lookup.NORMAL_SELECT_CHAR)
885 public void testNoCommonPrefixInsideIdentifier() throws Throwable {
886 final String path = getTestName(false) + ".java";
887 configureByFile(path);
888 checkResultByFile(path);
889 assertStringItems("fai1", "fai2");
892 public void testProtectedInaccessibleOnSecondInvocation() throws Throwable {
893 myFixture.configureByFile(getTestName(false) + ".java");
894 myFixture.complete(CompletionType.BASIC, 2);
898 public void testPropertyReferencePrefix() throws Throwable {
899 myFixture.addFileToProject("test.properties", "foo.bar=Foo! Bar!").getVirtualFile();
903 private void doTest() throws Exception {
908 private void doTest(String finishChar) throws Exception {
914 private void doAntiTest() throws Exception {
916 checkResultByFile(getTestName(false) + ".java");
917 assertEmpty(myItems);
918 assertNull(getLookup());
921 public void testSecondAnonymousClassParameter() throws Throwable { doTest(); }
923 public void testSpaceAfterReturn() throws Throwable {
929 private def checkResult() {
930 checkResultByFile(getTestName(false) + "_after.java")
933 public void testIntersectionTypeMembers() throws Throwable {
935 assertStringItems "fooa", "foob"
938 public void testCastInstanceofedQualifier() throws Throwable { doTest(); }
939 public void testCastComplexInstanceofedQualifier() throws Throwable { doTest(); }
941 public void testCastTooComplexInstanceofedQualifier() throws Throwable { doAntiTest(); }
942 public void testDontCastInstanceofedQualifier() throws Throwable { doTest(); }
943 public void testQualifierCastingWithUnknownAssignments() throws Throwable { doTest(); }
944 public void testQualifierCastingBeforeLt() throws Throwable { doTest(); }
945 public void testNoReturnInTernary() throws Throwable { doTest(); }
947 public void testOrAssignmentDfa() throws Throwable { doTest(); }
949 public void testWildcardsInLookup() throws Exception {
951 assertNotNull(getLookup());
953 final List<LookupElement> list = getLookup().getItems();
954 assertEquals("azzzfzzz", list.get(0).getLookupString());
955 assertEquals("fzazzz", list.get(1).getLookupString());
958 public void testTabReplacesMethodNameWithLocalVariableName() throws Throwable { doTest('\t'); }
959 public void testMethodParameterAnnotationClass() throws Throwable { doTest(); }
960 public void testPrimitiveCastOverwrite() throws Throwable { doTest '\t' }
961 public void testClassReferenceInFor() throws Throwable { doTest ' ' }
962 public void testClassReferenceInFor2() throws Throwable { doTest ' ' }
963 public void testClassReferenceInFor3() throws Throwable {
964 CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
969 CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER
973 public void testEnumConstantFromEnumMember() throws Throwable { doTest(); }
975 public void testPrimitiveMethodParameter() throws Throwable { doTest(); }
977 public void testNewExpectedClassParens() throws Throwable { doTest(); }
979 public void testQualifyInnerMembers() throws Throwable { doTest('\n') }
981 public void testSuggestExpectedTypeMembers() throws Throwable { doTest('\n') }
982 public void testSuggestExpectedTypeMembersInCall() throws Throwable { doTest('\n') }
983 public void testExpectedTypesDotSelectsItem() throws Throwable { doTest('.') }
985 public void testExpectedTypeMembersVersusStaticImports() throws Throwable {
987 assertStringItems('FOO', 'FOX')
990 public void testDoubleExpectedTypeFactoryMethod() throws Throwable {
992 assertStringItems('Key', 'create', 'create')
993 assert renderElement(myItems[1]).itemText == 'Key.<Boolean>create'
994 assert renderElement(myItems[2]).itemText == 'Key.create'
997 public void testSuggestExpectedTypeMembersNonImported() throws Throwable {
998 myFixture.addClass("package foo; public class Super { public static final Super FOO = null; }")
999 myFixture.addClass("package foo; public class Usage { public static void foo(Super s) {} }")
1003 public void testClassNameInIfBeforeIdentifier() throws Throwable {
1004 myFixture.addClass("public class ABCDEFFFFF {}")
1008 public void testClassNameWithInnersTab() throws Throwable { doTest('\t') }
1010 public void testClassNameWithGenericsTab() throws Throwable {doTest('\t') }
1011 public void testClassNameWithGenericsTab2() throws Throwable {doTest('\t') }
1013 public void testLiveTemplatePrefixTab() throws Throwable {doTest('\t') }
1015 public void testOnlyAnnotationsAfterAt() throws Throwable { doTest() }
1017 public void testOnlyExceptionsInCatch1() throws Exception { doTest() }
1018 public void testOnlyExceptionsInCatch2() throws Exception { doTest() }
1019 public void testOnlyExceptionsInCatch3() throws Exception { doTest() }
1020 public void testOnlyExceptionsInCatch4() throws Exception { doTest() }
1022 public void testCommaAfterVariable() throws Throwable { doTest(',') }
1024 public void testClassAngleBracket() throws Throwable { doTest('<') }
1025 public void testNoArgsMethodSpace() throws Throwable { doTest(' ') }
1027 public void testClassSquareBracket() throws Throwable { doTest('[') }
1028 public void testPrimitiveSquareBracket() throws Throwable { doTest('[') }
1029 public void testVariableSquareBracket() throws Throwable { doTest('[') }
1030 public void testMethodSquareBracket() throws Throwable { doTest('[') }
1032 public void testMethodParameterTypeDot() throws Throwable { doAntiTest() }
1033 public void testNewGenericClass() throws Throwable { doTest('\n') }
1034 public void testNewGenericInterface() throws Throwable { doTest() }
1035 public void testEnumPrivateFinal() throws Throwable { doTest() }
1037 public void testSwitchConstantsFromReferencedClass() throws Throwable { doTest('\n') }
1039 public void testUnfinishedMethodTypeParameter() throws Throwable {
1041 assertStringItems("MyParameter", "MySecondParameter")
1043 public void testUnfinishedMethodTypeParameter2() throws Throwable {
1045 assertStringItems("MyParameter", "MySecondParameter")
1048 public void testSuperProtectedMethod() throws Throwable {
1049 myFixture.addClass """package foo;
1051 protected void foo() { }
1056 public void testTopLevelClassesFromPackaged() throws Throwable {
1057 myFixture.addClass "public class Fooooo {}"
1058 final text = "package foo; class Bar { Fooo<caret> }"
1059 def file = myFixture.addFileToProject("foo/Bar.java", text)
1060 myFixture.configureFromExistingVirtualFile file.virtualFile
1061 assertEmpty myFixture.completeBasic()
1062 myFixture.checkResult text
1065 public void testRightShift() throws Throwable {
1067 assertStringItems("myField1", "myField2");
1070 public void testAfterCommonPrefix() throws Throwable {
1073 assertStringItems("equals", "equalsIgnoreCase");
1075 assertStringItems("equals", "equalsIgnoreCase");
1080 public void testClassNameInsideIdentifierInIf() throws Throwable {
1082 myFixture.complete(CompletionType.BASIC, 2)
1087 public void testKeywordSmartEnter() {
1089 myFixture.performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT)
1093 public void testImportStringValue() throws Throwable {
1094 myFixture.addClass("package foo; public class StringValue {}")
1095 myFixture.addClass("package java.lang; class StringValue {}")
1097 myFixture.complete(CompletionType.BASIC, 2)
1102 public void testPrimitiveArrayWithRBrace() throws Throwable { doTest '[' }
1104 public void testSuggestMembersOfStaticallyImportedClasses() throws Exception {
1105 myFixture.addClass("""package foo;
1107 public static void foo() {}
1108 public static void bar() {}
1114 public void testSuggestMembersOfStaticallyImportedClassesUnqualifiedOnly() throws Exception {
1115 def old = CodeInsightSettings.instance.SHOW_STATIC_AFTER_INSTANCE
1116 CodeInsightSettings.instance.SHOW_STATIC_AFTER_INSTANCE = true
1119 myFixture.addClass("""package foo;
1121 public static void foo() {}
1122 public static void bar() {}
1126 assertOneElement(myFixture.getLookupElements())
1131 CodeInsightSettings.instance.SHOW_STATIC_AFTER_INSTANCE = old
1135 public void testInstanceMagicMethod() throws Exception { doTest() }
1137 public void testNoDotOverwrite() throws Exception { doTest('.') }
1139 public void testStaticInnerExtendingOuter() throws Exception { doTest() }
1140 public void testPrimitiveClass() throws Exception { doTest() }
1141 public void testPrimitiveArrayClass() throws Exception { doTest() }
1142 public void testPrimitiveArrayOnlyClass() throws Exception { doAntiTest() }
1143 public void testPrimitiveArrayInAnno() throws Exception { doTest() }
1145 public void testSaxParserCommonPrefix() throws Exception {
1146 myFixture.addClass("public class SAXParser {}")
1147 myFixture.addClass("public class SAXParseException {}")
1151 public void testNewClassAngleBracket() throws Exception { doTest('<') }
1152 public void testNewClassSquareBracket() throws Exception { doTest('[') }
1154 public void testMethodColon() throws Exception { doTest(':') }
1155 public void testVariableColon() throws Exception { doTest(':') }
1157 public void testNoMethodsInParameterType() {
1159 assertOrderedEquals myFixture.lookupElementStrings, "final", "float"
1162 public void testStaticallyImportedFieldsTwice() {
1163 myFixture.addClass("""
1165 public static final int aZOO;
1168 myFixture.configureByText("a.java", """
1174 assertOneElement myFixture.completeBasic()
1177 public void testStatementKeywords() {
1178 myFixture.configureByText("a.java", """
1183 myFixture.completeBasic()
1184 final def strings = myFixture.lookupElementStrings
1185 assertTrue 'if' in strings
1186 assertTrue 'while' in strings
1187 assertTrue 'do' in strings
1188 assertTrue 'new' in strings
1189 assertTrue 'try' in strings
1191 strings.remove 'new'
1192 assertFalse 'new' in strings
1195 public void testExpressionKeywords() {
1196 myFixture.configureByText("a.java", """
1201 myFixture.completeBasic()
1202 final def strings = myFixture.lookupElementStrings
1203 assertTrue 'new' in strings
1206 public void testImportAsterisk() {
1207 myFixture.configureByText "a.java", "import java.lang.<caret>"
1208 myFixture.completeBasic()
1209 myFixture.type '*\n'
1210 myFixture.checkResult "import java.lang.*<caret>"
1213 public void testIntersectionTypesSOE() {
1214 myFixture.configureByText("a.java", """
1218 public boolean setLocation(Iterable<? extends File> path) {
1222 public void compile(List<File> classpath) {
1223 setLocation(<caret>);
1227 myFixture.completeBasic()
1228 myFixture.type '*\n'
1229 myFixture.checkResult """
1233 public boolean setLocation(Iterable<? extends File> path) {
1237 public void compile(List<File> classpath) {
1238 setLocation(classpath);
1244 public void testDontPreselectCaseInsensitivePrefixMatch() {
1245 CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
1247 myFixture.configureByText "a.java", "import java.io.*; class Foo {{ int fileSize; fil<caret>x }}"
1248 myFixture.completeBasic()
1249 assert lookup.currentItem.lookupString == 'fileSize'
1252 assert lookup.items[0].lookupString == 'File'
1253 assert lookup.items[1].lookupString == 'fileSize'
1254 assert lookup.currentItem == lookup.items[1]
1257 CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER
1261 public void testNoGenericsWhenChoosingWithParen() {
1263 myFixture.type 'Ma('
1267 public void testNoClosingWhenChoosingWithParenBeforeIdentifier() {