KT-1151 Code completion for not imported extension functions - test for completion extension function without params
This commit is contained in:
@@ -131,6 +131,7 @@ public class JetCompletionContributor extends CompletionContributor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterate through the function with attempt to resolve found functions
|
||||||
for (String functionFQN : functionFQNs) {
|
for (String functionFQN : functionFQNs) {
|
||||||
// System.out.println(functionFQN);
|
// System.out.println(functionFQN);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package first
|
||||||
|
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
fun firstFun() {
|
||||||
|
val a = ArrayList<Int>()
|
||||||
|
a.toLinke<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// RUNTIME: 1
|
||||||
|
// TIME: 2
|
||||||
|
// EXIST: toLinkedList
|
||||||
|
// NUMBER: 1
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package first
|
||||||
|
|
||||||
|
fun firstFun() {
|
||||||
|
val a = ""
|
||||||
|
a.hello<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: helloFun
|
||||||
|
// EXIST: helloFunPreventAutoInsert
|
||||||
|
// NUMBER: 2
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package second
|
||||||
|
|
||||||
|
fun String.helloFun() {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.helloFunPreventAutoInsert() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package first
|
||||||
|
|
||||||
|
fun firstFun() {
|
||||||
|
val a = ""
|
||||||
|
a.hello<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package second
|
||||||
|
|
||||||
|
fun String.helloFun() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package first
|
||||||
|
|
||||||
|
import second.helloFun
|
||||||
|
|
||||||
|
fun firstFun() {
|
||||||
|
val a = ""
|
||||||
|
a.helloFun()
|
||||||
|
}
|
||||||
@@ -68,17 +68,17 @@ public class ExpectedCompletionUtils {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Integer getExpectedNumber(String fileText) {
|
public Integer getExpectedNumber(String fileText) {
|
||||||
final String[] numberStrings = findListWithPrefix(numberLinePrefix, fileText);
|
return getPrefixedInt(fileText, numberLinePrefix);
|
||||||
if (numberStrings.length > 0) {
|
|
||||||
return Integer.parseInt(numberStrings[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Integer getExecutionTime(String fileText) {
|
public Integer getExecutionTime(String fileText) {
|
||||||
final String[] numberStrings = findListWithPrefix(executionTimePrefix, fileText);
|
return getPrefixedInt(fileText, executionTimePrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static Integer getPrefixedInt(String fileText, String prefix) {
|
||||||
|
final String[] numberStrings = findListWithPrefix(prefix, fileText);
|
||||||
if (numberStrings.length > 0) {
|
if (numberStrings.length > 0) {
|
||||||
return Integer.parseInt(numberStrings[0]);
|
return Integer.parseInt(numberStrings[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ public class JetBasicCompletionTest extends JetCompletionTestBase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testExtensionFromStandardLibrary() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void testFromImports() {
|
public void testFromImports() {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
@@ -101,6 +105,8 @@ public class JetBasicCompletionTest extends JetCompletionTestBase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTestDataPath() {
|
protected String getTestDataPath() {
|
||||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/completion/basic").getPath() +
|
return new File(PluginTestCaseBase.getTestDataPathBase(), "/completion/basic").getPath() +
|
||||||
|
|||||||
@@ -22,7 +22,12 @@ import com.intellij.codeInsight.completion.LightCompletionTestCase;
|
|||||||
import com.intellij.codeInsight.lookup.LookupElement;
|
import com.intellij.codeInsight.lookup.LookupElement;
|
||||||
import com.intellij.codeInsight.lookup.LookupManager;
|
import com.intellij.codeInsight.lookup.LookupManager;
|
||||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||||
|
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||||
import com.intellij.openapi.projectRoots.Sdk;
|
import com.intellij.openapi.projectRoots.Sdk;
|
||||||
|
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||||
|
import com.intellij.openapi.roots.ModuleRootManager;
|
||||||
|
import org.apache.commons.lang.SystemUtils;
|
||||||
|
import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor;
|
||||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,32 +52,71 @@ public abstract class JetCompletionTestBase extends LightCompletionTestCase {
|
|||||||
|
|
||||||
final String fileText = getFile().getText();
|
final String fileText = getFile().getText();
|
||||||
|
|
||||||
Integer completionTime = completionUtils.getExecutionTime(fileText);
|
boolean withKotlinRuntime = ExpectedCompletionUtils.getPrefixedInt(fileText, "// RUNTIME:") != null;
|
||||||
|
|
||||||
complete(completionTime == null ? 1 : completionTime);
|
|
||||||
|
|
||||||
final String[] expected = completionUtils.itemsShouldExist(fileText);
|
try {
|
||||||
final String[] unexpected = completionUtils.itemsShouldAbsent(fileText);
|
if (withKotlinRuntime) {
|
||||||
Integer itemsNumber = completionUtils.getExpectedNumber(fileText);
|
configureWithKotlinRuntime();
|
||||||
|
}
|
||||||
|
|
||||||
assertTrue("Should be some assertions about completion", expected.length != 0 || unexpected.length != 0 || itemsNumber != null);
|
Integer completionTime = completionUtils.getExecutionTime(fileText);
|
||||||
|
|
||||||
assertContainsItems(expected);
|
complete(completionTime == null ? 1 : completionTime);
|
||||||
assertNotContainItems(unexpected);
|
|
||||||
|
|
||||||
if (itemsNumber != null) {
|
final String[] expected = completionUtils.itemsShouldExist(fileText);
|
||||||
assertEquals(itemsNumber.intValue(), myItems.length);
|
final String[] unexpected = completionUtils.itemsShouldAbsent(fileText);
|
||||||
|
Integer itemsNumber = completionUtils.getExpectedNumber(fileText);
|
||||||
|
|
||||||
|
assertTrue("Should be some assertions about completion", expected.length != 0 || unexpected.length != 0 || itemsNumber != null);
|
||||||
|
|
||||||
|
assertContainsItems(expected);
|
||||||
|
assertNotContainItems(unexpected);
|
||||||
|
|
||||||
|
if (itemsNumber != null) {
|
||||||
|
assertEquals(itemsNumber.intValue(), myItems.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
if (withKotlinRuntime) {
|
||||||
|
unConfigureKotlinRuntime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void configureWithKotlinRuntime() {
|
||||||
|
final ModuleRootManager rootManager = ModuleRootManager.getInstance(getModule());
|
||||||
|
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||||
|
|
||||||
|
rootModel.setSdk(getFullJavaJDK());
|
||||||
|
JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE.configureModule(getModule(), rootModel, null);
|
||||||
|
|
||||||
|
rootModel.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unConfigureKotlinRuntime() {
|
||||||
|
final ModuleRootManager rootManager = ModuleRootManager.getInstance(getModule());
|
||||||
|
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||||
|
|
||||||
|
rootModel.setSdk(getProjectJDK());
|
||||||
|
JetWithJdkAndRuntimeLightProjectDescriptor.unConfigureModule(rootModel);
|
||||||
|
|
||||||
|
rootModel.commit();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Sdk getProjectJDK() {
|
protected Sdk getProjectJDK() {
|
||||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static Sdk getFullJavaJDK() {
|
||||||
|
return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void complete(final int time) {
|
protected void complete(final int time) {
|
||||||
new CodeCompletionHandlerBase(type, false, false, true).invokeCompletion(getProject(), getEditor(), time, false);
|
new CodeCompletionHandlerBase(type, false, false, true).invokeCompletion(getProject(), getEditor(), time, false);
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ public class JetMultifileBasicCompletionTest extends JetCompletionMultiTestBase
|
|||||||
doFileTest(2);
|
doFileTest(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNotImportedExtensionFunction() throws Exception {
|
||||||
|
doFileTest(2);
|
||||||
|
}
|
||||||
|
|
||||||
public void testExtensionFunction() throws Exception {
|
public void testExtensionFunction() throws Exception {
|
||||||
// TODO: fix and uncomment
|
// TODO: fix and uncomment
|
||||||
// doFileTest();
|
// doFileTest();
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ import java.io.File;
|
|||||||
*/
|
*/
|
||||||
public class CompletionMultifileHandlerTest extends CompletionTestCase {
|
public class CompletionMultifileHandlerTest extends CompletionTestCase {
|
||||||
|
|
||||||
|
public void testExtensionFunctions() throws Exception {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void testTopLevelFunctionImport() throws Exception {
|
public void testTopLevelFunctionImport() throws Exception {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-4
@@ -21,14 +21,14 @@ import com.intellij.openapi.module.ModuleType;
|
|||||||
import com.intellij.openapi.module.StdModuleTypes;
|
import com.intellij.openapi.module.StdModuleTypes;
|
||||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||||
import com.intellij.openapi.projectRoots.Sdk;
|
import com.intellij.openapi.projectRoots.Sdk;
|
||||||
import com.intellij.openapi.roots.ContentEntry;
|
import com.intellij.openapi.roots.*;
|
||||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
|
||||||
import com.intellij.openapi.roots.OrderRootType;
|
|
||||||
import com.intellij.openapi.roots.libraries.Library;
|
import com.intellij.openapi.roots.libraries.Library;
|
||||||
import com.intellij.openapi.vfs.JarFileSystem;
|
import com.intellij.openapi.vfs.JarFileSystem;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.testFramework.LightProjectDescriptor;
|
import com.intellij.testFramework.LightProjectDescriptor;
|
||||||
import org.apache.commons.lang.SystemUtils;
|
import org.apache.commons.lang.SystemUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.codegen.ForTestCompileStdlib;
|
import org.jetbrains.jet.codegen.ForTestCompileStdlib;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,11 +52,25 @@ public class JetWithJdkAndRuntimeLightProjectDescriptor implements LightProjectD
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
|
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @Nullable ContentEntry contentEntry) {
|
||||||
Library.ModifiableModel modifiableModel = model.getModuleLibraryTable().createLibrary("ktl").getModifiableModel();
|
Library.ModifiableModel modifiableModel = model.getModuleLibraryTable().createLibrary("ktl").getModifiableModel();
|
||||||
VirtualFile cd = JarFileSystem.getInstance().findFileByPath(ForTestCompileStdlib.stdlibJarForTests() + "!/");
|
VirtualFile cd = JarFileSystem.getInstance().findFileByPath(ForTestCompileStdlib.stdlibJarForTests() + "!/");
|
||||||
assert cd != null;
|
assert cd != null;
|
||||||
modifiableModel.addRoot(cd, OrderRootType.CLASSES);
|
modifiableModel.addRoot(cd, OrderRootType.CLASSES);
|
||||||
modifiableModel.commit();
|
modifiableModel.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void unConfigureModule(@NotNull ModifiableRootModel model) {
|
||||||
|
for (OrderEntry orderEntry : model.getOrderEntries()) {
|
||||||
|
if (orderEntry instanceof LibraryOrderEntry) {
|
||||||
|
LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;
|
||||||
|
|
||||||
|
Library library = libraryOrderEntry.getLibrary();
|
||||||
|
if (library != null && library.getName().equals("ktl")) {
|
||||||
|
model.getModuleLibraryTable().removeLibrary(library);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user