SmartTypeCompletion15Test merged into SmartTypeCompletionTest
[fedora-idea.git] / java / java-tests / testSrc / com / intellij / codeInsight / completion / SmartTypeCompletionTest.java
blob7dd7dc3ade643e9673fa0df3c15696feb3c62c30
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;
30 @Override
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;
107 try{
108 complete();
110 finally{
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");
141 select();
142 checkResultByFile(path + "/after1.java");
145 public void testAfterNew2() throws Exception {
146 String path = BASE_PATH + "/afterNew";
148 configureByFile(path + "/before2.java");
149 select();
150 checkResultByFile(path + "/after2.java");
153 public void testAfterNew3() throws Exception {
154 String path = BASE_PATH + "/afterNew";
156 configureByFile(path + "/before3.java");
157 select();
158 checkResultByFile(path + "/after3.java");
161 public void testAfterNew4() throws Exception {
162 String path = BASE_PATH + "/afterNew";
164 configureByFile(path + "/before4.java");
165 select();
166 checkResultByFile(path + "/after4.java");
169 public void testAfterNew5() throws Exception {
170 String path = BASE_PATH + "/afterNew";
172 configureByFile(path + "/before5.java");
173 select();
174 checkResultByFile(path + "/after5.java");
177 public void testAfterNew6() throws Exception {
178 String path = BASE_PATH + "/afterNew";
180 configureByFile(path + "/before6.java");
181 select();
182 checkResultByFile(path + "/after6.java");
185 public void testAfterNew7() throws Exception {
186 String path = BASE_PATH + "/afterNew";
188 configureByFile(path + "/before7.java");
189 select();
190 checkResultByFile(path + "/after7.java");
193 public void testAfterNew8() throws Exception {
194 String path = BASE_PATH + "/afterNew";
196 configureByFile(path + "/before8.java");
197 select();
198 checkResultByFile(path + "/after8.java");
201 public void testAfterNew9() throws Exception {
202 String path = BASE_PATH + "/afterNew";
204 configureByFile(path + "/before10.java");
205 select();
206 checkResultByFile(path + "/after10.java");
209 public void testAfterNew10() throws Exception {
210 String path = BASE_PATH + "/afterNew";
212 configureByFile(path + "/before12.java");
213 //select();
214 checkResultByFile(path + "/after12.java");
217 public void testAfterNew11() throws Exception {
218 String path = BASE_PATH + "/afterNew";
220 configureByFile(path + "/before13.java");
221 //select();
222 checkResultByFile(path + "/after13.java");
225 public void testAfterThrowNew1() throws Exception {
226 String path = BASE_PATH + "/afterNew";
228 configureByFile(path + "/before14.java");
229 //select();
230 checkResultByFile(path + "/after14.java");
233 public void testAfterThrowNew2() throws Exception {
234 String path = BASE_PATH + "/afterNew";
236 configureByFile(path + "/before15.java");
237 //select();
238 checkResultByFile(path + "/after15.java");
241 public void testAfterThrowNew3() throws Exception {
242 String path = BASE_PATH + "/afterNew";
244 configureByFile(path + "/before16.java");
245 //select();
246 checkResultByFile(path + "/after16.java");
249 public void testAfterThrow1() throws Exception {
250 String path = BASE_PATH;
252 configureByFile(path + "/CastInThrow.java");
253 //select();
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");
264 //performAction();
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");
460 select();
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");
467 type('e');
468 select();
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 {
482 doTest();
483 assertNull(myItems);
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();
505 select();
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 {
525 doTest();
528 public void testStaticSubclass() throws Throwable {
529 doTest();
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");
582 assertNull(myItems);
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");
598 assertNull(myItems);
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);
612 try {
613 doTest();
615 finally {
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");
626 assertNull(myItems);
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;
639 try{
640 doTest();
642 finally{
643 styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
647 public void testAssignFromTheSameFieldOfAnotherObject() throws Throwable {
648 doTest();
651 public void testTailAfterInstanceOf() throws Throwable {
652 doTest();
655 public void testSuggestInstanceofedValue() throws Throwable {
656 doTest();
659 public void testSuggestInstanceofedValueInTernary() throws Throwable {
660 doTest();
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());
693 select();
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");
701 select(',');
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));
708 select();
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));
715 select();
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));
722 select();
723 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
726 private void doAntiTest() throws Exception {
727 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
728 assertNull(myItems);
729 checkResultByFile(BASE_PATH + "/" + getTestName(false) + ".java");
732 public void testAfterNewWithGenerics() throws Exception {
733 doActionTest();
736 public void testClassLiteral() throws Exception {
737 doActionTest();
738 assertStringItems("String.class");
740 public void testNoClassLiteral() throws Exception {
741 doActionTest();
742 assertStringItems("Object.class", "getClass", "Class.forName", "Class.forName");
745 public void testClassLiteralInAnno2() throws Throwable {
746 doActionItemTest();
749 public void testClassLiteralInheritors() throws Throwable {
750 doActionItemTest();
753 public void testAfterNew15() throws Exception {
754 doActionItemTest();
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);
761 doActionItemTest();
764 public void testForeach() throws Exception {
765 doActionTest();
768 public void testIDEADEV2626() throws Exception {
769 doActionTest();
772 public void testCastWith2TypeParameters() throws Throwable { doTest(); }
774 public void testAnnotation() throws Exception {
775 doTest();
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 {
788 doTest();
789 testByCount(3, "RetentionPolicy.CLASS", "RetentionPolicy.SOURCE", "RetentionPolicy.RUNTIME");
791 public void testAnnotation2_2() throws Exception {
792 doTest();
793 testByCount(3, "RetentionPolicy.CLASS", "RetentionPolicy.SOURCE", "RetentionPolicy.RUNTIME");
796 public void testAnnotation3() throws Exception {
797 doTest();
800 public void testAnnotation3_2() throws Exception {
801 doTest();
804 public void testAnnotation4() throws Exception {
805 doTest();
807 testByCount(2, "true","false");
810 public void testAnnotation5() throws Exception {
811 doTest();
813 testByCount(2, "CONNECTION","NO_CONNECTION");
816 public void testAnnotation6() throws Exception {
817 doTest();
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 {
824 doTest();
827 public void testIDEADEV5150() throws Exception {
828 doTest();
831 public void testIDEADEV7835() throws Exception {
832 doTest();
835 public void testTypeArgs1() throws Exception {
836 doTest();
839 public void testTypeArgs2() throws Exception {
840 doTest();
843 public void testIDEADEV2668() throws Exception {
844 doTest();
847 public void testExcessiveTail() throws Exception {
848 doTest();
851 public void testExtendsInTypeCast() throws Exception {
852 doTest();
855 public void testIDEADEV13148() throws Exception {
856 configureByFile(BASE_PATH + "/IDEADEV13148.java");
857 testByCount(0);
860 public void testOverloadedMethods() throws Throwable {
861 doTest();
864 public void testEnumField() throws Throwable {
865 doItemTest();
868 public void testEnumField1() throws Exception {
869 doTest();
870 assertEquals(4, myItems.length);
873 public void testInsertTypeParametersOnImporting() throws Throwable {
874 doTest();
877 public void testEmptyListInReturn() throws Throwable {
878 doItemTest();
881 public void testEmptyListInReturn2() throws Throwable {
882 doTest();
885 public void testEmptyListInReturnTernary() throws Throwable {
886 doItemTest();
889 public void testEmptyListBeforeSemicolon() throws Throwable {
890 doItemTest();
893 public void testStaticallyImportedMagicMethod() throws Throwable {
894 doItemTest();
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 {
906 doTest();
909 public void testInferFromCall() throws Throwable {
910 doTest();
913 public void testInferFromCall1() throws Throwable {
914 doTest();
917 public void testCastToParameterizedType() throws Throwable { doActionTest(); }
919 public void testInnerEnumInMethod() throws Throwable {
920 doActionItemTest();
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");
935 performAction();
936 assertStringItems("Bar", "Goo");
939 public void testCommonPrefixWithSelection() throws Throwable {
940 doItemTest();
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 {
949 doActionTest();
952 public void testCastWithGenerics() throws Throwable {
953 doActionTest();
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());
963 }));
964 select('\n');
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");
970 if (performAction) {
971 performAction();
973 if (selectItem) {
974 selectItem(myItems[0]);
976 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
979 private void doActionTest() throws Exception {
980 doTest(true, false);
983 private void doItemTest() throws Exception {
984 doTest(false, true);
987 private void doActionItemTest() throws Exception {
988 doTest(true, true);
991 private void performAction() {
992 complete();
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;
1005 try {
1006 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
1007 if (myItems != null && myItems.length == 1) {
1008 select(c);
1010 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
1012 finally {
1013 if (c != Lookup.NORMAL_SELECT_CHAR) {
1014 CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = old;
1020 protected void setUp() throws Exception {
1021 super.setUp();
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);
1030 super.tearDown();
1033 @Override
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) {
1044 type(c);
1045 return;
1048 final TestLookupManager manager = (TestLookupManager) LookupManager.getInstance(getProject());
1049 final Lookup lookup = manager.getActiveLookup();
1050 if(lookup != null) {
1051 manager.forceSelection(c, lookup.getCurrentItem());