From 9feb82c2687f7399742fe31eb1a8e55a0076c13a Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 16 Sep 2015 03:27:11 +0300 Subject: [PATCH] Do not decompile old incompatible package parts Fix the test by reverting 282727b --- .../kotlin/idea/decompiler/DecompiledUtils.kt | 13 +++++++++---- .../DecompiledTextForWrongAbiVersionTest.kt | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/DecompiledUtils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/DecompiledUtils.kt index 1e6ce14cafb..e8b3f2867e9 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/DecompiledUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/DecompiledUtils.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.idea.decompiler import com.intellij.ide.highlighter.JavaClassFileType -import com.intellij.openapi.util.Key import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.ClassFileViewProvider import org.jetbrains.kotlin.idea.caches.JarUserDataManager @@ -28,7 +27,6 @@ import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name /** @@ -73,8 +71,15 @@ public fun isKotlinInternalCompiledFile(file: VirtualFile): Boolean { if (ClassFileViewProvider.isInnerClass(file)) { return true } - val header = KotlinBinaryClassCache.getKotlinBinaryClass(file)?.getClassHeader() ?: return false - return (header.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS && header.syntheticClassKind != KotlinSyntheticClass.Kind.PACKAGE_PART) || + val header = KotlinBinaryClassCache.getKotlinBinaryClass(file)?.classHeader ?: return false + + if (header.syntheticClassKind == KotlinSyntheticClass.Kind.PACKAGE_PART) { + // Old package parts should not be decompiled and shown anywhere + val version = header.version + return version.major < 0 || (version.major == 0 && version.minor < 24) + } + + return header.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS || (header.kind == KotlinClassHeader.Kind.CLASS && header.classKind != null && header.classKind != KotlinClass.Kind.CLASS) || (header.kind == KotlinClassHeader.Kind.MULTIFILE_CLASS_PART) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt index 99174b35600..a13d69e56aa 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt @@ -36,7 +36,7 @@ public class DecompiledTextForWrongAbiVersionTest : AbstractInternalCompiledClas return JetJdkAndLibraryProjectDescriptor(File(JetTestUtils.getTestDataPathBase() + "/cli/jvm/wrongAbiVersionLib/bin")) } - fun testPackagePartIsInvisibleWrongAbiVersion() = doTestNoFilesAreBuiltForSyntheticClass(PACKAGE_PART) + fun testPackagePartIsInvisibleWrongAbiVersion() = doTestNoPsiFilesAreBuiltForSyntheticClass(PACKAGE_PART) fun testTraitImplClassIsVisibleAsJavaClassWrongAbiVersion() = doTestTraitImplClassIsVisibleAsJavaClass()