diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/IDEKotlinBinaryClassCache.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/IDEKotlinBinaryClassCache.kt index 9a0f3133a60..8dd1edfdd54 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/IDEKotlinBinaryClassCache.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/IDEKotlinBinaryClassCache.kt @@ -32,7 +32,7 @@ object IDEKotlinBinaryClassCache { /** * Checks if this file is a compiled Kotlin class file (not necessarily ABI-compatible with the current plugin) */ - fun isKotlinJvmCompiledFile(file: VirtualFile): Boolean { + fun isKotlinJvmCompiledFile(file: VirtualFile, fileContent: ByteArray? = null): Boolean { if (file.extension != JavaClassFileType.INSTANCE!!.defaultExtension) { return false } @@ -41,7 +41,7 @@ object IDEKotlinBinaryClassCache { if (cached != null) { return cached.isKotlinBinary } - return getKotlinBinaryClass(file) != null + return getKotlinBinaryClass(file, fileContent) != null } fun getKotlinBinaryClass(file: VirtualFile, fileContent: ByteArray? = null): KotlinJvmBinaryClass? { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/ClassFileDecompilerUtil.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/ClassFileDecompilerUtil.kt index 18e3ff93eef..cd44f794a92 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/ClassFileDecompilerUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/ClassFileDecompilerUtil.kt @@ -49,16 +49,17 @@ fun isKotlinWithCompatibleAbiVersion(file: VirtualFile): Boolean { * Checks if this file is a compiled "internal" Kotlin class, i.e. a Kotlin class (not necessarily ABI-compatible with the current plugin) * which should NOT be decompiled (and, as a result, shown under the library in the Project view, be searchable via Find class, etc.) */ -fun isKotlinInternalCompiledFile(file: VirtualFile): Boolean { - if (!IDEKotlinBinaryClassCache.isKotlinJvmCompiledFile(file)) { +fun isKotlinInternalCompiledFile(file: VirtualFile, fileContent: ByteArray): Boolean { + if (!IDEKotlinBinaryClassCache.isKotlinJvmCompiledFile(file, fileContent)) { return false } - if (ClassFileViewProvider.isInnerClass(file)) { + val innerClass = ClassFileViewProvider.isInnerClass(file, fileContent) + if (innerClass) { return true } - val (header, classId) = IDEKotlinBinaryClassCache.getKotlinBinaryClassHeaderData(file) ?: return false + val (header, classId) = IDEKotlinBinaryClassCache.getKotlinBinaryClassHeaderData(file, fileContent) ?: return false if (classId.isLocal) return true return header.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS || diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt index 8908e1ecbe8..745b4640b3f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.types.asFlexibleType import org.jetbrains.kotlin.types.isFlexible +import java.io.IOException class KotlinClassFileDecompiler : ClassFileDecompilers.Full() { private val stubBuilder = KotlinClsStubBuilder() @@ -47,14 +48,21 @@ class KotlinClassFileDecompiler : ClassFileDecompilers.Full() { override fun createFileViewProvider(file: VirtualFile, manager: PsiManager, physical: Boolean): KotlinDecompiledFileViewProvider { val project = manager.project - return KotlinDecompiledFileViewProvider(manager, file, physical) { provider -> + return KotlinDecompiledFileViewProvider(manager, file, physical) factory@{ provider -> val virtualFile = provider.virtualFile val fileIndex = ServiceManager.getService(project, FileIndexFacade::class.java) - when { - !fileIndex.isInLibraryClasses(virtualFile) && fileIndex.isInSource(virtualFile) -> null - isKotlinInternalCompiledFile(virtualFile) -> null - else -> KtClsFile(provider) + if (!fileIndex.isInLibraryClasses(virtualFile) && fileIndex.isInSource(virtualFile)) return@factory null + val content = try { + virtualFile.contentsToByteArray(false) } + catch (e: IOException) { + return@factory null + } + + if (isKotlinInternalCompiledFile(virtualFile, content)) + null + else + KtClsFile(provider) } } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClsStubBuilder.kt index 025c979c368..812a09d87fb 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClsStubBuilder.kt @@ -44,7 +44,7 @@ open class KotlinClsStubBuilder : ClsStubBuilder() { override fun buildFileStub(content: FileContent): PsiFileStub<*>? { val file = content.file - if (isKotlinInternalCompiledFile(file)) { + if (isKotlinInternalCompiledFile(file, content.content)) { return null }