smart completion tests -> community
[fedora-idea.git] / java / java-tests / testSrc / com / intellij / codeInsight / completion / SecondSmartTypeCompletionTest.java
blob1cd9f5cff3a8bffcba7c61e1160838e15c097dec
1 package com.intellij.codeInsight.completion;
3 import com.intellij.JavaTestUtil;
4 import com.intellij.codeInsight.CodeInsightSettings;
5 import com.intellij.codeInsight.lookup.LookupElement;
6 import com.intellij.codeInsight.lookup.LookupElementDecorator;
7 import com.intellij.codeInsight.lookup.LookupItem;
8 import com.intellij.codeInsight.lookup.LookupManager;
9 import com.intellij.codeInsight.lookup.impl.LookupImpl;
10 import com.intellij.openapi.projectRoots.Sdk;
11 import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
12 import com.intellij.openapi.roots.LanguageLevelProjectExtension;
13 import com.intellij.pom.java.LanguageLevel;
14 import com.intellij.testFramework.IdeaTestUtil;
15 import org.jetbrains.annotations.NonNls;
17 import java.util.Arrays;
19 @SuppressWarnings({"ALL"})
20 public class SecondSmartTypeCompletionTest extends LightCompletionTestCase {
21 private static final String BASE_PATH = "/codeInsight/completion/smartType/second";
23 public SecondSmartTypeCompletionTest() {
24 setType(CompletionType.SMART);
27 @Override
28 protected String getTestDataPath() {
29 return JavaTestUtil.getJavaTestDataPath();
32 public void testMethodAsQualifier() throws Throwable { doTest(); }
33 public void testFieldAsQualifier() throws Throwable { doTest(); }
34 public void testMethodWithParams() throws Throwable { doTest(); }
35 public void testMergeMethods() throws Throwable { doTest(); }
37 public void testMethodDelegation() throws Throwable { doTest(); }
39 public void testGenerics() throws Throwable { doTest(); }
40 public void testQualifierMatters() throws Throwable { doTest(); }
42 public void testDifferentQualifiers() throws Throwable {
43 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
44 assertStringItems("b.getGoo", "getBar().getGoo");
47 public void testSuggestArraysAsList() throws Throwable { doTest(); }
48 public void testSuggestArraysAsListWildcard() throws Throwable { doTest(); }
50 public void testSuggestToArrayWithNewEmptyArray() throws Throwable { doTest(); }
51 public void testSuggestToArrayWithNewNonEmptyArray() throws Throwable { doTest(); }
53 public void testSuggestToArrayWithExistingEmptyArray() throws Throwable {
54 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
55 assertStringItems("foos().toArray(EMPTY_ARRAY)", "foos().toArray(EMPTY_ARRAY2)");
56 selectItem(myItems[0]);
57 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
60 public void testToArrayGenericArrayCreation() throws Throwable { doTest(); }
62 public void testToArrayFieldsQualifier() throws Throwable { doTest(); }
63 public void testToArrayMethodQualifier() throws Throwable { doTest(); }
65 public void testToListWithQualifier() throws Throwable { doTest(); }
67 public void testSuggestToArrayWithExistingEmptyArrayFromAnotherClass() throws Throwable {
68 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
69 assertStringItems("foos().toArray(Bar.EMPTY_ARRAY)", "foos().toArray(Bar.EMPTY_ARRAY2)");
70 selectItem(myItems[0]);
71 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
74 public void testIgnoreToString() throws Throwable { doTest(); }
75 public void testDontIgnoreToStringInsideIt() throws Throwable { doTest(); }
76 public void testDontIgnoreToStringInStringBuilders() throws Throwable {
77 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
78 assertStringItems("bar.substring", "bar.substring", "bar.toString");
81 public void testNoObjectMethodsAsFirstPart() throws Throwable { doTest(); }
82 public void testGetClassLoader() throws Throwable { doTest(); }
84 public void testChainingPerformance() throws Throwable {
85 long time = System.currentTimeMillis();
86 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
87 IdeaTestUtil.assertTiming("", 3000, System.currentTimeMillis() - time);
88 assertNotNull(myItems);
91 public void testArrayMemberAccess() throws Throwable { doTest(); }
92 public void testVarargMemberAccess() throws Throwable { doTest(); }
93 public void testQualifiedArrayMemberAccess() throws Throwable { doTest(); }
95 public void testNoArraysAsListCommonPrefix() throws Throwable {
96 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
97 checkResultByFile(BASE_PATH + "/" + getTestName(false) + ".java");
98 assertStringItems("bar()", "foo()");
99 assertEquals("Arrays.asList(f.bar())", ((LookupItem)((LookupElementDecorator)myItems[0]).getDelegate()).getPresentableText());
100 assertEquals("Arrays.asList(f.foo())", ((LookupItem)((LookupElementDecorator)myItems[1]).getDelegate()).getPresentableText());
101 selectItem(myItems[1]);
102 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
105 public void testRestoreInitialPrefix() throws Throwable {
106 configureByFileNoComplete(BASE_PATH + "/" + getTestName(false) + ".java");
107 complete(1);
108 assertStringItems("MyEnum.Bar", "MyEnum.Foo");
109 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
110 complete(1);
111 assertStringItems("MyEnum.Bar", "MyEnum.Foo", "my.getEnum");
114 public void testDontChainStringMethodsOnString() throws Throwable { doTest(); }
116 public void testDontSuggestTooGenericMethods() throws Throwable {
117 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
118 assertEquals("f.barAny", myItems[0].getLookupString());
119 assertEquals("f.zipAny", myItems[1].getLookupString());
122 public void testNoUnqualifiedCastsInQualifiedContext() throws Throwable { doAntiTest(); }
124 private void doAntiTest() throws Exception {
125 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
126 assertNull(myItems);
127 checkResultByFile(BASE_PATH + "/" + getTestName(false) + ".java");
130 public void testCastInstanceofedQualifier() throws Throwable { doTest(); }
132 public void testNoLeftRecursion() throws Throwable {
133 final boolean old = CodeInsightSettings.getInstance().SHOW_STATIC_AFTER_INSTANCE;
134 CodeInsightSettings.getInstance().SHOW_STATIC_AFTER_INSTANCE = true;
135 try {
136 doAntiTest();
138 finally {
139 CodeInsightSettings.getInstance().SHOW_STATIC_AFTER_INSTANCE = old;
143 public void testNoRedundantCasts() throws Throwable {
144 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
145 checkResultByFile(BASE_PATH + "/" + getTestName(false) + ".java");
146 assertStringItems("o.gggg", "false", "true");
149 public void testEmptyListInMethodCall() throws Throwable {
150 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
151 selectItem(myItems[0]);
152 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
155 public void testSingletonMap() throws Throwable {
156 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
157 selectItem(myItems[0]);
158 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
161 protected void checkResultByFile(@NonNls final String filePath) throws Exception {
162 if (myItems != null) {
163 System.out.println("items = " + Arrays.asList(myItems));
165 super.checkResultByFile(filePath);
169 private void doTest() throws Exception {
170 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
171 checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
174 @Override
175 protected void complete() {
176 complete(2);
177 LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
178 myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
181 protected void setUp() throws Exception {
182 super.setUp();
183 LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
186 protected void tearDown() throws Exception {
187 LookupManager.getInstance(getProject()).hideActiveLookup();
188 super.tearDown();
191 @Override
192 protected Sdk getProjectJDK() {
193 return JavaSdkImpl.getMockJdk15("java 1.5");