Rewrite NavigateToStdlibSourceTest with project descriptors
This commit is contained in:
+21
@@ -112,6 +112,27 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
||||
|
||||
return when (platformId) {
|
||||
JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES -> KotlinJdkAndMultiplatformStdlibDescriptor.JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES
|
||||
|
||||
KOTLIN_JVM_WITH_STDLIB_SOURCES -> ProjectDescriptorWithStdlibSources.INSTANCE
|
||||
|
||||
KOTLIN_JAVASCRIPT -> KotlinStdJSProjectDescriptor
|
||||
|
||||
KOTLIN_JVM_WITH_STDLIB_SOURCES_WITH_ADDITIONAL_JS -> {
|
||||
KotlinMultiModuleProjectDescriptor(
|
||||
KOTLIN_JVM_WITH_STDLIB_SOURCES_WITH_ADDITIONAL_JS,
|
||||
mainModuleDescriptor = ProjectDescriptorWithStdlibSources.INSTANCE,
|
||||
additionalModuleDescriptor = KotlinStdJSProjectDescriptor
|
||||
)
|
||||
}
|
||||
|
||||
KOTLIN_JAVASCRIPT_WITH_ADDITIONAL_JVM_WITH_STDLIB -> {
|
||||
KotlinMultiModuleProjectDescriptor(
|
||||
KOTLIN_JAVASCRIPT_WITH_ADDITIONAL_JVM_WITH_STDLIB,
|
||||
mainModuleDescriptor = KotlinStdJSProjectDescriptor,
|
||||
additionalModuleDescriptor = ProjectDescriptorWithStdlibSources.INSTANCE
|
||||
)
|
||||
}
|
||||
|
||||
else -> throw IllegalStateException("Unknown value for project descriptor kind")
|
||||
}
|
||||
}
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.test
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ModifiableRootModel
|
||||
|
||||
class KotlinMultiModuleProjectDescriptor(
|
||||
val id: String,
|
||||
private val mainModuleDescriptor: KotlinLightProjectDescriptor,
|
||||
private val additionalModuleDescriptor: KotlinLightProjectDescriptor
|
||||
) : KotlinLightProjectDescriptor() {
|
||||
lateinit var additionalModule: Module
|
||||
|
||||
override fun setUpProject(project: Project, handler: SetupHandler) {
|
||||
super.setUpProject(project, handler)
|
||||
|
||||
additionalModule = additionalModuleDescriptor.createMainModule(project)
|
||||
}
|
||||
|
||||
override fun configureModule(module: Module, model: ModifiableRootModel) {
|
||||
mainModuleDescriptor.configureModule(module, model)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as KotlinMultiModuleProjectDescriptor
|
||||
|
||||
if (id != other.id) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return id.hashCode()
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -9,4 +9,12 @@ package org.jetbrains.kotlin.idea.test
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
annotation class ProjectDescriptorKind(val value: String)
|
||||
|
||||
const val JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES = "JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES"
|
||||
const val JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES = "JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES"
|
||||
|
||||
const val KOTLIN_JVM_WITH_STDLIB_SOURCES = "KOTLIN_JVM_WITH_STDLIB_SOURCES"
|
||||
|
||||
const val KOTLIN_JAVASCRIPT = "KOTLIN_JAVASCRIPT"
|
||||
|
||||
const val KOTLIN_JVM_WITH_STDLIB_SOURCES_WITH_ADDITIONAL_JS = "KOTLIN_JVM_WITH_STDLIB_SOURCES_WITH_ADDITIONAL_JS"
|
||||
|
||||
const val KOTLIN_JAVASCRIPT_WITH_ADDITIONAL_JVM_WITH_STDLIB = "KOTLIN_JAVASCRIPT_WITH_ADDITIONAL_JVM_WITH_STDLIB"
|
||||
+30
-3
@@ -7,9 +7,7 @@ package org.jetbrains.kotlin.idea.decompiler.navigation
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.test.JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.ProjectDescriptorKind
|
||||
import org.jetbrains.kotlin.idea.test.*
|
||||
|
||||
class LightNavigateToStdlibSourceTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
@ProjectDescriptorKind(JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES)
|
||||
@@ -28,6 +26,35 @@ class LightNavigateToStdlibSourceTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
)
|
||||
}
|
||||
|
||||
@ProjectDescriptorKind(KOTLIN_JVM_WITH_STDLIB_SOURCES)
|
||||
fun testRefToPrintlnWithJVM() {
|
||||
doTest(
|
||||
"fun foo() { <caret>println() }",
|
||||
"Console.kt")
|
||||
}
|
||||
|
||||
@ProjectDescriptorKind(KOTLIN_JAVASCRIPT)
|
||||
fun testRefToPrintlnWithJS() {
|
||||
doTest(
|
||||
"fun foo() { <caret>println() }",
|
||||
"console.kt"
|
||||
)
|
||||
}
|
||||
|
||||
@ProjectDescriptorKind(KOTLIN_JVM_WITH_STDLIB_SOURCES_WITH_ADDITIONAL_JS)
|
||||
fun testRefToPrintlnWithJVMAndJS() {
|
||||
doTest(
|
||||
"fun foo() { <caret>println() }",
|
||||
"Console.kt")
|
||||
}
|
||||
|
||||
@ProjectDescriptorKind(KOTLIN_JAVASCRIPT_WITH_ADDITIONAL_JVM_WITH_STDLIB)
|
||||
fun testRefToPrintlnWithJSAndJVM() {
|
||||
doTest(
|
||||
"fun foo() { <caret>println() }",
|
||||
"console.kt")
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor() = getProjectDescriptorFromAnnotation()
|
||||
|
||||
private fun doTest(text: String, sourceFileName: String) {
|
||||
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.idea.decompiler.navigation
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.test.*
|
||||
|
||||
class NavigateToStdlibSourceTest : KotlinCodeInsightTestCase() {
|
||||
|
||||
private val FILE_TEXT = "fun foo() { <caret>println() }"
|
||||
|
||||
fun testRefToPrintlnWithJVM() {
|
||||
doTest("Console.kt", ModuleKind.KOTLIN_JVM_WITH_STDLIB_SOURCES)
|
||||
}
|
||||
|
||||
fun testRefToPrintlnWithJVMAndJS() {
|
||||
doTest("Console.kt", ModuleKind.KOTLIN_JVM_WITH_STDLIB_SOURCES, ModuleKind.KOTLIN_JAVASCRIPT)
|
||||
}
|
||||
|
||||
fun testRefToPrintlnWithJS() {
|
||||
doTest("console.kt", ModuleKind.KOTLIN_JAVASCRIPT)
|
||||
}
|
||||
|
||||
fun testRefToPrintlnWithJSAndJVM() {
|
||||
doTest("console.kt", ModuleKind.KOTLIN_JAVASCRIPT, ModuleKind.KOTLIN_JVM_WITH_STDLIB_SOURCES)
|
||||
}
|
||||
|
||||
private fun doTest(sourceFileName: String, mainModule: ModuleKind, additionalModule: ModuleKind? = null) {
|
||||
val navigationElement = configureAndResolve(FILE_TEXT, mainModule, additionalModule)
|
||||
TestCase.assertEquals(sourceFileName, navigationElement.containingFile.name)
|
||||
}
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
|
||||
PluginTestCaseBase.addJdk(testRootDisposable) { ProjectDescriptorWithStdlibSources.INSTANCE.sdk }
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
super.tearDown()
|
||||
// Workaround for IDEA's bug during tests.
|
||||
// After tests IDEA disposes VirtualFiles within LocalFileSystem, but doesn't rebuild indices.
|
||||
// This causes library source files to be impossible to find via indices
|
||||
closeAndDeleteProject()
|
||||
}
|
||||
|
||||
protected fun configureAndResolve(
|
||||
text: String,
|
||||
mainModuleKind: ModuleKind,
|
||||
additionalModuleKind: ModuleKind? = null
|
||||
): PsiElement {
|
||||
module.configureAs(mainModuleKind)
|
||||
if (additionalModuleKind != null) {
|
||||
val additionalModule = this.createModule("additional-module")
|
||||
additionalModule.configureAs(additionalModuleKind)
|
||||
}
|
||||
|
||||
configureByText(KotlinFileType.INSTANCE, text)
|
||||
|
||||
val ref = file.findReferenceAt(editor.caretModel.offset)
|
||||
val resolve = ref!!.resolve()
|
||||
return resolve!!.navigationElement
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user