Test navigation from source when same jar is in different libraries
One library can have sources attached and the other doesn't #KT-15093 In progress
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
lib.kt
|
||||
fun <1>foo() {}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package library
|
||||
|
||||
fun foo() {}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package m1
|
||||
|
||||
public fun use() {
|
||||
library.foo()
|
||||
}
|
||||
+45
-21
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.LibraryInfo
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.LibrarySourceInfo
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getNullableModuleInfo
|
||||
import org.jetbrains.kotlin.idea.decompiler.navigation.NavigationChecker.Companion.checkAnnotatedCode
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.getModuleDir
|
||||
import org.jetbrains.kotlin.test.MockLibraryUtil
|
||||
@@ -40,7 +41,7 @@ import org.jetbrains.kotlin.test.util.projectLibrary
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
|
||||
class NavigationWithMultipleCustomLibrariesTest : AbstractNavigationWithMultipleLibrariesTest() {
|
||||
class NavigationWithMultipleCustomLibrariesTest : AbstractNavigationToSourceOrDecompiledTest() {
|
||||
|
||||
override val testDataPath = PluginTestCaseBase.getTestDataPathBase() + "/decompiler/navigationMultipleLibs/"
|
||||
|
||||
@@ -61,7 +62,7 @@ class NavigationWithMultipleCustomLibrariesTest : AbstractNavigationWithMultiple
|
||||
}
|
||||
}
|
||||
|
||||
class NavigationWithMultipleRuntimesTest : AbstractNavigationWithMultipleLibrariesTest() {
|
||||
class NavigationWithMultipleRuntimesTest : AbstractNavigationToSourceOrDecompiledTest() {
|
||||
|
||||
override val testDataPath = PluginTestCaseBase.getTestDataPathBase() + "/decompiler/navigationMultipleRuntimes/"
|
||||
|
||||
@@ -90,10 +91,7 @@ class NavigationWithMultipleRuntimesTest : AbstractNavigationWithMultipleLibrari
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractNavigationWithMultipleLibrariesTest : ModuleTestCase() {
|
||||
|
||||
abstract val testDataPath: String
|
||||
|
||||
abstract class AbstractNavigationToSourceOrDecompiledTest: AbstractNavigationWithMultipleLibrariesTest() {
|
||||
fun doTest(withSources: Boolean, expectedFileName: String) {
|
||||
val srcPath = testDataPath + "src"
|
||||
val moduleA = module("moduleA", srcPath)
|
||||
@@ -109,24 +107,44 @@ abstract class AbstractNavigationWithMultipleLibrariesTest : ModuleTestCase() {
|
||||
checkReferencesInModule(moduleB, "libB", expectedFileName)
|
||||
}
|
||||
|
||||
private fun module(name: String, srcPath: String) = createModuleFromTestData(srcPath, name, StdModuleTypes.JAVA, true)!!
|
||||
|
||||
private fun checkReferencesInModule(module: Module, libraryName: String, expectedFileName: String) {
|
||||
NavigationChecker.checkAnnotatedCode(findSourceFile(module), File(testDataPath + expectedFileName)) {
|
||||
checkLibraryName(it, libraryName)
|
||||
}
|
||||
}
|
||||
|
||||
private fun findSourceFile(module: Module): PsiFile {
|
||||
val ioFile = File(module.getModuleDir()).listFiles().first()
|
||||
val vFile = LocalFileSystem.getInstance().findFileByIoFile(ioFile)!!
|
||||
return PsiManager.getInstance(project).findFile(vFile)!!
|
||||
}
|
||||
|
||||
|
||||
abstract fun createProjectLib(libraryName: String, withSources: Boolean): Library
|
||||
}
|
||||
|
||||
class NavigationToSingleJarInMultipleLibrariesTest : AbstractNavigationWithMultipleLibrariesTest() {
|
||||
|
||||
override val testDataPath = "${PluginTestCaseBase.getTestDataPathBase()}/multiModuleReferenceResolve/sameJarInDifferentLibraries/"
|
||||
|
||||
fun testNavigatingToLibrarySharingSameJarOnlyOneHasSourcesAttached() {
|
||||
val srcPath = testDataPath + "src"
|
||||
val moduleA = module("m1", srcPath)
|
||||
val moduleB = module("m2", srcPath)
|
||||
val moduleC = module("m3", srcPath)
|
||||
|
||||
val sharedJar = MockLibraryUtil.compileLibraryToJar(testDataPath + "libSrc", "sharedJar", true, false, false)
|
||||
val jarRoot = sharedJar.jarRoot
|
||||
|
||||
moduleA.addDependency(projectLibrary("libA", jarRoot))
|
||||
moduleB.addDependency(projectLibrary("libB", jarRoot, jarRoot.findChild("src")!!))
|
||||
moduleC.addDependency(projectLibrary("libC", jarRoot))
|
||||
|
||||
val expectedFile = File(testDataPath + "expected.sources")
|
||||
checkAnnotatedCode(findSourceFile(moduleA), expectedFile)
|
||||
checkAnnotatedCode(findSourceFile(moduleB), expectedFile)
|
||||
checkAnnotatedCode(findSourceFile(moduleC), expectedFile)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractNavigationWithMultipleLibrariesTest : ModuleTestCase() {
|
||||
abstract val testDataPath: String
|
||||
|
||||
protected fun module(name: String, srcPath: String) = createModuleFromTestData(srcPath, name, StdModuleTypes.JAVA, true)!!
|
||||
|
||||
protected fun checkReferencesInModule(module: Module, libraryName: String, expectedFileName: String) {
|
||||
checkAnnotatedCode(findSourceFile(module), File(testDataPath + expectedFileName)) {
|
||||
checkLibraryName(it, libraryName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkLibraryName(referenceTarget: PsiElement, expectedName: String) {
|
||||
val navigationFile = referenceTarget.navigationElement.containingFile ?: return
|
||||
@@ -138,3 +156,9 @@ private fun checkLibraryName(referenceTarget: PsiElement, expectedName: String)
|
||||
}
|
||||
Assert.assertEquals("Referenced code from unrelated library: ${referenceTarget.text}", expectedName, libraryName)
|
||||
}
|
||||
|
||||
private fun findSourceFile(module: Module): PsiFile {
|
||||
val ioFile = File(module.getModuleDir()).listFiles().first()
|
||||
val vFile = LocalFileSystem.getInstance().findFileByIoFile(ioFile)!!
|
||||
return PsiManager.getInstance(module.project).findFile(vFile)!!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user