e14ee12ebec4fd91c1f81290a6600a4752b4c765
[idea/community.git] / java / java-tests / testSrc / com / intellij / java / codeInsight / completion / NormalCompletionTest.groovy
1 // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.java.codeInsight.completion
3
4 import com.intellij.codeInsight.CodeInsightSettings
5 import com.intellij.codeInsight.JavaProjectCodeInsightSettings
6 import com.intellij.codeInsight.completion.CompletionType
7 import com.intellij.codeInsight.completion.JavaPsiClassReferenceElement
8 import com.intellij.codeInsight.lookup.Lookup
9 import com.intellij.codeInsight.lookup.LookupElement
10 import com.intellij.codeInsight.lookup.LookupElementPresentation
11 import com.intellij.codeInsight.lookup.LookupManager
12 import com.intellij.codeInsight.lookup.impl.LookupImpl
13 import com.intellij.lang.java.JavaLanguage
14 import com.intellij.openapi.actionSystem.IdeActions
15 import com.intellij.psi.PsiClass
16 import com.intellij.psi.PsiDocumentManager
17 import com.intellij.psi.PsiMethod
18 import com.intellij.psi.PsiTypeParameter
19 import com.intellij.psi.codeStyle.CodeStyleSettingsManager
20 import com.intellij.psi.codeStyle.CommonCodeStyleSettings
21 import com.intellij.psi.codeStyle.JavaCodeStyleSettings
22 import com.intellij.testFramework.LightProjectDescriptor
23 import com.intellij.testFramework.NeedsIndex
24 import com.intellij.testFramework.PlatformTestUtil
25 import com.intellij.util.ui.UIUtil
26 import com.siyeh.ig.style.UnqualifiedFieldAccessInspection
27 import groovy.transform.CompileStatic
28 import org.jetbrains.annotations.NotNull
29
30 @CompileStatic
31 class NormalCompletionTest extends NormalCompletionTestCase {
32
33   @NotNull
34   @Override
35   protected LightProjectDescriptor getProjectDescriptor() {
36     return JAVA_9
37   }
38
39   void testSimple() throws Exception {
40     configureByFile("Simple.java")
41     assertStringItems("_local1", "_local2", "_field", "_baseField", "_method", "_baseMethod")
42   }
43
44   void testCastToPrimitive1() throws Exception {
45     configureByFile("CastToPrimitive1.java")
46
47     for (final LookupElement item : myItems) {
48       if (item.getLookupString().equals("int")) return
49     }
50     assertTrue(false)
51   }
52
53   void testCastToPrimitive2() throws Exception {
54     configureByFile("CastToPrimitive2.java")
55
56     for (final LookupElement item : myItems) {
57       if (item.getLookupString().equals("int")) return
58     }
59     assertTrue(false)
60   }
61
62   void testCastToPrimitive3() throws Exception {
63     configureByFile("CastToPrimitive3.java")
64
65     for (final LookupElement item : myItems) {
66       if (item.getLookupString().equals("int")) return
67     }
68     assertTrue(false)
69   }
70
71   void testWriteInInvokeLater() throws Exception {
72     configureByFile("WriteInInvokeLater.java")
73   }
74
75   void testQualifiedNew1() throws Exception {
76     configure()
77     assertStringItems "IInner", "Inner"
78   }
79
80   void testQualifiedNew2() throws Exception {
81     configure()
82     assertStringItems "AnInner", "Inner"
83   }
84
85   void testKeywordsInName() throws Exception {
86     doTest 'a\n'
87   }
88
89   @NeedsIndex.ForStandardLibrary
90   void testSimpleVariable() throws Exception { doTest('\n') }
91
92   void testTypeParameterItemPresentation() {
93     configure()
94     LookupElementPresentation presentation = renderElement(myItems[0])
95     assert "Param" == presentation.itemText
96     assert presentation.tailText == " type parameter of Foo"
97     assert !presentation.typeText
98     assert !presentation.icon
99     assert !presentation.itemTextBold
100
101     presentation = renderElement(myItems[1])
102     assert "Param2" == presentation.itemText
103     assert presentation.tailText == " type parameter of goo"
104   }
105
106   void testDisplayDefaultValueInAnnotationMethods() {
107     configure()
108     LookupElementPresentation presentation = renderElement(myItems[0])
109     assert "myInt" == presentation.itemText
110     assert presentation.tailText == " default 42"
111     assert presentation.tailFragments[0].grayed
112     assert !presentation.typeText
113     assert !presentation.itemTextBold
114
115     presentation = renderElement(myItems[1])
116     assert "myString" == presentation.itemText
117     assert presentation.tailText == ' default "unknown"'
118   }
119
120   @NeedsIndex.ForStandardLibrary
121   void testMethodItemPresentation() {
122     configure()
123     LookupElementPresentation presentation = renderElement(myItems[0])
124     assert "equals" == presentation.itemText
125     assert "(Object anObject)" == presentation.tailText
126     assert "boolean" == presentation.typeText
127
128     assert !presentation.tailFragments.any { it.grayed }
129     assert presentation.itemTextBold
130   }
131
132   void testFieldItemPresentationGenerics() {
133     configure()
134     LookupElementPresentation presentation = renderElement(myItems[0])
135     assert "target" == presentation.itemText
136     assert !presentation.tailText
137     assert "String" == presentation.typeText
138   }
139
140   @NeedsIndex.ForStandardLibrary
141   void testMethodItemPresentationGenerics() {
142     configure()
143     LookupElementPresentation presentation = renderElement(myItems[1])
144     assert "add" == presentation.itemText
145     assert "(int index, String element)" == presentation.tailText
146     assert "void" == presentation.typeText
147
148     presentation = renderElement(myItems[0])
149     assert "(String e)" == presentation.tailText
150     assert "boolean" == presentation.typeText
151
152     assert !presentation.tailFragments.any { it.grayed }
153     assert presentation.itemTextBold
154   }
155
156   void testPreferLongerNamesOption() throws Exception {
157     configureByFile("PreferLongerNamesOption.java")
158
159     assertEquals(3, myItems.length)
160     assertEquals("abcdEfghIjk", myItems[0].getLookupString())
161     assertEquals("efghIjk", myItems[1].getLookupString())
162     assertEquals("ijk", myItems[2].getLookupString())
163
164     LookupManager.getInstance(getProject()).hideActiveLookup()
165
166     JavaCodeStyleSettings.getInstance(getProject()).PREFER_LONGER_NAMES = false
167       configureByFile("PreferLongerNamesOption.java")
168
169       assertEquals(3, myItems.length)
170       assertEquals("ijk", myItems[0].getLookupString())
171       assertEquals("efghIjk", myItems[1].getLookupString())
172       assertEquals("abcdEfghIjk", myItems[2].getLookupString())
173   }
174
175   void testSCR7208() throws Exception {
176     configureByFile("SCR7208.java")
177   }
178
179   @NeedsIndex.ForStandardLibrary
180   void testProtectedFromSuper() throws Exception {
181     configureByFile("ProtectedFromSuper.java")
182     Arrays.sort(myItems)
183     assertTrue("Exception not found", Arrays.binarySearch(myItems, "xxx") > 0)
184   }
185
186   @NeedsIndex.ForStandardLibrary
187   void testBeforeInitialization() throws Exception {
188     configureByFile("BeforeInitialization.java")
189     assertNotNull(myItems)
190     assertTrue(myItems.length > 0)
191   }
192
193   @NeedsIndex.ForStandardLibrary
194   void testProtectedFromSuper2() throws Exception {
195
196     configureByFile("ProtectedFromSuper.java")
197     Arrays.sort(myItems)
198     assertTrue("Exception not found", Arrays.binarySearch(myItems, "xxx") > 0)
199   }
200
201   void testClassLiteralInArrayAnnoInitializer() throws Throwable { doTest() }
202
203   void testClassLiteralInArrayAnnoInitializer2() throws Throwable { doTest() }
204
205   void testReferenceParameters() throws Exception {
206     configureByFile("ReferenceParameters.java")
207     assertNotNull(myItems)
208     myFixture.assertPreferredCompletionItems 0, 'AAAA', 'AAAB'
209   }
210
211   @Override
212   protected void tearDown() throws Exception {
213     CodeInsightSettings.instance.AUTOCOMPLETE_ON_CODE_COMPLETION = true
214     CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.FIRST_LETTER)
215     CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = true
216     super.tearDown()
217   }
218
219   void testConstructorName1() throws Exception {
220     CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false
221     configure()
222     assert 'ABCDE' in myFixture.lookupElementStrings
223   }
224
225   void testConstructorName2() throws Exception {
226     CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false
227     configure()
228     assert 'ABCDE' in myFixture.lookupElementStrings
229   }
230
231   @NeedsIndex.ForStandardLibrary
232   void testObjectsInThrowsBlock() throws Exception {
233     configureByFile("InThrowsCompletion.java")
234     assert "C" == myFixture.lookupElementStrings[0]
235     assert "B" in myFixture.lookupElementStrings
236   }
237
238   void testAnnoParameterValue() throws Exception {
239     configure()
240     def strings = myFixture.lookupElementStrings
241     assert 'AssertionError' in strings
242     assert !('enum' in strings)
243     assert !('final' in strings)
244     assert !('equals' in strings)
245     assert !('new' in strings)
246     assert !('null' in strings)
247     assert !('public' in strings)
248     assert !('super' in strings)
249     assert !('null' in strings)
250   }
251
252   void testAfterInstanceof() throws Exception {
253     configureByFile("AfterInstanceof.java")
254     assert "A" in myFixture.lookupElementStrings
255   }
256
257   void testAfterCast1() throws Exception {
258     configureByFile("AfterCast1.java")
259
260     assertNotNull(myItems)
261     assertEquals(2, myItems.length)
262   }
263
264   void testAfterCast2() throws Exception {
265     configureByFile("AfterCast2.java")
266     checkResultByFile("AfterCast2-result.java")
267   }
268
269   void testMethodCallForTwoLevelSelection() throws Exception {
270     configureByFile("MethodLookup.java")
271     assertEquals(2, myItems.length)
272   }
273
274   void testMethodCallBeforeAnotherStatementWithParen() throws Exception {
275     configureByFile("MethodLookup2.java")
276     checkResultByFile("MethodLookup2_After.java")
277   }
278
279   void testMethodCallBeforeAnotherStatementWithParen2() throws Exception {
280     codeStyleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true
281     configureByFile("MethodLookup2.java")
282     checkResultByFile("MethodLookup2_After2.java")
283   }
284
285   void testSwitchEnumLabel() throws Exception {
286     configureByFile("SwitchEnumLabel.java")
287     assertEquals(3, myItems.length)
288   }
289
290   void testSwitchCaseWithEnumConstant() { doTest() }
291
292   void testSecondSwitchCaseWithEnumConstant() { doTest() }
293
294   @NeedsIndex.ForStandardLibrary
295   void testInsideSwitchCaseWithEnumConstant() {
296     configure()
297     myFixture.assertPreferredCompletionItems 0, 'compareTo', 'equals'
298   }
299
300   void testMethodInAnnotation() throws Exception {
301     configureByFile("Annotation.java")
302     checkResultByFile("Annotation_after.java")
303   }
304
305   void testMethodInAnnotation2() throws Exception {
306     configureByFile("Annotation2.java")
307     checkResultByFile("Annotation2_after.java")
308   }
309
310   void testMethodInAnnotation3() throws Exception {
311     configureByFile("Annotation3.java")
312     checkResultByFile("Annotation3_after.java")
313   }
314
315   void testMethodInAnnotation5() throws Exception {
316     configureByFile("Annotation5.java")
317     checkResultByFile("Annotation5_after.java")
318   }
319
320   void testMethodInAnnotation7() throws Exception {
321     configureByFile("Annotation7.java")
322     selectItem(myItems[0])
323     checkResultByFile("Annotation7_after.java")
324   }
325
326   void testEnumInAnnotation() throws Exception {
327     configureByFile("Annotation4.java")
328     checkResultByFile("Annotation4_after.java")
329   }
330
331   void testSecondAttribute() throws Exception {
332     configureByFile("Annotation6.java")
333     checkResultByFile("Annotation6_after.java")
334   }
335
336   void testIDEADEV6408() throws Exception {
337     configureByFile("IDEADEV6408.java")
338     assertFirstStringItems "boolean", "byte"
339   }
340
341   void testMethodWithLeftParTailType() throws Exception {
342     configureByFile("MethodWithLeftParTailType.java")
343     type('(')
344     checkResultByFile("MethodWithLeftParTailType_after.java")
345
346     configureByFile("MethodWithLeftParTailType2.java")
347     type('(')
348     checkResultByFile("MethodWithLeftParTailType2_after.java")
349   }
350
351   void testSuperErasure() throws Exception {
352     configureByFile("SuperErasure.java")
353     checkResultByFile("SuperErasure_after.java")
354   }
355
356   void testMethodWithLeftParTailTypeNoPairBrace() throws Exception {
357     CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false
358     doTest('(')
359   }
360
361   void testMethodWithLeftParTailTypeNoPairBrace2() throws Exception {
362     CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false
363
364     //no tail type should work the normal way
365     configureByFile("MethodWithLeftParTailTypeNoPairBrace.java")
366     selectItem(myItems[0])
367     checkResultByFile("MethodWithLeftParTailTypeNoPairBrace_after2.java")
368   }
369
370   void testMethodNoPairBrace() throws Exception {
371     CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false
372     doTest '\n'
373   }
374
375   void testExcessSpaceInTypeCast() throws Throwable {
376    configure()
377    selectItem(myItems[0])
378    checkResult()
379   }
380
381   void testFieldType() { doTest() }
382
383   void testFieldOfLocalClass() {
384     configure()
385     assert renderElement(myItems[0]).itemText == 'field'
386     type('\t')
387     checkResult()
388   }
389
390   void testPackageInAnnoParam() throws Throwable {
391     doTest()
392   }
393
394   void testAnonymousTypeParameter() throws Throwable { doTest() }
395
396   @NeedsIndex.ForStandardLibrary
397   void testClassLiteralInAnnoParam() throws Throwable {
398     doTest()
399   }
400
401   @NeedsIndex.ForStandardLibrary
402   void testNoForceBraces() {
403     codeStyleSettings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS
404     doTest('\n')
405   }
406
407   void testExcludeStringBuffer() throws Throwable {
408     JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, StringBuffer.name)
409     configure()
410     assert !('StringBuffer' in myFixture.lookupElementStrings)
411   }
412
413   @NeedsIndex.Full
414   void testExcludeInstanceInnerClasses() throws Throwable {
415     JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo")
416     myFixture.addClass 'package foo; public class Outer { public class Inner {} }'
417     myFixture.addClass 'package bar; public class Inner {}'
418     configure()
419     assert 'bar.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName
420     assert myFixture.lookupElementStrings == ['Inner']
421   }
422
423   @NeedsIndex.Full
424   void testExcludedInstanceInnerClassCreation() throws Throwable {
425     JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo")
426     myFixture.addClass 'package foo; public class Outer { public class Inner {} }'
427     myFixture.addClass 'package bar; public class Inner {}'
428     configure()
429     assert 'foo.Outer.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName
430     assert myFixture.lookupElementStrings == ['Inner']
431   }
432
433   @NeedsIndex.Full
434   void testExcludedInstanceInnerClassQualifiedReference() throws Throwable {
435     JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo")
436     myFixture.addClass 'package foo; public class Outer { public class Inner {} }'
437     myFixture.addClass 'package bar; public class Inner {}'
438     configure()
439     assert 'foo.Outer.Inner' == ((JavaPsiClassReferenceElement)myFixture.lookupElements[0]).qualifiedName
440     assert myFixture.lookupElementStrings == ['Inner']
441   }
442
443   @NeedsIndex.Full
444   void testStaticMethodOfExcludedClass() {
445     JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo")
446     myFixture.addClass 'package foo; public class Outer { public static void method() {} }'
447     configure()
448     assert myFixture.lookupElementStrings == ['method']
449   }
450
451   @NeedsIndex.Full
452   void testExcludeWildcards() {
453     JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo.Outer.*1*")
454     myFixture.addClass '''
455 package foo; 
456 public class Outer { 
457   public static void method1() {} 
458   public static void method2() {} 
459   public static void method12() {} 
460   public static void method42() {} 
461 }'''
462     myFixture.configureByText 'a.java', 'class C {{ foo.Outer.m<caret> }}'
463     myFixture.completeBasic()
464     assert myFixture.lookupElementStrings == ['method2', 'method42']
465   }
466
467   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for int hashCode lookup preventing autocompletion and additional \n)")
468   void testAtUnderClass() throws Throwable {
469     doTest('\n')
470   }
471
472   void testLocalClassName() throws Throwable { doTest() }
473
474   void testAssigningFieldForTheFirstTime() throws Throwable { doTest() }
475
476   void testClassTypeParameters() throws Throwable {
477     configure()
478     assert 'K' in myFixture.lookupElementStrings
479   }
480
481   void testClassTypeParametersGenericBounds() throws Throwable {
482     configure()
483     assert 'K' in myFixture.lookupElementStrings
484   }
485
486   @NeedsIndex.ForStandardLibrary
487   void testLocalClassTwice() throws Throwable {
488     configure()
489     assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo', 'ZipOutputStream'
490   }
491
492   @NeedsIndex.ForStandardLibrary
493   void testLocalTopLevelConflict() throws Throwable {
494     configure()
495     assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo', 'ZipOutputStream'
496   }
497
498   @NeedsIndex.ForStandardLibrary
499   void testFinalBeforeMethodCall() throws Throwable {
500     configure()
501     assertStringItems 'final', 'finalize'
502   }
503
504   void testMethodCallAfterFinally() { doTest() }
505
506   void testPrivateInAnonymous() throws Throwable { doTest() }
507
508   void testStaticMethodFromOuterClass() {
509     configure()
510     assertStringItems 'foo', 'A.foo', 'for'
511     assert renderElement(myItems[1]).itemText == 'A.foo'
512     selectItem(myItems[1])
513     checkResult()
514   }
515
516   void testInstanceMethodFromOuterClass() {
517     configure()
518     assertStringItems 'foo', 'A.this.foo', 'for'
519     assert renderElement(myItems[1]).itemText == 'A.this.foo'
520     selectItem(myItems[1])
521     checkResult()
522   }
523
524   void testMethodParenthesesSpaces() throws Throwable {
525     codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
526     codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
527     doTest()
528   }
529
530   void testMethodParenthesesSpacesArgs() throws Throwable {
531     codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
532     codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
533     doTest()
534   }
535
536   void testAtUnderClassNoModifiers() throws Throwable {
537     doTest()
538   }
539
540   void testBreakInIfCondition() throws Throwable { doTest() }
541
542   void testAccessStaticViaInstance() throws Throwable { doTest() }
543
544   void testIfConditionLt() {
545     configure()
546     myFixture.assertPreferredCompletionItems 0, 'getAnnotationsAreaOffset'
547   }
548
549   @NeedsIndex.ForStandardLibrary(reason = "On emptly indices 'foo' is the only item, so is not filtered out in  JavaCompletionProcessor.dispreferStaticAfterInstance")
550   void testAccessStaticViaInstanceSecond() throws Throwable {
551     configure()
552     assert !('foo' in myFixture.lookupElementStrings)
553     myFixture.complete(CompletionType.BASIC, 2)
554     myFixture.assertPreferredCompletionItems 0, 'foo'
555     myFixture.type('\n')
556     checkResult()
557   }
558
559   void testAccessInstanceFromStaticSecond() throws Throwable {
560     configure()
561     myFixture.complete(CompletionType.BASIC, 2)
562     checkResult()
563   }
564
565   void testBreakLabel() {
566     myFixture.configureByText("a.java", """
567       class a {{
568         foo: while (true) break <caret>
569       }}""".stripIndent())
570     complete()
571     assert myFixture.lookupElementStrings == ['foo']
572   }
573
574   void testContinueLabel() {
575     myFixture.configureByText("a.java", """
576       class a {{
577         foo: while (true) continue <caret>
578       }}""".stripIndent())
579     complete()
580     assert myFixture.lookupElementStrings == ['foo']
581   }
582
583   void testContinueLabelTail() {
584     myFixture.configureByText("a.java", """
585       class a {{
586         foo: while (true) con<caret>
587       }}""".stripIndent())
588     complete()
589     myFixture.checkResult("""
590       class a {{
591         foo: while (true) continue <caret>
592       }}""".stripIndent())
593   }
594
595   @NeedsIndex.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
596   void testAnonymousProcess() {
597     myFixture.addClass 'package java.lang; public class Process {}'
598     myFixture.addClass '''
599 import java.util.*;
600 public class Process {}
601 interface Pred <A> { boolean predicate(A elem); }
602 public class ListUtils {
603     public static <A> List<A> filter(List<A> list, Pred<A> pred) {}
604 }
605 '''
606     configure()
607     type '\n'
608     checkResult()
609   }
610
611   void testNoThisInComment() throws Throwable { doAntiTest() }
612
613   void testIncNull() throws Throwable {
614     configure()
615     checkResultByFile(getTestName(false) + ".java")
616     assert !('null' in myFixture.lookupElementStrings)
617   }
618
619   void testLastExpressionInFor() throws Throwable { doTest() }
620
621   void testOnlyKeywordsInsideSwitch() throws Throwable {
622     configureByFile(getTestName(false) + ".java")
623     assertStringItems("case", "default")
624   }
625
626   @NeedsIndex.ForStandardLibrary
627   void testBooleanLiterals() throws Throwable {
628     doTest('\n')
629   }
630
631   void testDoubleBooleanInParameter() throws Throwable {
632     configure()
633     assertFirstStringItems("boolean", "byte")
634   }
635
636   void testDoubleConstant() throws Throwable {
637     configure()
638     assertStringItems("Intf.XFOO", "XFOO")
639   }
640
641   void testNotOnlyKeywordsInsideSwitch() throws Throwable {
642     doTest()
643   }
644
645   @NeedsIndex.ForStandardLibrary
646   void testChainedCallOnNextLine() throws Throwable {
647     configureByFile(getTestName(false) + ".java")
648     selectItem(myItems[0])
649     checkResult()
650   }
651
652   void testFinishWithDot() throws Throwable {
653     configureByFile(getTestName(false) + ".java")
654     type('.')
655     checkResult()
656   }
657
658   void testEnclosingThis() throws Throwable { doTest() }
659
660   @NeedsIndex.Full
661   void testSeamlessConstant() throws Throwable {
662     configureByFile(getTestName(false) + ".java")
663     selectItem(myItems[0])
664     checkResult()
665   }
666
667   void testDefaultAnnoParam() throws Throwable { doTest() }
668
669   void testSpaceAfterLookupString() throws Throwable {
670     configureByFile(getTestName(false) + ".java")
671     type(' ')
672     assertNull(getLookup())
673     checkResult()
674   }
675
676   @NeedsIndex.ForStandardLibrary
677   void testNoSpaceInParensWithoutParams() throws Throwable {
678     codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
679     try {
680       doTest()
681     }
682     finally {
683       codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false
684     }
685   }
686
687   @NeedsIndex.ForStandardLibrary
688   void testTwoSpacesInParensWithParams() throws Throwable {
689     codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
690     doTest()
691   }
692
693   @NeedsIndex.ForStandardLibrary
694   void testQualifierAsPackage() throws Throwable {
695     configureByFile(getTestName(false) + ".java")
696     selectItem(myItems[0])
697     checkResult()
698   }
699
700   @NeedsIndex.ForStandardLibrary
701   void testQualifierAsPackage2() throws Throwable {
702     doTest()
703   }
704
705   @NeedsIndex.ForStandardLibrary
706   void testQualifierAsPackage3() throws Throwable {
707     doTest()
708   }
709
710   @NeedsIndex.ForStandardLibrary
711   void testPreselectEditorSelection() {
712     configure()
713     assert lookup.currentItem != myFixture.lookupElements[0]
714     assert 'finalize' == lookup.currentItem.lookupString
715   }
716
717   void testNoMethodsInNonStaticImports() {
718     configure()
719     assertStringItems("*")
720   }
721
722   @NeedsIndex.ForStandardLibrary
723   void testMembersInStaticImports() { doTest('\n') }
724
725   @NeedsIndex.ForStandardLibrary
726   void testPackageNamedVariableBeforeAssignment() throws Throwable {
727     doTest()
728   }
729
730   void testInnerEnumConstant() throws Throwable { doTest('\n') }
731
732   void testNoExpectedReturnTypeDuplication() {
733     configure()
734     assert myFixture.lookupElementStrings == ['boolean', 'byte']
735   }
736   void testNoExpectedVoidReturnTypeDuplication() {
737     configure()
738     assert myFixture.lookupElementStrings == ['void']
739   }
740
741   void testNoExpectedArrayTypeDuplication() {
742     configure()
743     assert myFixture.lookupElementStrings == ['char']
744   }
745
746   void testShadowedTypeParameter() {
747     configure()
748     assert myFixture.lookupElementStrings == ['MyParam']
749   }
750
751   @NeedsIndex.ForStandardLibrary
752   void testMethodReturnType() { doTest('\n') }
753
754   void testMethodReturnTypeNoSpace() throws Throwable {
755     configureByFile(getTestName(false) + ".java")
756     selectItem(myItems[0])
757     checkResult()
758   }
759
760   void testEnumWithoutConstants() throws Throwable {
761     doTest()
762   }
763
764   @NeedsIndex.ForStandardLibrary
765   void testDoWhileMethodCall() throws Throwable {
766     doTest()
767   }
768
769   void testSecondTypeParameterExtends() throws Throwable {
770     doTest()
771   }
772
773   @NeedsIndex.ForStandardLibrary
774   void testGetterWithExistingNonEmptyParameterList() throws Throwable {
775     doTest()
776   }
777
778   void testNothingAfterNumericLiteral() throws Throwable { doAntiTest() }
779
780   void testNothingAfterTypeParameterQualifier() { doAntiTest() }
781
782   void testExcludeVariableBeingDeclared() { doAntiTest() }
783
784   void testExcludeVariableBeingDeclared2() { doAntiTest() }
785
786   void testSpacesAroundEq() throws Throwable { doTest('=') }
787
788   void _testClassBeforeCast() throws Throwable { doTest '\n' }
789
790   void testNoAllClassesOnQualifiedReference() throws Throwable {
791     doAntiTest()
792   }
793
794   void testFinishClassNameWithDot() throws Throwable {
795     doTest('.')
796   }
797
798   @NeedsIndex.ForStandardLibrary
799   void testFinishClassNameWithLParen() throws Throwable {
800     doTest('(')
801   }
802
803   void testSelectNoParameterSignature() throws Throwable {
804     configureByFile(getTestName(false) + ".java")
805     final int parametersCount = ((PsiMethod)getLookup().getCurrentItem().getObject()).getParameterList().getParametersCount()
806     assertEquals(0, parametersCount)
807     type '\n'
808     checkResult()
809   }
810
811   @NeedsIndex.ForStandardLibrary
812   void testCompletionInsideClassLiteral() throws Throwable {
813     configureByFile(getTestName(false) + ".java")
814     type('\n')
815     checkResult()
816   }
817
818   void testFieldNegation() throws Throwable { doTest('!') }
819
820   void testDefaultInSwitch() throws Throwable { doTest() }
821
822   void testBreakInSwitch() throws Throwable { doTest() }
823
824   void testSuperInConstructor() throws Throwable {
825     doTest()
826   }
827
828   @NeedsIndex.ForStandardLibrary
829   void testSuperInConstructorWithParams() throws Throwable {
830     doTest()
831   }
832
833   void testSuperInMethod() throws Throwable {
834     doTest()
835   }
836
837   void testSecondMethodParameterName() throws Throwable {
838     doTest()
839   }
840
841   void testAnnotationAsUsualObject() throws Throwable {
842     doTest()
843   }
844
845   void testAnnotationAsUsualObjectFromJavadoc() throws Throwable {
846     doTest()
847   }
848
849   void testAnnotationAsUsualObjectInsideClass() throws Throwable {
850     doTest()
851   }
852
853   void testAnnotationOnNothingParens() throws Throwable {
854     doTest()
855   }
856
857   void testMultiResolveQualifier() throws Throwable {
858     doTest()
859   }
860
861   void testSecondMethodParameter() throws Throwable { doTest() }
862
863   void testReturnInCase() throws Throwable { doTest() }
864
865   void testUnboxedConstantsInCase() throws Throwable { doTest() }
866
867   void testAnnotationWithoutValueMethod() throws Throwable {
868     configureByFile(getTestName(false) + ".java")
869     assertStringItems("bar", "foo")
870   }
871
872   void testAddExplicitValueInAnnotation() throws Throwable {
873     configureByTestName()
874     assertStringItems("bar", "goo")
875     selectItem(myItems[0])
876     checkResult()
877   }
878
879   void testUnnecessaryMethodMerging() throws Throwable {
880     configureByFile(getTestName(false) + ".java")
881     assertStringItems("fofoo", "fofoo")
882   }
883
884   @NeedsIndex.ForStandardLibrary
885   void testMethodMergingMinimalTail() { doTest() }
886
887   void testAnnotationQualifiedName() throws Throwable {
888     doTest()
889   }
890
891   @NeedsIndex.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
892   void testClassNameAnonymous() throws Throwable {
893     doTest('\n')
894   }
895
896   @NeedsIndex.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
897   void testClassNameWithInner() throws Throwable {
898     configure()
899     assertStringItems 'Zzoo', 'Zzoo.Impl'
900     type '\n'
901     checkResult()
902   }
903
904   void testClassNameWithInner2() throws Throwable { doTest('\n') }
905
906   void testClassNameWithInstanceInner() throws Throwable { doTest('\n') }
907
908   @NeedsIndex.ForStandardLibrary
909   void testDoubleFalse() throws Throwable {
910     configureByFile(getTestName(false) + ".java")
911     assertFirstStringItems("false", "fefefef", "float", "finalize")
912   }
913
914   void testSameNamedVariableInNestedClasses() throws Throwable {
915     configure()
916     myFixture.assertPreferredCompletionItems 0, "ffid", "Beda.this.ffid"
917     selectItem(myItems[1])
918     checkResult()
919   }
920
921   void testHonorUnderscoreInPrefix() throws Throwable {
922     doTest()
923   }
924
925   @NeedsIndex.ForStandardLibrary
926   void testNoSemicolonAfterExistingParenthesesEspeciallyIfItsACast() throws Throwable { doTest() }
927
928   void testReturningTypeVariable() throws Throwable { doTest() }
929
930   void testReturningTypeVariable2() throws Throwable { doTest() }
931
932   void testReturningTypeVariable3() throws Throwable { doTest() }
933
934   @NeedsIndex.ForStandardLibrary
935   void testImportInGenericType() throws Throwable {
936     configure()
937     myFixture.complete(CompletionType.BASIC, 2)
938     myFixture.type('\n')
939     checkResult()
940   }
941
942   void testCaseTailType() throws Throwable { doTest() }
943
944   def doPrimitiveTypeTest() {
945     configure()
946     checkResultByFile(getTestName(false) + ".java")
947     assertTrue 'boolean' in myFixture.lookupElementStrings
948   }
949
950   void testFinalInForLoop() throws Throwable {
951     configure()
952     assertStringItems 'final'
953   }
954
955   @NeedsIndex.ForStandardLibrary
956   void testFinalInForLoop2() throws Throwable {
957     configure()
958     myFixture.assertPreferredCompletionItems 0, 'finalize', 'final'
959   }
960
961   void testOnlyClassesInExtends() throws Throwable {
962     configure()
963     assertStringItems 'Inner'
964   }
965
966   void testNoThisClassInExtends() throws Throwable {
967     configure()
968     assertStringItems 'Fooxxxx2'
969   }
970
971   void testPrimitiveTypesInForLoop() throws Throwable { doPrimitiveTypeTest() }
972
973   void testPrimitiveTypesInForLoop2() throws Throwable { doPrimitiveTypeTest() }
974
975   void testPrimitiveTypesInForLoop3() throws Throwable { doPrimitiveTypeTest() }
976
977   void testPrimitiveTypesInForLoop4() throws Throwable { doPrimitiveTypeTest() }
978
979   void testPrimitiveTypesInForLoop5() throws Throwable { doPrimitiveTypeTest() }
980
981   void testPrimitiveTypesInForLoop6() throws Throwable { doPrimitiveTypeTest() }
982
983   void testPrimitiveTypesInForLoopSpace() throws Throwable {
984     configure()
985     myFixture.type ' '
986     checkResultByFile(getTestName(false) + "_after.java")
987   }
988
989   void testSuggestInaccessibleOnSecondInvocation() throws Throwable {
990     configure()
991     assertStringItems("_bar", "_goo")
992     complete()
993     assertStringItems("_bar", "_goo", "_foo")
994     getLookup().setCurrentItem(getLookup().getItems().get(2))
995     selectItem(lookup.items[2], Lookup.NORMAL_SELECT_CHAR)
996     checkResult()
997   }
998
999   void testNoCommonPrefixInsideIdentifier() throws Throwable {
1000     final String path = getTestName(false) + ".java"
1001     configureByFile(path)
1002     checkResultByFile(path)
1003     assertStringItems("fai1", "fai2")
1004   }
1005
1006   @NeedsIndex.Full
1007   void testProtectedInaccessibleOnSecondInvocation() throws Throwable {
1008     myFixture.configureByFile(getTestName(false) + ".java")
1009     myFixture.complete(CompletionType.BASIC, 2)
1010     myFixture.type('\n')
1011     checkResult()
1012   }
1013
1014   void testPropertyReferencePrefix() throws Throwable {
1015     myFixture.addFileToProject("test.properties", "foo.bar=Foo! Bar!").getVirtualFile()
1016     doAntiTest()
1017   }
1018
1019   @NeedsIndex.ForStandardLibrary
1020   void testSecondAnonymousClassParameter() { doTest() }
1021
1022   void testSpaceAfterReturn() throws Throwable {
1023     configure()
1024     type '\n'
1025     checkResult()
1026   }
1027
1028   void testIntersectionTypeMembers() throws Throwable {
1029     configure()
1030     assertStringItems "fooa", "foob"
1031   }
1032
1033   void testNoReturnInTernary() throws Throwable { doTest() }
1034
1035   void testWildcardsInLookup() throws Exception {
1036     configure()
1037     assertNotNull(getLookup())
1038     type('*fz')
1039     assert !lookup
1040   }
1041
1042   void testSmartEnterWrapsConstructorCall() throws Throwable { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
1043
1044   void testSmartEnterNoNewLine() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
1045
1046   void testSmartEnterWithNewLine() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
1047
1048   @NeedsIndex.SmartMode(reason = "MethodCallFixer.apply needs smart mode to count number of parameters")
1049   void testSmartEnterGuessArgumentCount() throws Throwable { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
1050
1051   void testSmartEnterInsideArrayBrackets() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
1052
1053   void testTabReplacesMethodNameWithLocalVariableName() throws Throwable { doTest('\t') }
1054
1055   void testMethodParameterAnnotationClass() throws Throwable { doTest() }
1056
1057   @NeedsIndex.Full
1058   void testInnerAnnotation() {
1059     configure()
1060     assert myFixture.lookupElementStrings == ['Dependency']
1061     type '\t'
1062     checkResult()
1063   }
1064
1065   void testPrimitiveCastOverwrite() throws Throwable { doTest() }
1066
1067   void testClassReferenceInFor() throws Throwable { doTest ' ' }
1068
1069   void testClassReferenceInFor2() throws Throwable { doTest ' ' }
1070
1071   void testClassReferenceInFor3() throws Throwable {
1072     CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.NONE)
1073     doTest ' '
1074   }
1075
1076   void testEnumConstantFromEnumMember() throws Throwable { doTest() }
1077
1078   void testPrimitiveMethodParameter() throws Throwable { doTest() }
1079
1080   void testNewExpectedClassParens() throws Throwable { doTest('\n') }
1081
1082   void testQualifyInnerMembers() throws Throwable { doTest('\n') }
1083
1084   void testDeepInner() throws Throwable {
1085     configure()
1086     assert myFixture.lookupElementStrings == ['ClassInner1', 'ClassInner1.ClassInner2']
1087     selectItem(lookup.items[1])
1088     checkResult()
1089   }
1090
1091   void testSuggestExpectedTypeMembers() throws Throwable { doTest('\n') }
1092
1093   void testSuggestExpectedTypeMembersInCall() throws Throwable { doTest('\n') }
1094
1095   void testSuggestExpectedTypeMembersInAnno() throws Throwable { doTest('\n') }
1096
1097   void testExpectedTypesDotSelectsItem() throws Throwable { doTest('.') }
1098
1099   @NeedsIndex.Full
1100   void testExpectedTypeMembersVersusStaticImports() throws Throwable {
1101     configure()
1102     assertStringItems('XFOO', 'XFOX')
1103   }
1104
1105   @NeedsIndex.Full
1106   void testSuggestExpectedTypeMembersNonImported() throws Throwable {
1107     myFixture.addClass("package foo; public class Super { public static final Super FOO = null; }")
1108     myFixture.addClass("package foo; public class Usage { public static void foo(Super s) {} }")
1109     doTest('\n')
1110   }
1111
1112   @NeedsIndex.Full
1113   void testStaticallyImportedInner() throws Throwable {
1114     configure()
1115     assertStringItems('AIOInner', 'ArrayIndexOutOfBoundsException')
1116   }
1117
1118   void testClassNameInIfBeforeIdentifier() throws Throwable {
1119     myFixture.addClass("public class ABCDEFFFFF {}")
1120     doTest('\n')
1121   }
1122
1123   void testClassNameWithInnersTab() throws Throwable { doTest('\t') }
1124
1125   void testClassNameWithGenericsTab() throws Throwable { doTest('\t') }
1126
1127   void testLiveTemplatePrefixTab() throws Throwable { doTest('\t') }
1128
1129   void testOnlyAnnotationsAfterAt() throws Throwable { doTest() }
1130
1131   @NeedsIndex.ForStandardLibrary
1132   void testOnlyAnnotationsAfterAt2() throws Throwable { doTest('\n') }
1133
1134   void testAnnotationBeforeIdentifier() { doTest('\n') }
1135
1136   void testAnnotationBeforeQualifiedReference() { doTest('\n') }
1137
1138   void testAnnotationBeforeIdentifierFinishWithSpace() { doTest(' ') }
1139
1140   @NeedsIndex.ForStandardLibrary
1141   void testOnlyExceptionsInCatch1() throws Exception { doTest('\n') }
1142
1143   @NeedsIndex.ForStandardLibrary
1144   void testOnlyExceptionsInCatch2() throws Exception { doTest('\n') }
1145
1146   @NeedsIndex.ForStandardLibrary
1147   void testOnlyExceptionsInCatch3() throws Exception { doTest('\n') }
1148
1149   @NeedsIndex.ForStandardLibrary
1150   void testOnlyExceptionsInCatch4() throws Exception { doTest('\n') }
1151
1152   void testCommaAfterVariable() throws Throwable { doTest(',') }
1153
1154   void testClassAngleBracket() throws Throwable { doTest('<') }
1155
1156   void testNoArgsMethodSpace() throws Throwable { doTest(' ') }
1157
1158   void testClassSquareBracket() throws Throwable { doTest('[') }
1159
1160   void testPrimitiveSquareBracket() throws Throwable { doTest('[') }
1161
1162   void testVariableSquareBracket() throws Throwable { doTest('[') }
1163
1164   void testMethodSquareBracket() throws Throwable { doTest('[') }
1165
1166   void testMethodParameterTypeDot() throws Throwable { doAntiTest() }
1167
1168   @NeedsIndex.ForStandardLibrary
1169   void testNewGenericClass() throws Throwable { doTest('\n') }
1170
1171   void testNewGenericInterface() throws Throwable { doTest() }
1172
1173   void testEnumPrivateFinal() throws Throwable { doTest() }
1174
1175   void testNoFieldsInImplements() throws Throwable { doTest() }
1176
1177   void testSwitchConstantsFromReferencedClass() throws Throwable { doTest('\n') }
1178
1179   void testSwitchValueFinishWithColon() throws Throwable { doTest(':') }
1180
1181   void testUnfinishedMethodTypeParameter() throws Throwable {
1182     configure()
1183     assertStringItems("MyParameter", "MySecondParameter")
1184   }
1185
1186   void testUnfinishedMethodTypeParameter2() throws Throwable {
1187     configure()
1188     assertStringItems("MyParameter", "MySecondParameter")
1189   }
1190
1191   @NeedsIndex.Full
1192   void testSuperProtectedMethod() throws Throwable {
1193     myFixture.addClass """package foo;
1194       public class Bar {
1195           protected void foo() { }
1196       }"""
1197     doTest()
1198   }
1199
1200   @NeedsIndex.ForStandardLibrary
1201   void testOuterSuperMethodCall() {
1202     configure()
1203     assert 'Class2.super.put' == renderElement(myItems[0]).itemText
1204     type '\n'
1205     checkResult() }
1206
1207   void testTopLevelClassesFromPackaged() throws Throwable {
1208     myFixture.addClass "public class Fooooo {}"
1209     final text = "package foo; class Bar { Fooo<caret> }"
1210     def file = myFixture.addFileToProject("foo/Bar.java", text)
1211     myFixture.configureFromExistingVirtualFile file.virtualFile
1212     assertEmpty myFixture.completeBasic()
1213     myFixture.checkResult text
1214   }
1215
1216   void testRightShift() throws Throwable {
1217     configure()
1218     assertStringItems("myField1", "myField2")
1219   }
1220
1221   @NeedsIndex.ForStandardLibrary
1222   void testAfterCommonPrefix() throws Throwable {
1223     configure()
1224     type 'eq'
1225     assertFirstStringItems("equals", "equalsIgnoreCase")
1226     complete()
1227     assertFirstStringItems("equals", "equalsIgnoreCase")
1228     type '('
1229     checkResult()
1230   }
1231
1232   @NeedsIndex.ForStandardLibrary
1233   void testClassNameInsideIdentifierInIf() throws Throwable {
1234     configure()
1235     myFixture.complete(CompletionType.BASIC, 2)
1236     type '\n'
1237     checkResult()
1238   }
1239
1240   void testKeywordSmartEnter() {
1241     configure()
1242     myFixture.assertPreferredCompletionItems 0, 'null', 'nullity'
1243     myFixture.performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT)
1244     checkResult()
1245   }
1246   void testSynchronizedArgumentSmartEnter() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
1247
1248   @NeedsIndex.Full
1249   void testImportStringValue() throws Throwable {
1250     myFixture.addClass("package foo; public class StringValue {}")
1251     myFixture.addClass("package java.lang; class StringValue {}")
1252     configure()
1253     myFixture.complete(CompletionType.BASIC, 2)
1254     type ' '
1255     checkResult()
1256   }
1257
1258   void testPrimitiveArrayWithRBrace() throws Throwable { doTest '[' }
1259
1260   @NeedsIndex.Full
1261   void testSuggestMembersOfStaticallyImportedClasses() throws Exception {
1262     myFixture.addClass("""package foo;
1263     public class Foo {
1264       public static void foo() {}
1265       public static void bar() {}
1266     }
1267     """)
1268     doTest('\n')
1269   }
1270
1271   @NeedsIndex.Full
1272   void testSuggestMembersOfStaticallyImportedClassesUnqualifiedOnly() throws Exception {
1273     myFixture.addClass("""package foo;
1274     public class Foo {
1275       public static void foo() {}
1276       public static void bar() {}
1277     }
1278     """)
1279     configure()
1280     complete()
1281     assertOneElement(myFixture.getLookupElements())
1282     myFixture.type '\t'
1283     checkResult()
1284   }
1285
1286   @NeedsIndex.Full
1287   void testSuggestMembersOfStaticallyImportedClassesConflictWithLocalMethod() throws Exception {
1288     myFixture.addClass("""package foo;
1289     public class Foo {
1290       public static void foo() {}
1291       public static void bar() {}
1292     }
1293     """)
1294     configure()
1295     myFixture.assertPreferredCompletionItems 0, 'bar', 'bar'
1296     assert renderElement(myFixture.lookupElements[1]).itemText == 'Foo.bar'
1297     myFixture.lookup.currentItem = myFixture.lookupElements[1]
1298     myFixture.type '\t'
1299     checkResult()
1300   }
1301
1302   @NeedsIndex.Full
1303   void testSuggestMembersOfStaticallyImportedClassesConflictWithLocalField() throws Exception {
1304     myFixture.addClass("""package foo;
1305     public class Foo {
1306       public static int foo = 1;
1307       public static int bar = 2;
1308     }
1309     """)
1310     configure()
1311     myFixture.assertPreferredCompletionItems 0, 'bar', 'Foo.bar'
1312     myFixture.lookup.currentItem = myFixture.lookupElements[1]
1313     myFixture.type '\t'
1314     checkResult()
1315   }
1316
1317   void testInstanceMagicMethod() throws Exception { doTest() }
1318
1319   void testNoDotOverwrite() throws Exception { doTest('.') }
1320
1321   void testNoModifierListOverwrite() { doTest('\t') }
1322
1323   void testStaticInnerExtendingOuter() throws Exception { doTest() }
1324
1325   void testPrimitiveClass() throws Exception { doTest() }
1326
1327   void testPrimitiveArrayClass() throws Exception { doTest() }
1328
1329   void testPrimitiveArrayOnlyClass() throws Exception { doAntiTest() }
1330
1331   void testPrimitiveArrayInAnno() throws Exception { doTest() }
1332
1333   void testNewClassAngleBracket() throws Exception { doTest('<') }
1334
1335   void testNewClassAngleBracketExpected() throws Exception { doTest('<') }
1336
1337   void testNewClassSquareBracket() throws Exception { doTest('[') }
1338
1339   void testMethodColon() throws Exception { doTest(':') }
1340
1341   void testVariableColon() throws Exception { doTest(':') }
1342
1343   void testFinishByClosingParenthesis() throws Exception { doTest(')') }
1344
1345   void testNoMethodsInParameterType() {
1346     configure()
1347     assertFirstStringItems "final", "float"
1348   }
1349
1350   @NeedsIndex.Full
1351   void testNonImportedClassInAnnotation() {
1352     myFixture.addClass("package foo; public class XInternalTimerServiceController {}")
1353     myFixture.configureByText "a.java", """
1354 class XInternalError {}
1355
1356 @interface Anno { Class value(); }
1357
1358 @Anno(XInternal<caret>)
1359 """
1360     myFixture.complete(CompletionType.BASIC, 2)
1361     assertFirstStringItems "XInternalError", "XInternalTimerServiceController"
1362   }
1363
1364   @NeedsIndex.Full
1365   void testNonImportedAnnotationClass() {
1366     myFixture.addClass("package foo; public @interface XAnotherAnno {}")
1367     configure()
1368     type('X')
1369     assertFirstStringItems "XAnno", "XAnotherAnno"
1370   }
1371
1372   @NeedsIndex.ForStandardLibrary
1373   void testMetaAnnotation() {
1374     myFixture.configureByText "a.java", "@<caret> @interface Anno {}"
1375     myFixture.complete(CompletionType.BASIC)
1376     assert myFixture.lookup.items.find { it.lookupString == 'Retention' }
1377   }
1378
1379   void testAnnotationClassFromWithinAnnotation() { doTest() }
1380
1381   @NeedsIndex.Full
1382   void testStaticallyImportedFieldsTwice() {
1383     myFixture.addClass("""
1384       class Foo {
1385         public static final int aZOO;
1386       }
1387     """)
1388     myFixture.configureByText("a.java", """
1389       import static Foo.*
1390       class Bar {{
1391         aZ<caret>a
1392       }}
1393     """)
1394     assertOneElement myFixture.completeBasic()
1395   }
1396
1397   void testStaticallyImportedFieldsTwiceSwitch() { doTest() }
1398
1399   void testStatementKeywords() {
1400     myFixture.configureByText("a.java", """
1401       class Bar {{
1402         <caret>xxx
1403       }}
1404     """)
1405     myFixture.completeBasic()
1406     final def strings = myFixture.lookupElementStrings
1407     assertTrue 'if' in strings
1408     assertTrue 'while' in strings
1409     assertTrue 'do' in strings
1410     assertTrue 'new' in strings
1411     assertTrue 'try' in strings
1412
1413     strings.remove 'new'
1414     assertFalse 'new' in strings
1415   }
1416
1417   void testExpressionKeywords() {
1418     myFixture.configureByText("a.java", """
1419       class Bar {{
1420         foo(<caret>xxx)
1421       }}
1422     """)
1423     myFixture.completeBasic()
1424     final def strings = myFixture.lookupElementStrings
1425     assertTrue 'new' in strings
1426   }
1427
1428   void testImportAsterisk() {
1429     myFixture.configureByText "a.java", "import java.lang.<caret>"
1430     myFixture.completeBasic()
1431     myFixture.type '*;'
1432     myFixture.checkResult "import java.lang.*;<caret>"
1433   }
1434
1435   void testDontPreselectCaseInsensitivePrefixMatch() {
1436     CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.NONE)
1437     myFixture.configureByText "a.java", "import java.io.*; class Foo {{ int fileSize; fil<caret>x }}"
1438     myFixture.completeBasic()
1439     assert lookup.currentItem.lookupString == 'fileSize'
1440     myFixture.type('e')
1441
1442     assert lookup.items[0].lookupString == 'File'
1443     assert lookup.items[1].lookupString == 'fileSize'
1444     assert lookup.currentItem == lookup.items[1]
1445   }
1446
1447   @NeedsIndex.ForStandardLibrary
1448   void testNoGenericsWhenChoosingWithParen() { doTest('Ma(') }
1449
1450   @NeedsIndex.ForStandardLibrary
1451   void testNoClosingWhenChoosingWithParenBeforeIdentifier() { doTest '(' }
1452
1453   void testPackageInMemberType() { doTest() }
1454   void testPackageInMemberTypeGeneric() { doTest() }
1455
1456   @NeedsIndex.ForStandardLibrary
1457   void testConstantInAnno() { doTest('\n') }
1458
1459   @NeedsIndex.SmartMode(reason = "Smart mode needed for EncodingReferenceInjector to provide EncodingReference with variants")
1460   void testCharsetName() {
1461     myFixture.addClass("package java.nio.charset; public class Charset { public static Charset forName(String s) {} }")
1462     configureByTestName()
1463     assert myFixture.lookupElementStrings.contains('UTF-8')
1464   }
1465
1466   @NeedsIndex.Full
1467   void testInnerClassInExtendsGenerics() {
1468     def text = "package bar; class Foo extends List<Inne<caret>> { public static class Inner {} }"
1469     myFixture.configureFromExistingVirtualFile(myFixture.addClass(text).containingFile.virtualFile)
1470     myFixture.completeBasic()
1471     myFixture.type('\n')
1472     myFixture.checkResult(text.replace('Inne<caret>', 'Foo.Inner<caret>'))
1473   }
1474
1475   @NeedsIndex.ForStandardLibrary
1476   void testClassNameDot() { doTest('.') }
1477
1478   @NeedsIndex.Full
1479   void testClassNameDotBeforeCall() {
1480     myFixture.addClass("package foo; public class FileInputStreamSmth {}")
1481     myFixture.configureByFile(getTestName(false) + ".java")
1482     PsiDocumentManager.getInstance(project).commitAllDocuments()
1483     type '\b'
1484     PsiDocumentManager.getInstance(project).commitAllDocuments()
1485     myFixture.complete(CompletionType.BASIC, 2)
1486     assert lookup
1487     type '.'
1488     checkResult()
1489   }
1490
1491   void testNoReturnAfterDot() {
1492     configure()
1493     assert !('return' in myFixture.lookupElementStrings)
1494   }
1495
1496   @NeedsIndex.ForStandardLibrary
1497   void testDuplicateExpectedTypeInTypeArgumentList() {
1498     configure()
1499     def items = myFixture.lookupElements.findAll { it.lookupString == 'String' }
1500     assert items.size() == 1
1501     assert renderElement(items[0]).tailText == ' (java.lang)'
1502   }
1503
1504   void testDuplicateInnerClass() {
1505     configure()
1506     def items = myFixture.lookupElements.findAll { it.lookupString == 'Inner' }
1507     assert items.size() == 1
1508   }
1509
1510   void testSameSignature() {
1511     configure()
1512     myFixture.assertPreferredCompletionItems(0, 's', 's, file', 's, file, a')
1513     lookup.setCurrentItem(lookup.items[2])
1514     myFixture.type('\n')
1515     checkResult()
1516   }
1517
1518   @NeedsIndex.ForStandardLibrary
1519   void testNoParenthesesAroundCallQualifier() { doTest() }
1520
1521   @NeedsIndex.Full
1522   void testAllAssertClassesMethods() {
1523     myFixture.addClass 'package foo; public class Assert { public static boolean foo() {} }'
1524     myFixture.addClass 'package bar; public class Assert { public static boolean bar() {} }'
1525     configure()
1526     assert myFixture.lookupElementStrings == ['Assert.bar', 'Assert.foo']
1527     myFixture.type '\n'
1528     checkResult()
1529   }
1530
1531   @NeedsIndex.Full
1532   void testCastVisually() {
1533     configure()
1534     def p = renderElement(myFixture.lookupElements[0])
1535     assert p.itemText == 'getValue'
1536     assert p.itemTextBold
1537     assert p.typeText == 'Foo'
1538   }
1539
1540   @NeedsIndex.ForStandardLibrary
1541   void testSuggestEmptySet() {
1542     configure()
1543     assert 'emptySet' == myFixture.lookupElementStrings[0]
1544     type '\n'
1545     checkResult()
1546   }
1547
1548   @NeedsIndex.ForStandardLibrary
1549   void testSuggestAllTypeArguments() {
1550     configure()
1551     assert 'String, List<String>' == lookup.items[0].lookupString
1552     assert 'String, List<String>' == renderElement(lookup.items[0]).itemText
1553     type '\n'
1554     checkResult()
1555   }
1556
1557   void testNoFinalInAnonymousConstructor() { doTest() }
1558
1559   @NeedsIndex.ForStandardLibrary
1560   void testListArrayListCast() { doTest('\n') }
1561
1562   void testInterfaceImplementationNoCast() { doTest() }
1563
1564   @NeedsIndex.Full
1565   void testStaticallyImportedMethodsBeforeExpression() { doTest() }
1566
1567   @NeedsIndex.Full
1568   void testInnerChainedReturnType() { doTest() }
1569
1570   private CommonCodeStyleSettings getCodeStyleSettings() {
1571     return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE)
1572   }
1573
1574   void testCompatibleInterfacesCast() {
1575     configure()
1576     assert myFixture.lookupElementStrings.containsAll(['foo', 'bar'])
1577   }
1578
1579   void testDontAutoInsertMiddleMatch() {
1580     configure()
1581     checkResult()
1582     assert lookup.items.size() == 1
1583   }
1584
1585   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for method implementations)")
1586   void testImplementViaCompletion() {
1587     configure()
1588     myFixture.assertPreferredCompletionItems 0, 'private', 'protected', 'public', 'public void run'
1589     def item = lookup.items[3]
1590
1591     def p = renderElement(item)
1592     assert p.itemText == 'public void run'
1593     assert p.tailText == '(String t, int myInt) {...}'
1594     assert p.typeText == 'Foo'
1595
1596     lookup.currentItem = item
1597     myFixture.type('\n')
1598     checkResult()
1599   }
1600
1601   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for implementing methods)")
1602   void testImplementViaCompletionWithGenerics() {
1603     configure()
1604     myFixture.assertPreferredCompletionItems 0, 'public void methodWithGenerics', 'public void methodWithTypeParam'
1605     assert renderElement(lookup.items[0]).tailText == '(List k) {...}'
1606     assert renderElement(lookup.items[1]).tailText == '(K k) {...}'
1607   }
1608
1609   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
1610   void testImplementViaOverrideCompletion() {
1611     configure()
1612     myFixture.assertPreferredCompletionItems 0, 'Override/Implement methods...', 'Override', 'public void run'
1613     lookup.currentItem = lookup.items[2]
1614     myFixture.type('\n')
1615     checkResult()
1616   }
1617
1618   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
1619   void testSuggestToOverrideMethodsWhenTypingOverrideAnnotation() {
1620     configure()
1621     myFixture.assertPreferredCompletionItems 0, 'Override/Implement methods...', 'Override'
1622     myFixture.type('\n')
1623     checkResult()
1624   }
1625
1626   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
1627   void testSuggestToOverrideMethodsWhenTypingOverrideAnnotationBeforeMethod() {
1628     configure()
1629     myFixture.assertPreferredCompletionItems 0, 'Override/Implement methods...', 'Override'
1630     myFixture.type('\n')
1631     checkResult()
1632   }
1633
1634   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for implementing methods)")
1635   void testStrikeOutDeprecatedSuperMethods() {
1636     configure()
1637     myFixture.assertPreferredCompletionItems 0, 'void foo1', 'void foo2'
1638     assert !renderElement(lookup.items[0]).strikeout
1639     assert renderElement(lookup.items[1]).strikeout
1640   }
1641
1642   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for equals() and hashCode())")
1643   void testInvokeGenerateEqualsHashCodeOnOverrideCompletion() { doTest() }
1644   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for 'toString()')")
1645   void testInvokeGenerateToStringOnOverrideCompletion() { doTest() }
1646
1647   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for getters and setters)")
1648   void testAccessorViaCompletion() {
1649     configure()
1650
1651     def getter = myFixture.lookupElements.find { it.lookupString == 'public int getField' }
1652     def setter = myFixture.lookupElements.find { it.lookupString == 'public void setField' }
1653     assert getter : myFixture.lookupElementStrings
1654     assert setter : myFixture.lookupElementStrings
1655
1656     def p = renderElement(getter)
1657     assert p.itemText == getter.lookupString
1658     assert p.tailText == '() {...}'
1659     assert !p.typeText
1660
1661     p = renderElement(setter)
1662     assert p.itemText == setter.lookupString
1663     assert p.tailText == '(int field) {...}'
1664     assert !p.typeText
1665
1666     lookup.currentItem = getter
1667     myFixture.type('\n')
1668     checkResult()
1669   }
1670
1671   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for getters and setters)")
1672   void testNoSetterForFinalField() {
1673     configure()
1674     myFixture.assertPreferredCompletionItems 0, 'public', 'public int getFinalField'
1675     assert !myFixture.lookupElements.find { it.lookupString == 'public void setFinalField' }
1676     assert !myFixture.lookupElements.find { it.lookupString == 'public int getCONSTANT' }
1677   }
1678
1679   void testBraceOnNextLine() {
1680     codeStyleSettings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE
1681     doTest()
1682   }
1683
1684   void testDoForceBraces() {
1685     codeStyleSettings.DOWHILE_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS
1686     doTest('\n')
1687   }
1688
1689   void testMulticaretSingleItemInsertion() {
1690     doTest()
1691   }
1692
1693   @NeedsIndex.ForStandardLibrary
1694   void testMulticaretMethodWithParen() {
1695     doTest()
1696   }
1697
1698   @NeedsIndex.ForStandardLibrary
1699   void testMulticaretTyping() {
1700     configure()
1701     assert lookup
1702     type('p')
1703     assert lookup
1704     type('\n')
1705     checkResult()
1706   }
1707
1708   @NeedsIndex.ForStandardLibrary
1709   void testMulticaretCompletionFromNonPrimaryCaret() {
1710     configure()
1711     myFixture.assertPreferredCompletionItems(0, "arraycopy")
1712   }
1713
1714   void testMulticaretCompletionFromNonPrimaryCaretWithTab() {
1715     doTest '\t'
1716   }
1717
1718   @NeedsIndex.Full
1719   void "test complete lowercase class name"() {
1720     myFixture.addClass("package foo; public class myClass {}")
1721     myFixture.configureByText "a.java", """
1722 class Foo extends my<caret>
1723 """
1724     myFixture.complete(CompletionType.BASIC, 2)
1725     myFixture.checkResult '''import foo.myClass;
1726
1727 class Foo extends myClass
1728 '''
1729   }
1730
1731   void testNoClassesWithDollar() {
1732     myFixture.addClass('package some; public class $WithDollarNonImported {}')
1733     myFixture.addClass('package imported; public class $WithDollarImported {}')
1734     doAntiTest()
1735   }
1736
1737   @NeedsIndex.ForStandardLibrary
1738   void "test don't show static inner class after instance qualifier"() {
1739     myFixture.configureByText "a.java", """
1740 class Foo {
1741   static class Inner {}
1742 }
1743 class Bar {
1744   void foo(Foo f) {
1745     f.<caret>
1746   }
1747 }  
1748 """
1749     myFixture.completeBasic()
1750     assert !('Inner' in myFixture.lookupElementStrings)
1751   }
1752
1753   @NeedsIndex.ForStandardLibrary
1754   void "test show static member after instance qualifier when nothing matches"() {
1755     myFixture.configureByText "a.java", "class Foo{{ \"\".<caret> }}"
1756     myFixture.completeBasic()
1757     assert !('valueOf' in myFixture.lookupElementStrings)
1758     ((LookupImpl)myFixture.lookup).hide()
1759     myFixture.type 'val'
1760     myFixture.completeBasic()
1761     assert ('valueOf' in myFixture.lookupElementStrings)
1762   }
1763
1764   void testNoMathTargetMethods() { doAntiTest() }
1765
1766   @NeedsIndex.Full
1767   void testNoLowercaseClasses() {
1768     myFixture.addClass("package foo; public class abcdefgXxx {}")
1769     doAntiTest()
1770     myFixture.complete(CompletionType.BASIC, 2)
1771     assertStringItems('abcdefgXxx')
1772   }
1773
1774   @NeedsIndex.Full
1775   void testProtectedFieldInAnotherPackage() {
1776     myFixture.addClass("package foo; public class Super { protected String myString; }")
1777     doTest()
1778   }
1779
1780   @NeedsIndex.Full
1781   void testUnimportedStaticInnerClass() {
1782     myFixture.addClass("package foo; public class Super { public static class Inner {} }")
1783     doTest()
1784   }
1785
1786   void testNoJavaLangPackagesInImport() { doAntiTest() }
1787
1788   @NeedsIndex.Full
1789   void testNoStaticDuplicatesFromExpectedMemberFactories() {
1790     configure()
1791     myFixture.complete(CompletionType.BASIC, 2)
1792     myFixture.assertPreferredCompletionItems(0, "xcreateZoo", "xcreateElephant")
1793   }
1794
1795   void testNoInaccessibleCompiledElements() {
1796     configure()
1797     myFixture.complete(CompletionType.BASIC, 2)
1798     checkResultByFile(getTestName(false) + ".java")
1799     assertEmpty(myItems)
1800     assertNull(getLookup())
1801   }
1802
1803   @NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for getters)")
1804   void "test code cleanup during completion generation"() {
1805     myFixture.configureByText "a.java", "class Foo {int i; ge<caret>}"
1806     myFixture.enableInspections(new UnqualifiedFieldAccessInspection())
1807     myFixture.complete(CompletionType.BASIC)
1808     UIUtil.dispatchAllInvocationEvents()
1809     myFixture.checkResult '''class Foo {int i;
1810
1811     public int getI() {
1812         return this.i;
1813     }
1814 }'''
1815   }
1816
1817   void testIndentingForSwitchCase() { doTest() }
1818
1819   void testShowMostSpecificOverride() {
1820     configure()
1821     assert 'B' == renderElement(myFixture.lookup.items[0]).typeText
1822   }
1823
1824   @NeedsIndex.ForStandardLibrary
1825   void testShowMostSpecificOverrideOnlyFromClass() {
1826     configure()
1827     assert 'Door' == renderElement(myFixture.lookup.items[0]).typeText
1828   }
1829
1830   void testNoOverrideWithMiddleMatchedName() {
1831     configure()
1832     assert !('public void removeTemporaryEditorNode' in myFixture.lookupElementStrings)
1833   }
1834
1835   void testShowVarInitializers() {
1836     configure()
1837     myFixture.assertPreferredCompletionItems 0, 'FIELD1', 'FIELD2', 'FIELD3', 'FIELD4'
1838     def items = myFixture.lookup.items
1839     assert items.collect { renderElement(it).tailText } == ['( "x")', '("y") {...}', null, ' ( = 42)']
1840     assert renderElement(items[3]).tailFragments[0].italic
1841   }
1842
1843   @NeedsIndex.Full
1844   void testShowNonImportedVarInitializers() {
1845     configure()
1846     myFixture.assertPreferredCompletionItems 1, 'Field', 'FIELD1', 'FIELD2', 'FIELD3', 'FIELD4'
1847     def fieldItems = myFixture.lookup.items[1..4]
1848     assert fieldItems.collect { renderElement(it).tailText } == ['( "x") in E', '("y") {...} in E', null, ' ( = 42) in E']
1849     assert renderElement(fieldItems[3]).tailFragments[0].italic
1850     assert !renderElement(fieldItems[3]).tailFragments[1].italic
1851   }
1852
1853   @NeedsIndex.ForStandardLibrary
1854   void testSuggestInterfaceArrayWhenObjectIsExpected() {
1855     configure()
1856     assert renderElement(myFixture.lookup.items[0]).tailText.contains('{...}')
1857     assert renderElement(myFixture.lookup.items[1]).tailText.contains('[]')
1858   }
1859
1860   @NeedsIndex.ForStandardLibrary
1861   void testSuggestInterfaceArrayWhenObjectArrayIsExpected() {
1862     configure()
1863     assert renderElement(myFixture.lookup.items[0]).tailText.contains('{...}')
1864     assert renderElement(myFixture.lookup.items[1]).tailText.contains('[]')
1865   }
1866
1867   void testDispreferPrimitiveTypesInCallArgs() throws Throwable {
1868     CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.NONE)
1869     configure()
1870     myFixture.assertPreferredCompletionItems 0, "dx", "doo", "Doo", "double"
1871   }
1872
1873   @NeedsIndex.ForStandardLibrary
1874   void testCopyConstructor() { doTest('\n') }
1875
1876   @NeedsIndex.ForStandardLibrary
1877   void testGetClassType() {
1878     configure()
1879     assert 'Class<? extends Number>' == renderElement(myFixture.lookupElements[0]).typeText
1880   }
1881
1882   @NeedsIndex.Full
1883   void testNonImportedClassAfterNew() {
1884     def uClass = myFixture.addClass('package foo; public class U {}')
1885     myFixture.configureByText('a.java', 'class X {{ new U<caret>x }}')
1886     myFixture.completeBasic()
1887     assert myFixture.lookupElements[0].object == uClass
1888   }
1889
1890   void testSuggestClassNamesForLambdaParameterTypes() { doTest('\n') }
1891
1892   void testOnlyExtendsSuperInWildcard() {
1893     CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.NONE)
1894
1895     configure()
1896     assert myFixture.lookupElementStrings == ['extends', 'super']
1897     LookupManager.getInstance(project).hideActiveLookup()
1898
1899     myFixture.type('n')
1900     assert !myFixture.completeBasic()
1901     myFixture.type('\b')
1902     checkResultByFile(getTestName(false) + ".java")
1903   }
1904
1905   @NeedsIndex.Full
1906   void testChainInLambdaBinary() {
1907     codeStyleSettings.ALIGN_MULTILINE_BINARY_OPERATION = true
1908     myFixture.addClass("package pkg; public class PathUtil { public static String toSystemDependentName() {} }")
1909     doTest('\n')
1910   }
1911
1912   @NeedsIndex.ForStandardLibrary
1913   void testPairAngleBracketDisabled() {
1914     CodeInsightSettings.instance.AUTOINSERT_PAIR_BRACKET = false
1915     doTest('<')
1916   }
1917
1918   void testDuplicateGenericMethodSuggestionWhenInheritingFromRawType() {
1919     configure()
1920     assert myFixture.lookupElementStrings == ['indexOf']
1921   }
1922
1923   @NeedsIndex.ForStandardLibrary
1924   void testDuplicateEnumValueOf() {
1925     configure()
1926     assert myFixture.lookupElements.collect { renderElement((LookupElement)it).itemText } == ['Bar.valueOf', 'Foo.valueOf', 'Enum.valueOf']
1927   }
1928
1929   void testTypeArgumentInCast() {
1930     configure()
1931     myFixture.assertPreferredCompletionItems 0, 'String'
1932   }
1933
1934   void testNoCallsInPackageStatement() { doAntiTest() }
1935
1936   @NeedsIndex.Full
1937   void testTypeParameterShadowingClass() {
1938     configure()
1939     myFixture.assertPreferredCompletionItems 0, 'Tttt', 'Tttt'
1940     assert myFixture.lookupElements[0].object instanceof PsiTypeParameter
1941     assert !(myFixture.lookupElements[1].object instanceof PsiTypeParameter)
1942     selectItem(myFixture.lookupElements[1])
1943     checkResult()
1944   }
1945
1946   void testLowercaseDoesNotMatchUnderscore() {
1947     configure()
1948     assert myFixture.lookupElementStrings == ['web']
1949   }
1950
1951   void testLocalClassPresentation() {
1952     def cls = myFixture.addFileToProject('foo/Bar.java', """package foo; 
1953 class Bar {{
1954     class Local {}
1955     Lo<caret>x
1956 }}""")
1957     myFixture.configureFromExistingVirtualFile(cls.containingFile.virtualFile)
1958     def item = myFixture.completeBasic()[0]
1959     assert renderElement(item).tailText.contains('local class')
1960   }
1961
1962   void testNoDuplicateInCast() {
1963     configure()
1964     assert myFixture.lookupElementStrings == null
1965   }
1966
1967   void testNoNonAnnotationMethods() { doAntiTest() }
1968
1969   @NeedsIndex.ForStandardLibrary
1970   void testPreferBigDecimalToJavaUtilInner() {
1971     configure()
1972     myFixture.assertPreferredCompletionItems 0, 'BigDecimal', 'BigDecimalLayoutForm'
1973   }
1974
1975   @NeedsIndex.ForStandardLibrary
1976   void testOnlyExceptionsInMultiCatch1() { doTest('\n') }
1977
1978   @NeedsIndex.ForStandardLibrary
1979   void testOnlyExceptionsInMultiCatch2() { doTest('\n') }
1980
1981   @NeedsIndex.ForStandardLibrary
1982   void testOnlyResourcesInResourceList1() { doTest('\n') }
1983
1984   @NeedsIndex.ForStandardLibrary
1985   void testOnlyResourcesInResourceList2() { doTest('\n') }
1986
1987   @NeedsIndex.ForStandardLibrary
1988   void testOnlyResourcesInResourceList3() { doTest('\n') }
1989
1990   @NeedsIndex.ForStandardLibrary
1991   void testOnlyResourcesInResourceList4() { doTest('\n') }
1992
1993   void testOnlyResourcesInResourceList5() { doTest('\n') }
1994
1995   @NeedsIndex.ForStandardLibrary
1996   void testMethodReferenceNoStatic() { doTest('\n') }
1997
1998   void testMethodReferenceCallContext() { doTest('\n') }
1999
2000   @NeedsIndex.Full
2001   void testDestroyingCompletedClassDeclaration() { doTest('\n') }
2002
2003   @NeedsIndex.ForStandardLibrary
2004   void testResourceParentInResourceList() {
2005     configureByTestName()
2006     assert 'MyOuterResource' == myFixture.lookupElementStrings[0]
2007     assert 'MyClass' in myFixture.lookupElementStrings
2008     myFixture.type('C\n')
2009     checkResultByFile(getTestName(false) + "_after.java")
2010   }
2011
2012   void testAfterTryWithResources() {
2013     configureByTestName()
2014     def strings = myFixture.lookupElementStrings
2015     assert strings.containsAll(['final', 'finally', 'int', 'Util'])
2016   }
2017
2018   void testNewObjectHashMapWithSmartEnter() {
2019     configureByTestName()
2020     myFixture.performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT)
2021     checkResultByFile(getTestName(false) + "_after.java")
2022   }
2023
2024   @NeedsIndex.Full
2025   void testCompletingClassWithSameNameAsPackage() {
2026     myFixture.addClass("package Apple; public class Apple {}")
2027     doTest('\n')
2028   }
2029
2030   void testSuggestGetInstanceMethodName() { doTest() }
2031
2032   @NeedsIndex.Full(reason = "AllClassesSearchExecutor.processClassNames from JavaNoVariantsDelegator.suggestNonImportedClasses uses stub indices to provide completion, so matching Scratch class is ignored, ant so is its inner class")
2033   void testTabOnNewInnerClass() {
2034     configureByTestName()
2035     lookup.currentItem = myFixture.lookupElements.find { it.lookupString.contains('Inner') }
2036     myFixture.type('\t')
2037     checkResult()
2038   }
2039
2040   @NeedsIndex.Full
2041   void testRemoveUnusedImportOfSameName() {
2042     myFixture.addClass("package foo; public class List {}")
2043     configureByTestName()
2044     lookup.currentItem = myFixture.lookupElements.find { it.object instanceof PsiClass && ((PsiClass)it.object).qualifiedName == 'java.util.List' }
2045     myFixture.type('\n')
2046     checkResult()
2047   }
2048
2049   void "test no duplication after new with expected type parameter"() {
2050     myFixture.configureByText 'a.java', 'class Foo<T> { T t = new <caret> }'
2051     complete()
2052     assert myFixture.lookupElements.findAll { it.allLookupStrings.contains('T') }.size() < 2
2053   }
2054
2055   void "test no duplication for inner class on second invocation"() {
2056     myFixture.configureByText 'a.java', '''
2057 class Abc {
2058     class FooBar {}
2059     void foo() {
2060         FooBar<caret>x
2061     }
2062 }'''
2063     myFixture.complete(CompletionType.BASIC, 2)
2064     assert myFixture.lookupElements.size() == 1
2065   }
2066
2067   void "test smart enter wraps type arguments"() {
2068     myFixture.configureByText 'a.java', 'class Foo<T> { F<caret>List<String> }'
2069     myFixture.completeBasic()
2070     myFixture.type(Lookup.COMPLETE_STATEMENT_SELECT_CHAR)
2071     myFixture.checkResult 'class Foo<T> { Foo<List<String>><caret> }'
2072   }
2073
2074   void testNoSuggestionsAfterEnumConstant() { doAntiTest() }
2075
2076   void testPutCaretInsideParensInFixedPlusVarargOverloads() { doTest('\n') }
2077
2078   void testSuggestCurrentClassInSecondSuperGenericParameter() { doTest('\n') }
2079
2080   @NeedsIndex.Full
2081   void "test after new editing prefix back and forth when sometimes there are expected type suggestions and sometimes not"() {
2082     myFixture.addClass("class Super {}")
2083     myFixture.addClass("class Sub extends Super {}")
2084     myFixture.addClass("package foo; public class SubOther {}")
2085     myFixture.configureByText('a.java', "class C { Super s = new SubO<caret>x }")
2086
2087     myFixture.completeBasic()
2088     myFixture.assertPreferredCompletionItems 0, 'SubOther'
2089     myFixture.type('\b')
2090     myFixture.assertPreferredCompletionItems 0, 'Sub'
2091     myFixture.type('O')
2092     myFixture.assertPreferredCompletionItems 0, 'SubOther'
2093   }
2094
2095   void "test correct typos"() {
2096     myFixture.configureByText("a.java", "class MyClass { MyCals<caret> }")
2097     myFixture.completeBasic()
2098     myFixture.type('\n')
2099     myFixture.checkResult("class MyClass { MyClass<caret> }")
2100   }
2101
2102   void testRemoveParenthesesWhenReplacingEmptyCallWithConstant() {
2103     doTest('\t')
2104   }
2105
2106   void testNoCallsAfterAnnotationInCodeBlock() { doTest() }
2107   
2108   void testExtendsAfterEnum() {
2109     myFixture.configureByText("a.java", "enum X ex<caret>") // should not complete
2110     myFixture.completeBasic()
2111     myFixture.checkResult("enum X ex")
2112   }
2113
2114   @NeedsIndex.Full
2115   void testAddImportWhenCompletingInnerAfterNew() {
2116     myFixture.addClass("package p; public class Outer { public static class Inner {} }")
2117     configureByTestName()
2118     selectItem(myItems.find { it.lookupString.contains('Inner') })
2119     checkResult()
2120   }
2121
2122   void "test completing qualified class name"() {
2123     myFixture.configureByText("a.java", "class C implements java.util.Li<caret>")
2124     myFixture.completeBasic()
2125     myFixture.assertPreferredCompletionItems(0, 'List')
2126     myFixture.type('\n')
2127     myFixture.checkResult("class C implements java.util.List<caret>")
2128   }
2129
2130   @NeedsIndex.ForStandardLibrary
2131   void "test suggest Object methods when super is unresolved"() {
2132     def checkGetClassPresent = { String text ->
2133       myFixture.configureByText("a.java", text)
2134       myFixture.completeBasic()
2135       myFixture.assertPreferredCompletionItems 0, 'getClass'
2136     }
2137     checkGetClassPresent("class C extends Unresolved {{ getCl<caret>x }}")
2138     checkGetClassPresent("class C implements Unresolved {{ getCl<caret>x }}")
2139     checkGetClassPresent("class C extends Unresolved implements Runnable {{ getCl<caret>x }}")
2140     checkGetClassPresent("class C extends Unresolved1 implements Unresolved2 {{ getCl<caret>x }}")
2141   }
2142
2143   void testSuggestInverseOfDefaultAnnoParamValueForBoolean() {
2144     configureByTestName()
2145     myFixture.assertPreferredCompletionItems(0, 'smth = true', 'value = false')
2146
2147     def smthDefault = myItems.find { it.lookupString == 'smth = false' }
2148     def presentation = renderElement(smthDefault)
2149     assert presentation.tailText == ' (default)'
2150     assert presentation.tailFragments[0].grayed
2151
2152     myFixture.type('\n')
2153     checkResult()
2154   }
2155
2156   void testCaseColonAfterStringConstant() { doTest() }
2157
2158   void testOneElementArray() {
2159     configureByTestName()
2160     myFixture.assertPreferredCompletionItems 0, 'aaa', 'aaa[0]'
2161     selectItem(myItems[1])
2162     checkResult()
2163   }
2164
2165   void testSuggestChainsOfExpectedType() {
2166     configure()
2167     myFixture.assertPreferredCompletionItems 0, 'bar', 'bar().getGoo'
2168     selectItem(myItems[1])
2169     checkResult()
2170   }
2171
2172   void testTopLevelPublicClass() { doTest() }
2173   void testTopLevelPublicClassIdentifierExists() { doTest() }
2174   void testTopLevelPublicClassBraceExists() { doTest() }
2175
2176   void testPerformanceWithManyNonMatchingDeclarations() {
2177     def importedNumbers = 0..<10
2178     for (i in (importedNumbers)) {
2179       myFixture.addClass("class Foo$i {\n" +
2180                          (0..100).collect { "static int FOO$it = 3;\n" }.join("") +
2181                          "}")
2182     }
2183     String text = importedNumbers.collect { "import static Foo${it}.*;\n" }.join("") +
2184                   "class C {\n" +
2185                   (0..100).collect { "String method$it() {}\n" } +
2186                   "{ " +
2187                   "int localVariable = 2;\n" +
2188                   "localV<caret>x }" +
2189                   "}"
2190     myFixture.configureByText("a.java", text)
2191     PlatformTestUtil.startPerformanceTest(name, 300, {
2192       assert myFixture.completeBasic().length == 1
2193     }).setup {
2194       lookup?.hideLookup(true)
2195       myFixture.type("\bV")
2196       psiManager.dropPsiCaches()
2197       assert !lookup
2198     }.assertTiming()
2199   }
2200
2201   void "test performance with many matching statically-imported declarations"() {
2202     def fieldCount = 7000
2203
2204     myFixture.addClass("interface Constants {" +
2205             (0..<fieldCount).collect { "String field$it = \"x\";\n" } +
2206     "}")
2207     myFixture.configureByText("a.java", "import static Constants.*; class C { { field<caret>x } }")
2208     PlatformTestUtil.startPerformanceTest(name, 10_000, {
2209       assert myFixture.completeBasic().length > 100
2210     }).setup {
2211       lookup?.hideLookup(true)
2212       myFixture.type("\bd")
2213       psiManager.dropPsiCaches()
2214       assert !lookup
2215     }.assertTiming()
2216   }
2217 }