Prevent KotlinDecompiledFileViewProvider from reading vfile when possible

This commit is contained in:
Simon Ogorodnik
2017-07-14 18:05:33 +03:00
parent bc5872dd8f
commit 6036c95511
2 changed files with 8 additions and 9 deletions
@@ -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
}
@@ -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)