Minor, extract createIncompatibleAbiVersionDecompiledText to common/
This commit is contained in:
committed by
Alexander Udalov
parent
f82ec6711d
commit
440b23ddf6
+2
-9
@@ -27,9 +27,7 @@ import org.jetbrains.kotlin.builtins.BuiltInsBinaryVersion
|
|||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider
|
import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider
|
||||||
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
|
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
|
||||||
import org.jetbrains.kotlin.idea.decompiler.classFile.CURRENT_ABI_VERSION_MARKER
|
import org.jetbrains.kotlin.idea.decompiler.common.createIncompatibleAbiVersionDecompiledText
|
||||||
import org.jetbrains.kotlin.idea.decompiler.classFile.FILE_ABI_VERSION_MARKER
|
|
||||||
import org.jetbrains.kotlin.idea.decompiler.classFile.INCOMPATIBLE_ABI_VERSION_COMMENT
|
|
||||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText
|
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText
|
||||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledText
|
import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledText
|
||||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.defaultDecompilerRendererOptions
|
import org.jetbrains.kotlin.idea.decompiler.textBuilder.defaultDecompilerRendererOptions
|
||||||
@@ -73,12 +71,7 @@ fun buildDecompiledTextForBuiltIns(builtInFile: VirtualFile): DecompiledText {
|
|||||||
when (file) {
|
when (file) {
|
||||||
is BuiltInDefinitionFile.Incompatible -> {
|
is BuiltInDefinitionFile.Incompatible -> {
|
||||||
// TODO: test
|
// TODO: test
|
||||||
return DecompiledText(
|
return createIncompatibleAbiVersionDecompiledText(BuiltInsBinaryVersion.INSTANCE, file.version)
|
||||||
INCOMPATIBLE_ABI_VERSION_COMMENT
|
|
||||||
.replace(CURRENT_ABI_VERSION_MARKER, BuiltInsBinaryVersion.INSTANCE.toString())
|
|
||||||
.replace(FILE_ABI_VERSION_MARKER, file.version.toString()),
|
|
||||||
mapOf()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
is BuiltInDefinitionFile.Compatible -> {
|
is BuiltInDefinitionFile.Compatible -> {
|
||||||
val packageFqName = file.packageFqName
|
val packageFqName = file.packageFqName
|
||||||
|
|||||||
+2
-16
@@ -24,6 +24,7 @@ import com.intellij.psi.compiled.ClassFileDecompilers
|
|||||||
import org.jetbrains.kotlin.idea.caches.IDEKotlinBinaryClassCache
|
import org.jetbrains.kotlin.idea.caches.IDEKotlinBinaryClassCache
|
||||||
import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider
|
import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider
|
||||||
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
|
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
|
||||||
|
import org.jetbrains.kotlin.idea.decompiler.common.createIncompatibleAbiVersionDecompiledText
|
||||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText
|
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText
|
||||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.ResolverForDecompiler
|
import org.jetbrains.kotlin.idea.decompiler.textBuilder.ResolverForDecompiler
|
||||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledText
|
import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledText
|
||||||
@@ -63,16 +64,6 @@ private val decompilerRendererForClassFiles = DescriptorRenderer.withOptions {
|
|||||||
typeNormalizer = { type -> if (type.isFlexible()) type.flexibility().lowerBound else type }
|
typeNormalizer = { type -> if (type.isFlexible()) type.flexibility().lowerBound else type }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val FILE_ABI_VERSION_MARKER: String = "FILE_ABI"
|
|
||||||
internal val CURRENT_ABI_VERSION_MARKER: String = "CURRENT_ABI"
|
|
||||||
|
|
||||||
val INCOMPATIBLE_ABI_VERSION_GENERAL_COMMENT: String = "// This class file was compiled with different version of Kotlin compiler and can't be decompiled."
|
|
||||||
val INCOMPATIBLE_ABI_VERSION_COMMENT: String =
|
|
||||||
"$INCOMPATIBLE_ABI_VERSION_GENERAL_COMMENT\n" +
|
|
||||||
"//\n" +
|
|
||||||
"// Current compiler ABI version is $CURRENT_ABI_VERSION_MARKER\n" +
|
|
||||||
"// File ABI version is $FILE_ABI_VERSION_MARKER"
|
|
||||||
|
|
||||||
fun buildDecompiledTextForClassFile(
|
fun buildDecompiledTextForClassFile(
|
||||||
classFile: VirtualFile,
|
classFile: VirtualFile,
|
||||||
resolver: ResolverForDecompiler = DeserializerForClassfileDecompiler(classFile)
|
resolver: ResolverForDecompiler = DeserializerForClassfileDecompiler(classFile)
|
||||||
@@ -81,12 +72,7 @@ fun buildDecompiledTextForClassFile(
|
|||||||
?: error("Decompiled data factory shouldn't be called on an unsupported file: " + classFile)
|
?: error("Decompiled data factory shouldn't be called on an unsupported file: " + classFile)
|
||||||
|
|
||||||
if (!classHeader.metadataVersion.isCompatible()) {
|
if (!classHeader.metadataVersion.isCompatible()) {
|
||||||
return DecompiledText(
|
return createIncompatibleAbiVersionDecompiledText(JvmMetadataVersion.INSTANCE, classHeader.metadataVersion)
|
||||||
INCOMPATIBLE_ABI_VERSION_COMMENT
|
|
||||||
.replace(CURRENT_ABI_VERSION_MARKER, JvmMetadataVersion.INSTANCE.toString())
|
|
||||||
.replace(FILE_ABI_VERSION_MARKER, classHeader.metadataVersion.toString()),
|
|
||||||
mapOf()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return when (classHeader.kind) {
|
return when (classHeader.kind) {
|
||||||
|
|||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.common
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText
|
||||||
|
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
||||||
|
|
||||||
|
private val FILE_ABI_VERSION_MARKER: String = "FILE_ABI"
|
||||||
|
private val CURRENT_ABI_VERSION_MARKER: String = "CURRENT_ABI"
|
||||||
|
|
||||||
|
val INCOMPATIBLE_ABI_VERSION_GENERAL_COMMENT: String = "// This class file was compiled with different version of Kotlin compiler and can't be decompiled."
|
||||||
|
private val INCOMPATIBLE_ABI_VERSION_COMMENT: String =
|
||||||
|
"$INCOMPATIBLE_ABI_VERSION_GENERAL_COMMENT\n" +
|
||||||
|
"//\n" +
|
||||||
|
"// Current compiler ABI version is $CURRENT_ABI_VERSION_MARKER\n" +
|
||||||
|
"// File ABI version is $FILE_ABI_VERSION_MARKER"
|
||||||
|
|
||||||
|
fun <V : BinaryVersion> createIncompatibleAbiVersionDecompiledText(expectedVersion: V, actualVersion: V): DecompiledText {
|
||||||
|
return DecompiledText(
|
||||||
|
INCOMPATIBLE_ABI_VERSION_COMMENT
|
||||||
|
.replace(CURRENT_ABI_VERSION_MARKER, expectedVersion.toString())
|
||||||
|
.replace(FILE_ABI_VERSION_MARKER, actualVersion.toString()),
|
||||||
|
mapOf()
|
||||||
|
)
|
||||||
|
}
|
||||||
+2
-2
@@ -20,8 +20,8 @@ import com.intellij.openapi.vfs.VirtualFile
|
|||||||
import com.intellij.psi.PsiManager
|
import com.intellij.psi.PsiManager
|
||||||
import com.intellij.testFramework.LightProjectDescriptor
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.decompiler.AbstractInternalCompiledClassesTest
|
import org.jetbrains.kotlin.idea.decompiler.AbstractInternalCompiledClassesTest
|
||||||
import org.jetbrains.kotlin.idea.decompiler.classFile.INCOMPATIBLE_ABI_VERSION_GENERAL_COMMENT
|
|
||||||
import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile
|
import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile
|
||||||
|
import org.jetbrains.kotlin.idea.decompiler.common.INCOMPATIBLE_ABI_VERSION_GENERAL_COMMENT
|
||||||
import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest
|
import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest
|
||||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.findClassFileByName
|
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.findClassFileByName
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor
|
||||||
@@ -47,7 +47,7 @@ class DecompiledTextForWrongAbiVersionTest : AbstractInternalCompiledClassesTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkFileWithWrongAbiVersion(file: VirtualFile) {
|
private fun checkFileWithWrongAbiVersion(file: VirtualFile) {
|
||||||
val psiFile = PsiManager.getInstance(project!!).findFile(file)
|
val psiFile = PsiManager.getInstance(project).findFile(file)
|
||||||
Assert.assertTrue(psiFile is KtClsFile)
|
Assert.assertTrue(psiFile is KtClsFile)
|
||||||
val decompiledText = psiFile!!.text!!
|
val decompiledText = psiFile!!.text!!
|
||||||
Assert.assertTrue(decompiledText.contains(INCOMPATIBLE_ABI_VERSION_GENERAL_COMMENT))
|
Assert.assertTrue(decompiledText.contains(INCOMPATIBLE_ABI_VERSION_GENERAL_COMMENT))
|
||||||
|
|||||||
Reference in New Issue
Block a user