Tests for navigation to stdlib multiplatform sources (KT-26004)
#KT-26004 Fixed
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.module.ModuleType
|
||||||
|
import com.intellij.openapi.module.StdModuleTypes
|
||||||
|
import com.intellij.openapi.projectRoots.Sdk
|
||||||
|
import com.intellij.openapi.roots.ModifiableRootModel
|
||||||
|
import com.intellij.openapi.roots.OrderRootType
|
||||||
|
import com.intellij.openapi.roots.libraries.Library
|
||||||
|
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor
|
||||||
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class KotlinJdkAndMultiplatformStdlibDescriptor private constructor(private val withSources: Boolean) : KotlinLightProjectDescriptor() {
|
||||||
|
override fun getModuleType(): ModuleType<*> = StdModuleTypes.JAVA
|
||||||
|
|
||||||
|
override fun getSdk(): Sdk? = PluginTestCaseBase.mockJdk8()
|
||||||
|
|
||||||
|
override fun configureModule(module: Module, model: ModifiableRootModel) {
|
||||||
|
model.addLib(
|
||||||
|
STDLIB_COMMON_LIB_NAME,
|
||||||
|
withSources,
|
||||||
|
ForTestCompileRuntime.stdlibCommonForTests(),
|
||||||
|
ForTestCompileRuntime.stdlibCommonSourcesForTests()
|
||||||
|
)
|
||||||
|
|
||||||
|
model.addLib(
|
||||||
|
STDLIB_LIB_NAME,
|
||||||
|
withSources,
|
||||||
|
ForTestCompileRuntime.runtimeJarForTests(),
|
||||||
|
ForTestCompileRuntime.stdlibMavenSourcesJarForTests()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES = KotlinJdkAndMultiplatformStdlibDescriptor(true)
|
||||||
|
|
||||||
|
private fun ModifiableRootModel.addLib(name: String, withSources: Boolean, classesJar: File, sourcesJar: File?): Library {
|
||||||
|
val editor = NewLibraryEditor().apply {
|
||||||
|
this.name = name
|
||||||
|
addRoot(VfsUtil.getUrlForLibraryRoot(classesJar), OrderRootType.CLASSES)
|
||||||
|
|
||||||
|
if (withSources && sourcesJar != null) {
|
||||||
|
addRoot(VfsUtil.getUrlForLibraryRoot(sourcesJar), OrderRootType.SOURCES)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConfigLibraryUtil.addLibrary(editor, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val STDLIB_COMMON_LIB_NAME = "stdlib-common"
|
||||||
|
private const val STDLIB_LIB_NAME = "stdlib"
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
-2
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.test
|
package org.jetbrains.kotlin.idea.test
|
||||||
|
|
||||||
import com.intellij.codeInsight.CodeInsightTestCase
|
|
||||||
import com.intellij.codeInsight.daemon.impl.EditorTracker
|
import com.intellij.codeInsight.daemon.impl.EditorTracker
|
||||||
import com.intellij.ide.highlighter.JavaFileType
|
import com.intellij.ide.highlighter.JavaFileType
|
||||||
import com.intellij.ide.startup.impl.StartupManagerImpl
|
import com.intellij.ide.startup.impl.StartupManagerImpl
|
||||||
@@ -31,7 +30,9 @@ import com.intellij.testFramework.LightProjectDescriptor
|
|||||||
import com.intellij.testFramework.LoggedErrorProcessor
|
import com.intellij.testFramework.LoggedErrorProcessor
|
||||||
import org.apache.log4j.Logger
|
import org.apache.log4j.Logger
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.config.*
|
import org.jetbrains.kotlin.config.CompilerSettings
|
||||||
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersion
|
||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||||
@@ -94,6 +95,16 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
|||||||
override fun getProjectDescriptor(): LightProjectDescriptor
|
override fun getProjectDescriptor(): LightProjectDescriptor
|
||||||
= getProjectDescriptorFromFileDirective()
|
= getProjectDescriptorFromFileDirective()
|
||||||
|
|
||||||
|
protected fun getProjectDescriptorFromAnnotation(): LightProjectDescriptor {
|
||||||
|
val testMethod = this::class.java.getDeclaredMethod(name)
|
||||||
|
val platformId = testMethod.getAnnotation(ProjectDescriptorKind::class.java)?.value
|
||||||
|
|
||||||
|
return when (platformId) {
|
||||||
|
JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES -> KotlinJdkAndMultiplatformStdlibDescriptor.JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES
|
||||||
|
else -> throw IllegalStateException("Unknown value for project descriptor kind")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected fun getProjectDescriptorFromTestName(): LightProjectDescriptor {
|
protected fun getProjectDescriptorFromTestName(): LightProjectDescriptor {
|
||||||
val testName = StringUtil.toLowerCase(getTestName(false))
|
val testName = StringUtil.toLowerCase(getTestName(false))
|
||||||
|
|
||||||
|
|||||||
+10
@@ -95,6 +95,16 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
|||||||
override fun getProjectDescriptor(): LightProjectDescriptor
|
override fun getProjectDescriptor(): LightProjectDescriptor
|
||||||
= getProjectDescriptorFromFileDirective()
|
= getProjectDescriptorFromFileDirective()
|
||||||
|
|
||||||
|
protected fun getProjectDescriptorFromAnnotation(): LightProjectDescriptor {
|
||||||
|
val testMethod = this::class.java.getDeclaredMethod(name)
|
||||||
|
val platformId = testMethod.getAnnotation(ProjectDescriptorKind::class.java)?.value
|
||||||
|
|
||||||
|
return when (platformId) {
|
||||||
|
JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES -> KotlinJdkAndMultiplatformStdlibDescriptor.JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES
|
||||||
|
else -> throw IllegalStateException("Unknown value for project descriptor kind")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected fun getProjectDescriptorFromTestName(): LightProjectDescriptor {
|
protected fun getProjectDescriptorFromTestName(): LightProjectDescriptor {
|
||||||
val testName = StringUtil.toLowerCase(getTestName(false))
|
val testName = StringUtil.toLowerCase(getTestName(false))
|
||||||
|
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
|
annotation class ProjectDescriptorKind(val value: String)
|
||||||
|
|
||||||
|
const val JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES = "JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES"
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.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
|
||||||
|
|
||||||
|
class LightNavigateToStdlibSourceTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
|
@ProjectDescriptorKind(JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES)
|
||||||
|
fun testNavigateToCommonDeclarationWhenPlatformSpecificOverloadAvailable() {
|
||||||
|
doTest(
|
||||||
|
"fun some() { <caret>mapOf(1 to 2, 3 to 4) }",
|
||||||
|
"Maps.kt"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ProjectDescriptorKind(JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES)
|
||||||
|
fun testNavigateToJVMSpecificationWithoutExpectActual() {
|
||||||
|
doTest(
|
||||||
|
"fun some() { <caret>mapOf(1 to 2) }",
|
||||||
|
"MapsJVM.kt"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getProjectDescriptor() = getProjectDescriptorFromAnnotation()
|
||||||
|
|
||||||
|
private fun doTest(text: String, sourceFileName: String) {
|
||||||
|
myFixture.configureByText(KotlinFileType.INSTANCE, text)
|
||||||
|
|
||||||
|
val ref = file.findReferenceAt(editor.caretModel.offset)
|
||||||
|
val resolve = ref!!.resolve()
|
||||||
|
val navigationElement = resolve!!.navigationElement
|
||||||
|
|
||||||
|
TestCase.assertEquals(sourceFileName, navigationElement.containingFile.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user