diff --git a/idea/testData/completion/codeFragmentInLibrarySource/customLibrary/customLibrary.kt b/idea/testData/completion/codeFragmentInLibrarySource/customLibrary/customLibrary.kt new file mode 100644 index 00000000000..be0316d3fb7 --- /dev/null +++ b/idea/testData/completion/codeFragmentInLibrarySource/customLibrary/customLibrary.kt @@ -0,0 +1,5 @@ +package customLibrary + +public fun foo(parameter: Int): Int { + return 1 +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/JdkAndMockLibraryProjectDescriptor.java b/idea/tests/org/jetbrains/jet/plugin/JdkAndMockLibraryProjectDescriptor.java index 1da204523bf..be64dc1776f 100644 --- a/idea/tests/org/jetbrains/jet/plugin/JdkAndMockLibraryProjectDescriptor.java +++ b/idea/tests/org/jetbrains/jet/plugin/JdkAndMockLibraryProjectDescriptor.java @@ -27,6 +27,8 @@ import org.jetbrains.jet.MockLibraryUtil; import java.io.File; public class JdkAndMockLibraryProjectDescriptor extends JetLightProjectDescriptor { + public static final String LIBRARY_NAME = "myKotlinLib"; + private final String sourcesPath; private final boolean withSources; @@ -37,10 +39,10 @@ public class JdkAndMockLibraryProjectDescriptor extends JetLightProjectDescripto @Override public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { - File libraryJar = MockLibraryUtil.compileLibraryToJar(sourcesPath, "myKotlinLib,", withSources); + File libraryJar = MockLibraryUtil.compileLibraryToJar(sourcesPath, LIBRARY_NAME, withSources); String jarUrl = "jar://" + FileUtilRt.toSystemIndependentName(libraryJar.getAbsolutePath()) + "!/"; - Library.ModifiableModel libraryModel = model.getModuleLibraryTable().getModifiableModel().createLibrary("myKotlinLib").getModifiableModel(); + Library.ModifiableModel libraryModel = model.getModuleLibraryTable().getModifiableModel().createLibrary(LIBRARY_NAME).getModifiableModel(); libraryModel.addRoot(jarUrl, OrderRootType.CLASSES); if (withSources) { libraryModel.addRoot(jarUrl + "src/", OrderRootType.SOURCES); diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/CodeFragmentCompletionInLibraryTest.kt b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/CodeFragmentCompletionInLibraryTest.kt new file mode 100644 index 00000000000..8d3ff0477d1 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/CodeFragmentCompletionInLibraryTest.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.debugger.evaluate + +import org.jetbrains.jet.completion.AbstractJvmBasicCompletionTest +import com.intellij.openapi.vfs.LocalFileSystem +import com.intellij.psi.PsiManager +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.lang.psi.JetFunction +import org.jetbrains.jet.lang.psi.JetPsiFactory +import org.jetbrains.jet.completion.util.testCompletion +import org.jetbrains.jet.plugin.project.TargetPlatform +import com.intellij.codeInsight.completion.CompletionType +import org.jetbrains.jet.plugin.JdkAndMockLibraryProjectDescriptor +import org.jetbrains.jet.plugin.PluginTestCaseBase +import com.intellij.openapi.module.Module +import com.intellij.openapi.roots.ModifiableRootModel +import com.intellij.openapi.roots.ContentEntry +import java.io.File +import com.intellij.openapi.roots.OrderRootType +import com.intellij.openapi.vfs.VirtualFile + +private val LIBRARY_SRC_PATH = PluginTestCaseBase.getTestDataPathBase() + "/completion/codeFragmentInLibrarySource/customLibrary/" + +public class CodeFragmentCompletionInLibraryTest : AbstractJvmBasicCompletionTest() { + + override fun getProjectDescriptor() = object: JdkAndMockLibraryProjectDescriptor(LIBRARY_SRC_PATH, false) { + override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry?) { + super.configureModule(module, model, contentEntry) + + val library = model.getModuleLibraryTable().getLibraryByName(JdkAndMockLibraryProjectDescriptor.LIBRARY_NAME) + val modifiableModel = library.getModifiableModel() + + modifiableModel.addRoot(findLibrarySourceDir(), OrderRootType.SOURCES) + modifiableModel.commit() + } + } + + public fun testCompletionInCustomLibrary() { + val sourceFile = findLibrarySourceDir().findChild("customLibrary.kt") + val jetFile = PsiManager.getInstance(getProject()).findFile(sourceFile) as JetFile + val fooFunctionFromLibrary = jetFile.getDeclarations().first() as JetFunction + val codeFragment = JetPsiFactory(fooFunctionFromLibrary).createExpressionCodeFragment( + "", + KotlinCodeFragmentFactory.getContextElement(fooFunctionFromLibrary.getBodyExpression()) + ) + myFixture.configureFromExistingVirtualFile(codeFragment.getVirtualFile()) + testCompletion("//EXIST: parameter", TargetPlatform.JVM, { + myFixture.complete(CompletionType.BASIC) + }) + } + + private fun findLibrarySourceDir(): VirtualFile { + return LocalFileSystem.getInstance().findFileByIoFile(File(LIBRARY_SRC_PATH))!! + } +} \ No newline at end of file