From 6036c9551139fd41334b9611a02f8188c9aab088 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 14 Jul 2017 18:05:33 +0300 Subject: [PATCH] Prevent KotlinDecompiledFileViewProvider from reading vfile when possible --- .../idea/decompiler/classFile/ClassFileDecompilerUtil.kt | 9 +++++++-- .../decompiler/classFile/KotlinClassFileDecompiler.kt | 8 +------- 2 files changed, 8 insertions(+), 9 deletions(-) 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 cd44f794a92..79ff531d33b 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,12 +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, fileContent: ByteArray): Boolean { +fun isKotlinInternalCompiledFile(file: VirtualFile, fileContent: ByteArray? = null): Boolean { if (!IDEKotlinBinaryClassCache.isKotlinJvmCompiledFile(file, fileContent)) { return false } - val innerClass = ClassFileViewProvider.isInnerClass(file, fileContent) + val innerClass = + if (fileContent == null) + ClassFileViewProvider.isInnerClass(file) + else + ClassFileViewProvider.isInnerClass(file, fileContent) + if (innerClass) { return true } 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 745b4640b3f..d6dbd5e1a7a 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 @@ -52,14 +52,8 @@ class KotlinClassFileDecompiler : ClassFileDecompilers.Full() { val virtualFile = provider.virtualFile val fileIndex = ServiceManager.getService(project, FileIndexFacade::class.java) 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)) + if (isKotlinInternalCompiledFile(virtualFile)) null else KtClsFile(provider)