Fix and test built-ins decompiler for incompatible version
This commit is contained in:
committed by
Alexander Udalov
parent
440b23ddf6
commit
5f39f628c9
+1
-2
@@ -70,7 +70,6 @@ fun buildDecompiledTextForBuiltIns(builtInFile: VirtualFile): DecompiledText {
|
||||
val file = BuiltInDefinitionFile.read(builtInFile)
|
||||
when (file) {
|
||||
is BuiltInDefinitionFile.Incompatible -> {
|
||||
// TODO: test
|
||||
return createIncompatibleAbiVersionDecompiledText(BuiltInsBinaryVersion.INSTANCE, file.version)
|
||||
}
|
||||
is BuiltInDefinitionFile.Compatible -> {
|
||||
@@ -128,7 +127,7 @@ sealed class BuiltInDefinitionFile {
|
||||
|
||||
internal fun isInternalBuiltInFile(file: BuiltInDefinitionFile): Boolean {
|
||||
when (file) {
|
||||
is BuiltInDefinitionFile.Incompatible -> return true
|
||||
is BuiltInDefinitionFile.Incompatible -> return false
|
||||
is BuiltInDefinitionFile.Compatible -> {
|
||||
return file.classesToDecompile.isEmpty() &&
|
||||
file.proto.`package`.functionCount == 0 &&
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
PsiJetFileStubImpl[package=]
|
||||
PACKAGE_DIRECTIVE:
|
||||
IMPORT_LIST:
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This class file was compiled with different version of Kotlin compiler and can't be decompiled.
|
||||
//
|
||||
// Current compiler ABI version is $VERSION$
|
||||
// File ABI version is 0.42.239
|
||||
Binary file not shown.
+42
-10
@@ -16,30 +16,62 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.stubBuilder
|
||||
|
||||
import com.intellij.psi.stubs.PsiFileStub
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.util.indexing.FileContentImpl
|
||||
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
|
||||
import org.jetbrains.kotlin.builtins.BuiltInsBinaryVersion
|
||||
import org.jetbrains.kotlin.idea.decompiler.builtIns.KotlinBuiltInStubBuilder
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtFileStubBuilder
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractBuiltInDecompilerTest : LightCodeInsightFixtureTestCase() {
|
||||
protected fun doTest(packageFqName: String): String {
|
||||
val stubTreeFromDecompiler = configureAndBuildFileStub(packageFqName)
|
||||
val stubTreeFromDecompiledText = KtFileStubBuilder().buildStubTree(myFixture.file)
|
||||
val expectedText = stubTreeFromDecompiledText.serializeToString()
|
||||
Assert.assertEquals("Stub mismatch for package $packageFqName", expectedText, stubTreeFromDecompiler.serializeToString())
|
||||
return expectedText
|
||||
}
|
||||
|
||||
abstract fun configureAndBuildFileStub(packageFqName: String): PsiFileStub<*>
|
||||
|
||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
|
||||
class BuiltInDecompilerTest : AbstractBuiltInDecompilerTest() {
|
||||
override fun configureAndBuildFileStub(packageFqName: String): PsiFileStub<*> {
|
||||
val dirInRuntime = findDir(packageFqName, project)
|
||||
val kotlinBuiltInsVirtualFile = dirInRuntime.children.single { it.extension == BuiltInSerializerProtocol.BUILTINS_FILE_EXTENSION }
|
||||
myFixture.configureFromExistingVirtualFile(kotlinBuiltInsVirtualFile)
|
||||
return KotlinBuiltInStubBuilder().buildFileStub(FileContentImpl.createByFile(kotlinBuiltInsVirtualFile))!!
|
||||
}
|
||||
|
||||
class BuiltInDecompilerTest : LightCodeInsightFixtureTestCase() {
|
||||
fun testBuiltInStubTreeEqualToStubTreeFromDecompiledText() {
|
||||
doTest("kotlin")
|
||||
doTest("kotlin.collections")
|
||||
}
|
||||
}
|
||||
|
||||
private fun doTest(packageFqName: String) {
|
||||
val dirInRuntime = findDir(packageFqName, project)
|
||||
val kotlinBuiltInsVirtualFile = dirInRuntime.children.single { it.extension == BuiltInSerializerProtocol.BUILTINS_FILE_EXTENSION }
|
||||
val stubTreeFromDecompiler = KotlinBuiltInStubBuilder().buildFileStub(FileContentImpl.createByFile(kotlinBuiltInsVirtualFile))!!
|
||||
myFixture.configureFromExistingVirtualFile(kotlinBuiltInsVirtualFile)
|
||||
class BuiltInDecompilerForWrongAbiVersionTest : AbstractBuiltInDecompilerTest() {
|
||||
override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/decompiler/builtins/"
|
||||
|
||||
val stubTreeFromDecompiledText = KtFileStubBuilder().buildStubTree(myFixture.file)
|
||||
val expectedText = stubTreeFromDecompiledText.serializeToString()
|
||||
Assert.assertEquals("Stub mismatch for package $packageFqName", expectedText, stubTreeFromDecompiler.serializeToString())
|
||||
override fun configureAndBuildFileStub(packageFqName: String): PsiFileStub<*> {
|
||||
myFixture.configureByFile(testDataPath + BuiltInSerializerProtocol.getBuiltInsFilePath(FqName(packageFqName)))
|
||||
return KotlinBuiltInStubBuilder().buildFileStub(FileContentImpl.createByFile(myFixture.file.virtualFile))!!
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
fun testStubTreesEqualForIncompatibleAbiVersion() {
|
||||
val serializedStub = doTest("test")
|
||||
KotlinTestUtils.assertEqualsToFile(
|
||||
File(testDataPath + "test.text"),
|
||||
myFixture.file.text.replace(BuiltInsBinaryVersion.INSTANCE.toString(), "\$VERSION\$")
|
||||
)
|
||||
KotlinTestUtils.assertEqualsToFile(File(testDataPath + "test.stubs"), serializedStub)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user