1 package com
.intellij
.codeInsight
.completion
;
3 import com
.intellij
.JavaTestUtil
;
4 import com
.intellij
.codeInsight
.CodeInsightSettings
;
5 import com
.intellij
.codeInsight
.lookup
.Lookup
;
6 import com
.intellij
.codeInsight
.lookup
.LookupElement
;
7 import com
.intellij
.codeInsight
.lookup
.LookupManager
;
8 import com
.intellij
.codeInsight
.lookup
.PsiTypeLookupItem
;
9 import com
.intellij
.codeInsight
.lookup
.impl
.TestLookupManager
;
10 import com
.intellij
.codeInsight
.template
.SmartCompletionContextType
;
11 import com
.intellij
.codeInsight
.template
.Template
;
12 import com
.intellij
.codeInsight
.template
.TemplateContextType
;
13 import com
.intellij
.codeInsight
.template
.TemplateManager
;
14 import com
.intellij
.codeInsight
.template
.impl
.TemplateImpl
;
15 import com
.intellij
.codeInsight
.template
.impl
.TemplateSettings
;
16 import com
.intellij
.openapi
.projectRoots
.Sdk
;
17 import com
.intellij
.openapi
.projectRoots
.impl
.JavaSdkImpl
;
18 import com
.intellij
.openapi
.roots
.LanguageLevelProjectExtension
;
19 import com
.intellij
.openapi
.util
.Condition
;
20 import com
.intellij
.pom
.java
.LanguageLevel
;
21 import com
.intellij
.psi
.codeStyle
.CodeStyleSettings
;
22 import com
.intellij
.psi
.codeStyle
.CodeStyleSettingsManager
;
23 import com
.intellij
.util
.containers
.ContainerUtil
;
24 import org
.jetbrains
.annotations
.NonNls
;
26 public class SmartTypeCompletionTest
extends LightCompletionTestCase
{
27 private static final String BASE_PATH
= "/codeInsight/completion/smartType";
28 private LanguageLevel myPrevLanguageLevel
;
31 protected String
getTestDataPath() {
32 return JavaTestUtil
.getJavaTestDataPath();
35 public void testParenAfterCast1() throws Exception
{
36 String path
= BASE_PATH
+ "/parenAfterCast";
38 configureByFile(path
+ "/before1.java");
39 checkResultByFile(path
+ "/after1.java");
42 public void testParenAfterCast2() throws Exception
{
43 String path
= BASE_PATH
+ "/parenAfterCast";
45 configureByFile(path
+ "/before2.java");
46 checkResultByFile(path
+ "/after2.java");
52 public void testParenAfterCast3() throws Exception
{
53 String path
= BASE_PATH
+ "/parenAfterCast";
55 configureByFile(path
+ "/before3.java");
56 checkResultByFile(path
+ "/after3.java");
59 public void testParenAfterCall1() throws Exception
{
60 String path
= BASE_PATH
+ "/parenAfterCall";
62 configureByFile(path
+ "/before1.java");
63 checkResultByFile(path
+ "/after1.java");
66 public void testParenAfterCall2() throws Exception
{
67 String path
= BASE_PATH
+ "/parenAfterCall";
69 configureByFile(path
+ "/before2.java");
70 checkResultByFile(path
+ "/after2.java");
73 public void testParenAfterCall3() throws Exception
{
74 String path
= BASE_PATH
+ "/parenAfterCall";
76 configureByFile(path
+ "/before3.java");
77 checkResultByFile(path
+ "/after3.java");
80 public void testParenAfterCall4() throws Exception
{
81 String path
= BASE_PATH
+ "/parenAfterCall";
83 configureByFile(path
+ "/before4.java");
84 checkResultByFile(path
+ "/after4.java");
87 public void testParenAfterCall5() throws Exception
{
88 String path
= BASE_PATH
+ "/parenAfterCall";
90 configureByFile(path
+ "/before5.java");
91 checkResultByFile(path
+ "/after5.java");
94 public void testParenAfterCall6() throws Exception
{
95 String path
= BASE_PATH
+ "/parenAfterCall";
97 configureByFile(path
+ "/before6.java");
98 checkResultByFile(path
+ "/after6.java");
101 public void testParenAfterCall1_SpaceWithinMethodCallParens() throws Exception
{
102 String path
= BASE_PATH
+ "/parenAfterCall";
104 CodeStyleSettings styleSettings
= CodeStyleSettingsManager
.getSettings(getProject());
105 configureByFileNoComplete(path
+ "/before1.java");
106 styleSettings
.SPACE_WITHIN_METHOD_CALL_PARENTHESES
= true;
111 styleSettings
.SPACE_WITHIN_METHOD_CALL_PARENTHESES
= false;
113 checkResultByFile(path
+ "/after1_space.java");
116 public void testParenAfterIf1() throws Exception
{
117 String path
= BASE_PATH
+ "/parenAfterIf";
119 configureByFile(path
+ "/before1.java");
120 checkResultByFile(path
+ "/after1.java");
123 public void testParenAfterIf2() throws Exception
{
124 String path
= BASE_PATH
+ "/parenAfterIf";
126 configureByFile(path
+ "/before2.java");
127 checkResultByFile(path
+ "/after2.java");
130 public void testForceLookupForAbstractClasses() throws Exception
{
131 String path
= BASE_PATH
+ "/afterNew";
133 configureByFile(path
+ "/before9.java");
134 checkResultByFile(path
+ "/after9.java");
137 public void testAfterNew1() throws Exception
{
138 String path
= BASE_PATH
+ "/afterNew";
140 configureByFile(path
+ "/before1.java");
142 checkResultByFile(path
+ "/after1.java");
145 public void testAfterNew2() throws Exception
{
146 String path
= BASE_PATH
+ "/afterNew";
148 configureByFile(path
+ "/before2.java");
150 checkResultByFile(path
+ "/after2.java");
153 public void testAfterNew3() throws Exception
{
154 String path
= BASE_PATH
+ "/afterNew";
156 configureByFile(path
+ "/before3.java");
158 checkResultByFile(path
+ "/after3.java");
161 public void testAfterNew4() throws Exception
{
162 String path
= BASE_PATH
+ "/afterNew";
164 configureByFile(path
+ "/before4.java");
166 checkResultByFile(path
+ "/after4.java");
169 public void testAfterNew5() throws Exception
{
170 String path
= BASE_PATH
+ "/afterNew";
172 configureByFile(path
+ "/before5.java");
174 checkResultByFile(path
+ "/after5.java");
177 public void testAfterNew6() throws Exception
{
178 String path
= BASE_PATH
+ "/afterNew";
180 configureByFile(path
+ "/before6.java");
182 checkResultByFile(path
+ "/after6.java");
185 public void testAfterNew7() throws Exception
{
186 String path
= BASE_PATH
+ "/afterNew";
188 configureByFile(path
+ "/before7.java");
190 checkResultByFile(path
+ "/after7.java");
193 public void testAfterNew8() throws Exception
{
194 String path
= BASE_PATH
+ "/afterNew";
196 configureByFile(path
+ "/before8.java");
198 checkResultByFile(path
+ "/after8.java");
201 public void testAfterNew9() throws Exception
{
202 String path
= BASE_PATH
+ "/afterNew";
204 configureByFile(path
+ "/before10.java");
206 checkResultByFile(path
+ "/after10.java");
209 public void testAfterNew10() throws Exception
{
210 String path
= BASE_PATH
+ "/afterNew";
212 configureByFile(path
+ "/before12.java");
214 checkResultByFile(path
+ "/after12.java");
217 public void testAfterNew11() throws Exception
{
218 String path
= BASE_PATH
+ "/afterNew";
220 configureByFile(path
+ "/before13.java");
222 checkResultByFile(path
+ "/after13.java");
225 public void testAfterThrowNew1() throws Exception
{
226 String path
= BASE_PATH
+ "/afterNew";
228 configureByFile(path
+ "/before14.java");
230 checkResultByFile(path
+ "/after14.java");
233 public void testAfterThrowNew2() throws Exception
{
234 String path
= BASE_PATH
+ "/afterNew";
236 configureByFile(path
+ "/before15.java");
238 checkResultByFile(path
+ "/after15.java");
241 public void testAfterThrowNew3() throws Exception
{
242 String path
= BASE_PATH
+ "/afterNew";
244 configureByFile(path
+ "/before16.java");
246 checkResultByFile(path
+ "/after16.java");
249 public void testAfterThrow1() throws Exception
{
250 String path
= BASE_PATH
;
252 configureByFile(path
+ "/CastInThrow.java");
254 checkResultByFile(path
+ "/CastInThrow-out.java");
257 public void testParenAfterNewWithinInnerExpr() throws Exception
{
258 String path
= BASE_PATH
+ "/afterNew";
260 configureByFile(path
+ "/LastArgInInnerNewBefore.java");
261 checkResultByFile(path
+ "/LastArgInInnerNewAfter.java");
263 //configureByFile(path + "/LastArgInInnerNewBefore2.java");
265 //checkResultByFile(path + "/LastArgInInnerNewAfter2.java");
267 configureByFile(path
+ "/LastArgInInnerNewBefore3.java");
268 checkResultByFile(path
+ "/LastArgInInnerNewAfter3.java");
270 configureByFile(path
+ "/LastArgInInnerNewBefore4.java");
271 checkResultByFile(path
+ "/LastArgInInnerNewAfter4.java");
274 public void testReturn1() throws Exception
{
275 String path
= BASE_PATH
+ "/return";
276 configureByFile(path
+ "/before1.java");
277 checkResultByFile(path
+ "/after1.java");
280 public void testReturn2() throws Exception
{
281 String path
= BASE_PATH
+ "/return";
283 configureByFile(path
+ "/before2.java");
284 checkResultByFile(path
+ "/after2.java");
287 public void testReturn3() throws Exception
{
288 String path
= BASE_PATH
+ "/return";
290 configureByFile(path
+ "/before3.java");
291 checkResultByFile(path
+ "/after3.java");
294 public void testGenerics1() throws Exception
{
295 String path
= BASE_PATH
+ "/generics";
297 configureByFile(path
+ "/before1.java");
298 checkResultByFile(path
+ "/after1.java");
301 public void testGenerics2() throws Exception
{
302 String path
= BASE_PATH
+ "/generics";
304 configureByFile(path
+ "/before2.java");
305 checkResultByFile(path
+ "/after2.java");
308 public void testGenerics3() throws Exception
{
309 String path
= BASE_PATH
+ "/generics";
311 configureByFile(path
+ "/before3.java");
312 checkResultByFile(path
+ "/after3.java");
315 public void testGenerics4() throws Exception
{
316 String path
= BASE_PATH
+ "/generics";
318 configureByFile(path
+ "/before4.java");
319 checkResultByFile(path
+ "/after4.java");
322 public void testGenerics5() throws Exception
{
323 String path
= BASE_PATH
+ "/generics";
325 configureByFile(path
+ "/before5.java");
326 checkResultByFile(path
+ "/after5.java");
329 public void testAfterInstanceOf1() throws Exception
{
330 String path
= BASE_PATH
+ "/afterInstanceOf";
332 configureByFile(path
+ "/before1.java");
333 checkResultByFile(path
+ "/after1.java");
336 public void testAfterInstanceOf2() throws Exception
{
337 String path
= BASE_PATH
+ "/afterInstanceOf";
339 configureByFile(path
+ "/before2.java");
340 checkResultByFile(path
+ "/after2.java");
343 public void testInsideCatch() throws Exception
{
344 String path
= BASE_PATH
;
346 configureByFile(path
+ "/InsideCatch.java");
347 checkResultByFile(path
+ "/InsideCatch-out.java");
351 public void testGenerics6() throws Exception
{
352 String path
= BASE_PATH
+ "/generics";
354 configureByFile(path
+ "/before6.java");
355 checkResultByFile(path
+ "/after6.java");
358 public void testWildcardNew1() throws Exception
{
359 String path
= BASE_PATH
+ "/generics";
361 configureByFile(path
+ "/before7.java");
362 checkResultByFile(path
+ "/after7.java");
365 public void testWildcardNew2() throws Exception
{
366 String path
= BASE_PATH
+ "/generics";
368 configureByFile(path
+ "/before8.java");
369 checkResultByFile(path
+ "/after8.java");
372 public void testWildcardEliminated() throws Exception
{
373 String path
= BASE_PATH
+ "/generics";
375 configureByFile(path
+ "/before9.java");
376 checkResultByFile(path
+ "/after9.java");
379 public void testBug1() throws Exception
{ doTest(); }
381 public void testQualifiedThis() throws Exception
{ doTest(); }
383 public void testBug2() throws Exception
{
384 configureByFile(BASE_PATH
+ "/Bug2.java");
388 public void testSillyAssignment1() throws Exception
{
389 configureByFile(BASE_PATH
+ "/Silly1.java");
390 checkResultByFile(BASE_PATH
+ "/Silly1.java");
393 public void testVarargs1() throws Exception
{ doTest(); }
395 public void testEnumConstInSwitch() throws Exception
{ doTest(); }
397 public void testEnumConstInSwitchOutside() throws Exception
{ doTest(); }
399 public void testIntConstInSwitch() throws Exception
{ doTest(); }
401 public void testDoubleEmptyArray() throws Exception
{
402 configureByFile(BASE_PATH
+ "/"+getTestName(false)+".java");
403 checkResultByFile(BASE_PATH
+ "/"+getTestName(false) + ".java");
404 assertEquals(2, myItems
.length
);
407 public void testCollectionsEmptySetInMethodCall() throws Throwable
{ doTest(); }
409 public void testCollectionsEmptySetInTernary() throws Throwable
{ doTest(); }
411 public void testStringConstantInAnno() throws Throwable
{ doTest(); }
413 public void testCollectionsEmptySetInTernary2() throws Throwable
{ doTest(); }
415 public void testConstructorOnSeparateLineInMethodCall() throws Throwable
{ doTest(); }
417 public void testConstructorWithExistingParens() throws Throwable
{ doTest(); }
419 public void testMethodAnnotationNamedParameter() throws Throwable
{ doTest(); }
421 public void testInheritedClass() throws Throwable
{ doTest(); }
423 public void testClassLiteralInAnno1() throws Throwable
{ doTest(); }
425 public void testExplicitWildcardParam() throws Throwable
{ doTest(); }
427 public void testExplicitWildcardArrayParam() throws Throwable
{ doTest(); }
429 public void testCatchInAnonymous() throws Throwable
{ doTest(); }
431 public void testThrowRuntimeException() throws Throwable
{ doTest(); }
433 public void testParameterizedConstructor() throws Throwable
{ doTest(); }
435 public void testNewInnerOfParameterizedClass() throws Throwable
{ doTest(); }
437 public void testQualifiedThisInAnonymousConstructor() throws Throwable
{ doTest(); }
439 public void testExceptionTwice() throws Throwable
{ doTest(); }
441 public void testExceptionTwice2() throws Throwable
{ doTest(); }
443 public void testNewInnerRunnable() throws Throwable
{ doTest(); }
445 public void testArrayAccessIndex() throws Throwable
{ doTest(); }
447 public void testThrowExceptionConstructor() throws Throwable
{ doTest(); }
449 public void testJavadocThrows() throws Throwable
{ doTest(); }
451 public void testDoNotExcludeAssignedVariable() throws Throwable
{ doTest(); }
453 public void testArrayIndexTailType() throws Throwable
{ doTest(); }
455 public void testHonorSelection() throws Throwable
{ doTest(); }
457 public void testTypeParametersInheritors() throws Throwable
{
458 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
459 assertStringItems("Foo", "Bar", "Goo");
461 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
464 public void testVoidExpectedType() throws Throwable
{
465 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
466 assertStringItems("notify", "notifyAll", "wait", "wait", "wait", "equals", "getClass", "hashCode", "toString");
469 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
472 public void testDoubleSemicolonPenetration() throws Throwable
{ doTest(); }
474 public void testTypeParametersInheritorsComma() throws Throwable
{ doTest(); }
476 public void testTypeParametersInheritorsInExpression() throws Throwable
{ doTest(); }
478 //do we need to see all Object inheritors at all?
479 public void _testTypeParametersObjectInheritors() throws Throwable
{ doTest(); }
481 public void testDoubleThis() throws Throwable
{
486 public void testSmartFinish() throws Throwable
{
487 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
488 select(Lookup
.COMPLETE_STATEMENT_SELECT_CHAR
);
489 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
492 public void testSillyAssignmentInTernary() throws Throwable
{ doTest(); }
494 public void testSameFieldInAnotherObject() throws Throwable
{ doTest(); }
496 public void testUnqualifiedConstantInSwitch() throws Throwable
{ doTest(); }
498 public void testAmbiguousConstant() throws Throwable
{ doTest(); }
500 public void testSameNamedFieldAndLocal() throws Throwable
{ doTest(); }
502 public void testAbstractClassTwice() throws Throwable
{
503 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
504 final int offset
= myEditor
.getCaretModel().getOffset();
506 myEditor
.getCaretModel().moveToOffset(offset
);
507 assertOneElement(myItems
);
510 public void testConstantTwice() throws Throwable
{ doTest(); }
512 public void testConstantTwice2() throws Throwable
{
513 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
514 assertEquals(2, myItems
.length
);
517 public void testNoKeyConstant() throws Throwable
{
518 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
519 assertEquals(2, myItems
.length
);
520 assertEquals("A_KEY", myItems
[0].getLookupString());
521 assertEquals("Key.create", myItems
[1].getLookupString());
524 public void testUserDataListAddAll() throws Throwable
{
528 public void testStaticSubclass() throws Throwable
{
532 public void testMethodCallDot() throws Throwable
{ doTest(); }
533 public void testNegateVariable() throws Throwable
{ doTest(); }
535 public void testExclamationMethodFinish() throws Throwable
{ doTest('!'); }
536 public void testExclamationVariableFinish() throws Throwable
{ doTest('!'); }
537 public void testExclamationStaticFieldFinish() throws Throwable
{ doTest('!'); }
538 public void testExclamationFinishNonBoolean() throws Throwable
{ doTest('!'); }
540 public void testExcludeDeclaredConstant() throws Throwable
{ doTest(); }
542 public void testTabMethodInBinaryExpression() throws Throwable
{ doTest('\t'); }
544 public void testIfConditionBinaryExpression() throws Throwable
{ doTest(); }
546 public void testDelegationToParent() throws Throwable
{ doTest(); }
548 public void testBeforeBinaryExpressionInMethodCall() throws Throwable
{ doTest(); }
550 public void testAssignableToAfterCast() throws Throwable
{ doTest(); }
552 public void testInstanceMethodParametersFromStaticContext() throws Throwable
{ doTest(); }
554 public void testInstanceMethodParametersFromStaticContext2() throws Throwable
{ doTest(); }
556 public void testBeforeCastToArray() throws Throwable
{ doTest(); }
558 public void testHidingFields() throws Throwable
{ doTest(); }
560 public void testVoidCast() throws Throwable
{ doAntiTest(); }
562 public void testIntPlusLongNotDouble() throws Throwable
{ doTest(); }
564 public void testNestedAssignments() throws Throwable
{ doTest(); }
566 public void testAfterNewInTernary() throws Throwable
{ doTest(); }
568 public void testSuggestAnythingWhenWildcardExpected() throws Throwable
{
569 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
570 assertStringItems("X<java.lang.Object>", "Y", "Z<java.lang.Object>");
573 public void testNewVararg() throws Throwable
{
574 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
575 assertStringItems("Foo", "Foo");
576 assertEquals(0, myItems
[0].as(PsiTypeLookupItem
.class).getBracketsCount());
577 assertEquals(1, myItems
[1].as(PsiTypeLookupItem
.class).getBracketsCount());
580 public void testInsideStringLiteral() throws Throwable
{
581 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
583 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
587 public void testDefaultAnnoParam() throws Throwable
{ doTest(); }
589 public void testCastGenericQualifier() throws Throwable
{ doTest(); }
591 public void testEverythingDoubles() throws Throwable
{
592 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
593 assertStringItems("hashCode", "indexOf", "lastIndexOf", "size");
596 public void testNonStaticInnerClass() throws Throwable
{
597 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
599 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
602 //todo 2nd completion
603 public void _testDefaultAnnoParam2() throws Throwable
{ doTest(); }
605 public void testLiveTemplate() throws Throwable
{
606 final Template template
= TemplateManager
.getInstance(getProject()).createTemplate("foo", "zzz");
607 template
.addTextSegment("FooFactory.createFoo()");
608 final SmartCompletionContextType completionContextType
=
609 ContainerUtil
.findInstance(TemplateContextType
.EP_NAME
.getExtensions(), SmartCompletionContextType
.class);
610 ((TemplateImpl
)template
).getTemplateContext().setEnabled(completionContextType
, true);
611 TemplateSettings
.getInstance().addTemplate(template
);
616 TemplateSettings
.getInstance().removeTemplate(template
);
620 public void testInThisExpression() throws Throwable
{ doTest(); }
622 public void testSuggestNull() throws Throwable
{ doTest(); }
624 public void testNoNullAfterDot() throws Throwable
{
625 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
627 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
630 public void testDefaultAnnoMethodValue() throws Throwable
{ doTest(); }
632 public void testUseIntConstantsFromTargetClass() throws Throwable
{ doTest(); }
633 public void testUseIntConstantsFromTargetClassReturnValue() throws Throwable
{ doTest(); }
634 public void testUseIntConstantsFromConstructedClass() throws Throwable
{ doTest(); }
636 public void testExtraSemicolonAfterMethodParam() throws Throwable
{
637 CodeStyleSettings styleSettings
= CodeStyleSettingsManager
.getSettings(getProject());
638 styleSettings
.SPACE_WITHIN_METHOD_CALL_PARENTHESES
= true;
643 styleSettings
.SPACE_WITHIN_METHOD_CALL_PARENTHESES
= false;
647 public void testAssignFromTheSameFieldOfAnotherObject() throws Throwable
{
651 public void testTailAfterInstanceOf() throws Throwable
{
655 public void testSuggestInstanceofedValue() throws Throwable
{
659 public void testSuggestInstanceofedValueInTernary() throws Throwable
{
663 public void testSuggestInstanceofedValueInComplexIf() throws Throwable
{ doTest(); }
665 public void testSuggestInstanceofedValueInElseNegated() throws Throwable
{ doTest(); }
667 public void testSuggestInstanceofedValueAfterReturn() throws Throwable
{ doTest(); }
669 public void testNoInstanceofedValueWhenBasicSuits() throws Throwable
{ doTest(); }
671 public void testSuggestCastedValueAfterCast() throws Throwable
{ doTest(); }
673 public void testNoInstanceofedValueInElse() throws Throwable
{ doAntiTest(); }
675 public void testNoInstanceofedValueInThenNegated() throws Throwable
{ doAntiTest(); }
677 public void testNoInstanceofedValueInElseWithComplexIf() throws Throwable
{ doAntiTest(); }
679 public void testReplaceWholeReferenceChain() throws Throwable
{ doTest(Lookup
.REPLACE_SELECT_CHAR
); }
681 public void testInstanceofedInsideAnonymous() throws Throwable
{ doTest(Lookup
.REPLACE_SELECT_CHAR
); }
683 public void testDoubleTrueInOverloadedMethodCall() throws Throwable
{ doTest(Lookup
.REPLACE_SELECT_CHAR
); }
685 public void testOneElementArray() throws Throwable
{ doTest(); }
687 public void testCastToArray() throws Throwable
{ doTest(); }
689 public void testDontAutoCastWhenAlreadyCasted() throws Throwable
{
690 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
691 assertEquals("s", myItems
[0].getLookupString());
692 assertEquals("String.copyValueOf", myItems
[1].getLookupString());
694 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
697 public void testAutoCastWhenAlreadyCasted() throws Throwable
{ doTest(); }
699 public void testCommaDoublePenetration() throws Throwable
{
700 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
702 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
705 public void testSuperMethodArguments() throws Throwable
{
706 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
707 getLookup().setCurrentItem(getLookup().getItems().get(1));
709 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
712 public void testDelegateMethodArguments() throws Throwable
{
713 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
714 getLookup().setCurrentItem(getLookup().getItems().get(1));
716 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
719 public void testSuperConstructorArguments() throws Throwable
{
720 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
721 getLookup().setCurrentItem(getLookup().getItems().get(2));
723 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
726 private void doAntiTest() throws Exception
{
727 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
729 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
732 public void testAfterNewWithGenerics() throws Exception
{
736 public void testClassLiteral() throws Exception
{
738 assertStringItems("String.class");
740 public void testNoClassLiteral() throws Exception
{
742 assertStringItems("Object.class", "getClass", "Class.forName", "Class.forName");
745 public void testClassLiteralInAnno2() throws Throwable
{
749 public void testClassLiteralInheritors() throws Throwable
{
753 public void testAfterNew15() throws Exception
{
757 public void testInsertOverride() throws Exception
{
758 CodeStyleSettings styleSettings
= CodeStyleSettingsManager
.getSettings(getProject());
759 styleSettings
.INSERT_OVERRIDE_ANNOTATION
= true;
760 LanguageLevelProjectExtension
.getInstance(getProject()).setLanguageLevel(LanguageLevel
.JDK_1_6
);
764 public void testForeach() throws Exception
{
768 public void testIDEADEV2626() throws Exception
{
772 public void testCastWith2TypeParameters() throws Throwable
{ doTest(); }
774 public void testAnnotation() throws Exception
{
776 testByCount(8, "ElementType.ANNOTATION_TYPE", "ElementType.CONSTRUCTOR", "ElementType.FIELD", "ElementType.LOCAL_VARIABLE",
777 "ElementType.METHOD", "ElementType.PACKAGE", "ElementType.PARAMETER", "ElementType.TYPE");
780 protected void checkResultByFile(@NonNls final String filePath
) throws Exception
{
781 if (myItems
!= null) {
782 //System.out.println("items = " + Arrays.asList(myItems));
784 super.checkResultByFile(filePath
);
787 public void testAnnotation2() throws Exception
{
789 testByCount(3, "RetentionPolicy.CLASS", "RetentionPolicy.SOURCE", "RetentionPolicy.RUNTIME");
791 public void testAnnotation2_2() throws Exception
{
793 testByCount(3, "RetentionPolicy.CLASS", "RetentionPolicy.SOURCE", "RetentionPolicy.RUNTIME");
796 public void testAnnotation3() throws Exception
{
800 public void testAnnotation3_2() throws Exception
{
804 public void testAnnotation4() throws Exception
{
807 testByCount(2, "true","false");
810 public void testAnnotation5() throws Exception
{
813 testByCount(2, "CONNECTION","NO_CONNECTION");
816 public void testAnnotation6() throws Exception
{
819 testByCount(8, "ElementType.ANNOTATION_TYPE", "ElementType.CONSTRUCTOR", "ElementType.FIELD", "ElementType.LOCAL_VARIABLE",
820 "ElementType.METHOD", "ElementType.PACKAGE", "ElementType.PARAMETER", "ElementType.TYPE");
823 public void testArrayClone() throws Exception
{
827 public void testIDEADEV5150() throws Exception
{
831 public void testIDEADEV7835() throws Exception
{
835 public void testTypeArgs1() throws Exception
{
839 public void testTypeArgs2() throws Exception
{
843 public void testIDEADEV2668() throws Exception
{
847 public void testExcessiveTail() throws Exception
{
851 public void testExtendsInTypeCast() throws Exception
{
855 public void testIDEADEV13148() throws Exception
{
856 configureByFile(BASE_PATH
+ "/IDEADEV13148.java");
860 public void testOverloadedMethods() throws Throwable
{
864 public void testEnumField() throws Throwable
{
868 public void testEnumField1() throws Exception
{
870 assertEquals(4, myItems
.length
);
873 public void testInsertTypeParametersOnImporting() throws Throwable
{
877 public void testEmptyListInReturn() throws Throwable
{
881 public void testEmptyListInReturn2() throws Throwable
{
885 public void testEmptyListInReturnTernary() throws Throwable
{
889 public void testEmptyListBeforeSemicolon() throws Throwable
{
893 public void testStaticallyImportedMagicMethod() throws Throwable
{
897 public void _testCallVarargArgument() throws Throwable
{ doTest(); }
899 public void testTabToReplaceClassKeyword() throws Throwable
{
900 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
901 selectItem(myItems
[0], Lookup
.REPLACE_SELECT_CHAR
);
902 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
905 public void testNoTypeParametersForToArray() throws Throwable
{
909 public void testInferFromCall() throws Throwable
{
913 public void testInferFromCall1() throws Throwable
{
917 public void testCastToParameterizedType() throws Throwable
{ doActionTest(); }
919 public void testInnerEnumInMethod() throws Throwable
{
923 public void testEnumAsDefaultAnnotationParam() throws Throwable
{ doTest(); }
925 public void testFilterPrivateConstructors() throws Throwable
{ doTest(); }
927 public void testExplicitMethodTypeParametersQualify() throws Throwable
{ doTest(); }
929 public void testWildcardedInstanceof() throws Throwable
{ doTest(); }
930 public void testWildcardedInstanceof2() throws Throwable
{ doTest(); }
931 public void testWildcardedInstanceof3() throws Throwable
{ doTest(); }
933 public void testTypeVariableInstanceOf() throws Throwable
{
934 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
936 assertStringItems("Bar", "Goo");
939 public void testCommonPrefixWithSelection() throws Throwable
{
943 public void testInsideGenericClassLiteral() throws Throwable
{
944 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
945 testByCount(3, "String.class", "StringBuffer.class", "StringBuilder.class");
948 public void testArrayAnnoParameter() throws Throwable
{
952 public void testCastWithGenerics() throws Throwable
{
956 public void testInnerEnum() throws Exception
{
957 configureByFile(BASE_PATH
+ "/"+getTestName(false)+".java");
959 getLookup().setCurrentItem(ContainerUtil
.find(myItems
, new Condition
<LookupElement
>() {
960 public boolean value(final LookupElement lookupItem
) {
961 return "Fubar.Bar".equals(lookupItem
.getLookupString());
965 checkResultByFile(BASE_PATH
+ "/"+getTestName(false) + "-out.java");
968 private void doTest(boolean performAction
, boolean selectItem
) throws Exception
{
969 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
974 selectItem(myItems
[0]);
976 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
979 private void doActionTest() throws Exception
{
983 private void doItemTest() throws Exception
{
987 private void doActionItemTest() throws Exception
{
991 private void performAction() {
995 private void doTest() throws Exception
{
996 doTest(Lookup
.NORMAL_SELECT_CHAR
);
999 private void doTest(final char c
) throws Exception
{
1000 boolean old
= CodeInsightSettings
.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION
;
1001 if (c
!= Lookup
.NORMAL_SELECT_CHAR
) {
1002 CodeInsightSettings
.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION
= false;
1006 configureByFile(BASE_PATH
+ "/" + getTestName(false) + ".java");
1007 if (myItems
!= null && myItems
.length
== 1) {
1010 checkResultByFile(BASE_PATH
+ "/" + getTestName(false) + "-out.java");
1013 if (c
!= Lookup
.NORMAL_SELECT_CHAR
) {
1014 CodeInsightSettings
.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION
= old
;
1020 protected void setUp() throws Exception
{
1022 myPrevLanguageLevel
= LanguageLevelProjectExtension
.getInstance(getJavaFacade().getProject()).getLanguageLevel();
1023 LanguageLevelProjectExtension
.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel
.JDK_1_5
);
1024 setType(CompletionType
.SMART
);
1027 protected void tearDown() throws Exception
{
1028 LookupManager
.getInstance(getProject()).hideActiveLookup();
1029 LanguageLevelProjectExtension
.getInstance(getJavaFacade().getProject()).setLanguageLevel(myPrevLanguageLevel
);
1034 protected Sdk
getProjectJDK() {
1035 return JavaSdkImpl
.getMockJdk15("java 1.5");
1038 private void select() {
1039 select(Lookup
.NORMAL_SELECT_CHAR
);
1042 private static void select(final char c
) {
1043 if (c
!= '\n' && c
!= '\t' && c
!= Lookup
.COMPLETE_STATEMENT_SELECT_CHAR
) {
1048 final TestLookupManager manager
= (TestLookupManager
) LookupManager
.getInstance(getProject());
1049 final Lookup lookup
= manager
.getActiveLookup();
1050 if(lookup
!= null) {
1051 manager
.forceSelection(c
, lookup
.getCurrentItem());