Generate navigateToDecompiledLibraryTest from the same test data as navigateToLibrarySourceTest

Change test data format
This commit is contained in:
Pavel V. Talanov
2016-03-18 19:38:36 +03:00
parent f74e8ee7f8
commit 68c0bb9dc2
45 changed files with 287 additions and 111 deletions
@@ -68,6 +68,7 @@ import org.jetbrains.kotlin.idea.debugger.AbstractKotlinSteppingTest
import org.jetbrains.kotlin.idea.debugger.AbstractPositionManagerTest
import org.jetbrains.kotlin.idea.debugger.AbstractSmartStepIntoTest
import org.jetbrains.kotlin.idea.debugger.evaluate.*
import org.jetbrains.kotlin.idea.decompiler.navigation.AbstractNavigateToDecompiledLibraryTest
import org.jetbrains.kotlin.idea.decompiler.navigation.AbstractNavigateToLibrarySourceTest
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.AbstractClsStubBuilderTest
import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractCommonDecompiledTextFromJsMetadataTest
@@ -428,6 +429,10 @@ fun main(args: Array<String>) {
model("decompiler/navigation/usercode", testClassName ="UsercodeWithJSModule", testMethod = "doWithJSModuleTest")
}
testClass<AbstractNavigateToDecompiledLibraryTest>() {
model("decompiler/navigation/usercode")
}
testClass<AbstractKotlinGotoImplementationTest>() {
model("navigation/implementations", recursive = false)
}
@@ -0,0 +1,3 @@
WithInnerAndObject.class
public companion <1>object {
public final fun <2>foo(): kotlin.Unit { /* compiled code */ }
@@ -2,8 +2,4 @@ import testData.libraries.*
fun foo() {
WithInnerAndObject.foo()
}
// main.kt
// companion <1>object {
// fun <2>foo() {
}
@@ -0,0 +1,3 @@
main.kt
companion <1>object {
fun <2>foo() {
@@ -0,0 +1,3 @@
ClassWithConstructor.class
public final class <1><3>ClassWithConstructor public <2>constructor(a: kotlin.String, b: kotlin.Any) {
public <4>constructor(a: kotlin.String) { /* compiled code */ }
@@ -2,7 +2,3 @@ import testData.libraries.*
val x: ClassWithConstructor = ClassWithConstructor("abc", 239)
val xx: ClassWithConstructor = ClassWithConstructor("abc")
// main.kt
//public class <1><3>ClassWithConstructor<2>(val a: String, b: Any) {
// <4>constructor(a: String): this(a, a)
@@ -0,0 +1,3 @@
main.kt
public class <1><3>ClassWithConstructor<2>(val a: String, b: Any) {
<4>constructor(a: String): this(a, a)
@@ -0,0 +1,9 @@
Color.class
public final enum class <1><2>Color private constructor(rgb: kotlin.Int) : kotlin.Enum<testData.libraries.Color> {
<3>RED,
GREEN,
BLUE;
public final val <4>rgb: kotlin.Int /* compiled code */
+1 -5
View File
@@ -1,8 +1,4 @@
import testData.libraries.*
val color: Color? = Color.RED
val rgb = color?.rgb
// main.kt
//public enum class <1><2>Color(val <4>rgb : Int) {
// <3>RED(0xFF0000),
val rgb = color?.rgb
@@ -0,0 +1,3 @@
main.kt
public enum class <1><2>Color(val <4>rgb : Int) {
<3>RED(0xFF0000),
@@ -0,0 +1,2 @@
MainKt.class
public inline fun <T> T.<1>filter(predicate: (T) -> kotlin.Boolean): T? { /* compiled code */ }
@@ -1,7 +1,3 @@
import testData.libraries.*
val v = 5.filter { it % 2 == 1 }
// main.kt
//public inline fun <T> T.<1>filter(predicate: (T)-> Boolean) : T? = this
@@ -0,0 +1,2 @@
main.kt
public inline fun <T> T.<1>filter(predicate: (T)-> Boolean) : T? = this
@@ -0,0 +1,6 @@
MainKt.class
public val kotlin.String.<1>exProp: kotlin.String /* compiled code */
public val <T> testData.libraries.Pair<T, T>.<3>exProp: kotlin.String /* compiled code */
Pair.class
public final class Pair<A, B> public <2>constructor(first: A, second: B) {
@@ -4,19 +4,4 @@ fun foo() {
println("".exProp)
val p = Pair(1, 2)
println(p.exProp)
}
// main.kt
//public val String.<1>exProp : String
//get() {
// return this
//}
//
//public val Int.exProp : Int
//get() {
// return this
//}
//
//public class Pair<A, B><2>(val first: A, val second: B)
//
//public val <T> Pair<T, T>.<3>exProp : String
}
@@ -0,0 +1,14 @@
main.kt
public val String.<1>exProp : String
get() {
return this
}
public val Int.exProp : Int
get() {
return this
}
public class Pair<A, B><2>(val first: A, val second: B)
public val <T> Pair<T, T>.<3>exProp : String
@@ -0,0 +1,2 @@
MainKt.class
public fun <T> <1>genericFunc(): T { /* compiled code */ }
@@ -3,6 +3,3 @@ import testData.libraries.*
fun test() {
genericFunc<String>()
}
// main.kt
//public fun <T> <1>genericFunc() : T = throw Exception()
@@ -0,0 +1,2 @@
main.kt
public fun <T> <1>genericFunc() : T = throw Exception()
@@ -0,0 +1,2 @@
MainKt.class
public fun <T> <1>genericFunc(): T { /* compiled code */ }
@@ -3,7 +3,4 @@ import testData.libraries.*
fun test() {
val s : String = genericFunc()
}
// main.kt
//public fun <T> <1>genericFunc() : T = throw Exception()
}
@@ -0,0 +1,2 @@
main.kt
public fun <T> <1>genericFunc() : T = throw Exception()
@@ -0,0 +1,8 @@
MainKt.class
public fun <4>func(): kotlin.Unit { /* compiled code */ }
public fun func(cs: kotlin.CharSequence): kotlin.Unit { /* compiled code */ }
public fun <3>func(a: kotlin.Int, b: kotlin.Int): kotlin.Unit { /* compiled code */ }
public fun <1><2>func(a: kotlin.Int, b: kotlin.String /* = compiled code */): kotlin.Unit { /* compiled code */ }
@@ -6,12 +6,3 @@ fun foo() {
func(5, 5)
func()
}
// main.kt
//public fun <1><2>func(a : Int, b : String = "55") {
//}
//
//public fun <3>func(a : Int, b : Int) {
//}
//
//public fun <4>func() {
@@ -0,0 +1,8 @@
main.kt
public fun <1><2>func(a : Int, b : String = "55") {
}
public fun <3>func(a : Int, b : Int) {
}
public fun <4>func() {
@@ -0,0 +1,4 @@
MainKt.class
public val <1>globalVal: testData.libraries.Pair<kotlin.Int, kotlin.String> /* compiled code */
public val <2>globalValWithGetter: kotlin.Long /* compiled code */
@@ -4,8 +4,3 @@ fun foo() {
println(testData.libraries.globalVal)
println(globalValWithGetter)
}
// main.kt
//public val <1>globalVal : Pair<Int, String> = Pair(239, "239")
//
//public val <2>globalValWithGetter : Long
@@ -0,0 +1,4 @@
main.kt
public val <1>globalVal : Pair<Int, String> = Pair(239, "239")
public val <2>globalValWithGetter : Long
@@ -0,0 +1,3 @@
NamedObject.class
public object <1>NamedObject {
public final val <2>objectMember: kotlin.Int /* compiled code */
@@ -1,7 +1,3 @@
import testData.libraries.*
val x = NamedObject.objectMember
// main.kt
//public object <1>NamedObject {
// public val <2>objectMember: Int = 1
@@ -0,0 +1,3 @@
main.kt
public object <1>NamedObject {
public val <2>objectMember: Int = 1
@@ -0,0 +1,4 @@
MainKt.class
public fun <T : kotlin.CharSequence> <2>funWithTypeParam(t: T): kotlin.Unit { /* compiled code */ }
public fun <T : kotlin.Number> <1>funWithTypeParam(t: T): kotlin.Unit { /* compiled code */ }
@@ -4,9 +4,3 @@ fun main(args: Array<String>) {
funWithTypeParam(1)
funWithTypeParam("")
}
// main.kt
//public fun <T: CharSequence> <2>funWithTypeParam(t: T) {
//}
//
//public fun <T: Number> <1>funWithTypeParam(t: T) {
@@ -0,0 +1,5 @@
main.kt
public fun <T: CharSequence> <2>funWithTypeParam(t: T) {
}
public fun <T: Number> <1>funWithTypeParam(t: T) {
@@ -0,0 +1,5 @@
ClassWithAbstractAndOpenMembers.class
public abstract class <1>ClassWithAbstractAndOpenMembers public constructor() {
public abstract val abstractVal: kotlin.String
public abstract var <2><3>abstractVar: kotlin.String
@@ -5,18 +5,3 @@ fun foo(a : ClassWithAbstractAndOpenMembers) {
println(a.abstractVar)
}
// main.kt
//public abstract class <1>ClassWithAbstractAndOpenMembers {
// public abstract fun abstractFun()
// public open fun openFun() {
// }
//
// public abstract val abstractVal : String
// public open val openVal : String = ""
// public open val openValWithGetter : String
// get() {
// return "239"
// }
//
// public abstract var <2><3>abstractVar : String
@@ -0,0 +1,14 @@
main.kt
public abstract class <1>ClassWithAbstractAndOpenMembers {
public abstract fun abstractFun()
public open fun openFun() {
}
public abstract val abstractVal : String
public open val openVal : String = ""
public open val openValWithGetter : String
get() {
return "239"
}
public abstract var <2><3>abstractVar : String
@@ -0,0 +1,4 @@
ExtraKt.class
public fun <1>func(str: kotlin.String): kotlin.Unit { /* compiled code */ }
MainKt.class
public fun <2>func(a: kotlin.Int, b: kotlin.String /* = compiled code */): kotlin.Unit { /* compiled code */ }
@@ -4,8 +4,3 @@ fun foo() {
func("5")
func(5)
}
// extra.kt
//public fun <1>func(str : kotlin.String) {
// main.kt
//public fun <2>func(a : Int, b : String = "55") {
@@ -0,0 +1,4 @@
extra.kt
public fun <1>func(str : kotlin.String) {
main.kt
public fun <2>func(a : Int, b : String = "55") {
@@ -0,0 +1,6 @@
Double.class
public final class Double public <3>constructor() {
MainKt.class
public fun <1>processDouble(d: kotlin.Double): kotlin.Unit { /* compiled code */ }
public fun <2>processDouble(d: testData.libraries.Double): kotlin.Unit { /* compiled code */ }
@@ -4,10 +4,3 @@ fun foo() {
processDouble(1.0);
processDouble(testData.libraries.Double())
}
// main.kt
//public class <3>Double
//
//public fun <2>processDouble(d: Double) {}
//
//public fun <1>processDouble(d: kotlin.Double) {}
@@ -0,0 +1,6 @@
main.kt
public class <3>Double
public fun <2>processDouble(d: Double) {}
public fun <1>processDouble(d: kotlin.Double) {}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -16,20 +16,18 @@
package org.jetbrains.kotlin.idea.decompiler.navigation
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.psi.PsiElement
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.UsefulTestCase
import junit.framework.TestCase
import org.jetbrains.kotlin.idea.navigation.NavigationTestUtils
import org.jetbrains.kotlin.idea.references.KtReference
import org.jetbrains.kotlin.idea.test.*
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
import java.util.LinkedHashMap
import java.util.*
abstract class AbstractNavigateToLibrarySourceTest : KotlinCodeInsightTestCase() {
abstract class AbstractNavigateToLibraryTest : KotlinCodeInsightTestCase() {
protected fun doTest(path: String): Unit = doTestEx(path)
@@ -38,6 +36,9 @@ abstract class AbstractNavigateToLibrarySourceTest : KotlinCodeInsightTestCase()
jsModule.configureAs(ModuleKind.KOTLIN_JAVASCRIPT)
}
abstract val withSource: Boolean
abstract val expectedFileExt: String
protected fun doTestEx(path: String, additionalConfig: (() -> Unit)? = null) {
configureByFile(path)
module.configureAs(getProjectDescriptor())
@@ -46,8 +47,8 @@ abstract class AbstractNavigateToLibrarySourceTest : KotlinCodeInsightTestCase()
additionalConfig()
}
checkAnnotatedLibraryCode(false)
checkAnnotatedLibraryCode(true)
checkAnnotatedLibraryCode(path, false)
checkAnnotatedLibraryCode(path, true)
}
override fun tearDown() {
@@ -58,11 +59,10 @@ abstract class AbstractNavigateToLibrarySourceTest : KotlinCodeInsightTestCase()
override fun getTestDataPath(): String =
KotlinTestUtils.getHomeDirectory() + File.separator
private fun checkAnnotatedLibraryCode(forceResolve: Boolean) {
private fun checkAnnotatedLibraryCode(path: String, forceResolve: Boolean) {
SourceNavigationHelper.setForceResolve(forceResolve)
val actualCode = NavigationTestUtils.getNavigateElementsText(project, collectInterestingNavigationElements())
val expectedCode = getExpectedAnnotatedLibraryCode()
UsefulTestCase.assertSameLines(expectedCode, actualCode)
KotlinTestUtils.assertEqualsToFile(File(path.replace(".kt", expectedFileExt)), actualCode)
}
private fun collectInterestingReferences(): Collection<KtReference> {
@@ -89,7 +89,7 @@ abstract class AbstractNavigateToLibrarySourceTest : KotlinCodeInsightTestCase()
val targetNavFile = targetNavPsiFile.virtualFile ?: return
if (ProjectFileIndex.SERVICE.getInstance(project).isInLibrarySource(targetNavFile)) {
if (!ProjectRootsUtil.isProjectSourceFile(project, targetNavFile)) {
put(ref.element, ref)
}
}
@@ -101,12 +101,16 @@ abstract class AbstractNavigateToLibrarySourceTest : KotlinCodeInsightTestCase()
target!!.navigationElement
}
private fun getExpectedAnnotatedLibraryCode(): String {
val document = getDocument(file)
TestCase.assertNotNull(document)
return KotlinTestUtils.getLastCommentedLines(document)
}
open fun getProjectDescriptor(): KotlinLightProjectDescriptor =
JdkAndMockLibraryProjectDescriptor(PluginTestCaseBase.getTestDataPathBase() + "/decompiler/navigation/library", withSource)
}
private fun getProjectDescriptor(): KotlinLightProjectDescriptor =
JdkAndMockLibraryProjectDescriptor(PluginTestCaseBase.getTestDataPathBase() + "/decompiler/navigation/library", true)
abstract class AbstractNavigateToDecompiledLibraryTest : AbstractNavigateToLibraryTest() {
override val withSource: Boolean get() = false
override val expectedFileExt: String get() = ".decompiled.expected"
}
abstract class AbstractNavigateToLibrarySourceTest : AbstractNavigateToLibraryTest() {
override val withSource: Boolean get() = true
override val expectedFileExt: String get() = ".source.expected"
}
@@ -0,0 +1,121 @@
/*
* Copyright 2010-2016 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.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/decompiler/navigation/usercode")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class NavigateToDecompiledLibraryTestGenerated extends AbstractNavigateToDecompiledLibraryTest {
public void testAllFilesPresentInUsercode() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/decompiler/navigation/usercode"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("ClassObject.kt")
public void testClassObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/ClassObject.kt");
doTest(fileName);
}
@TestMetadata("Constructor.kt")
public void testConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/Constructor.kt");
doTest(fileName);
}
@TestMetadata("Enum.kt")
public void testEnum() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/Enum.kt");
doTest(fileName);
}
@TestMetadata("ExtensionFunction.kt")
public void testExtensionFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/ExtensionFunction.kt");
doTest(fileName);
}
@TestMetadata("ExtensionProperty.kt")
public void testExtensionProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/ExtensionProperty.kt");
doTest(fileName);
}
@TestMetadata("GenericFunctionWithExplicitlyDeclaredTypeArguments.kt")
public void testGenericFunctionWithExplicitlyDeclaredTypeArguments() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/GenericFunctionWithExplicitlyDeclaredTypeArguments.kt");
doTest(fileName);
}
@TestMetadata("GenericFunctionWithInferredTypeArguments.kt")
public void testGenericFunctionWithInferredTypeArguments() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/GenericFunctionWithInferredTypeArguments.kt");
doTest(fileName);
}
@TestMetadata("GlobalFunction.kt")
public void testGlobalFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/GlobalFunction.kt");
doTest(fileName);
}
@TestMetadata("GlobalProperty.kt")
public void testGlobalProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/GlobalProperty.kt");
doTest(fileName);
}
@TestMetadata("NamedObject.kt")
public void testNamedObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/NamedObject.kt");
doTest(fileName);
}
@TestMetadata("OverloadedFunWithTypeParam.kt")
public void testOverloadedFunWithTypeParam() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/OverloadedFunWithTypeParam.kt");
doTest(fileName);
}
@TestMetadata("Property.kt")
public void testProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/Property.kt");
doTest(fileName);
}
@TestMetadata("SameNameInDifferentSources.kt")
public void testSameNameInDifferentSources() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/SameNameInDifferentSources.kt");
doTest(fileName);
}
@TestMetadata("TypeWithSameShortName.kt")
public void testTypeWithSameShortName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/TypeWithSameShortName.kt");
doTest(fileName);
}
}