Don't read file content to see if file is Kotlin-compiled if we have cached attribute but don't have complete data
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.caches
|
package org.jetbrains.kotlin.idea.caches
|
||||||
|
|
||||||
|
import com.intellij.ide.highlighter.JavaClassFileType
|
||||||
import com.intellij.openapi.components.ServiceManager
|
import com.intellij.openapi.components.ServiceManager
|
||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
@@ -28,6 +29,21 @@ object IDEKotlinBinaryClassCache {
|
|||||||
data class KotlinBinaryHeaderData(val classHeader: KotlinClassHeader, val classId: ClassId)
|
data class KotlinBinaryHeaderData(val classHeader: KotlinClassHeader, val classId: ClassId)
|
||||||
data class KotlinBinaryData(val isKotlinBinary: Boolean, val timestamp: Long, val headerData: KotlinBinaryHeaderData?)
|
data class KotlinBinaryData(val isKotlinBinary: Boolean, val timestamp: Long, val headerData: KotlinBinaryHeaderData?)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this file is a compiled Kotlin class file (not necessarily ABI-compatible with the current plugin)
|
||||||
|
*/
|
||||||
|
fun isKotlinJvmCompiledFile(file: VirtualFile): Boolean {
|
||||||
|
if (file.extension != JavaClassFileType.INSTANCE!!.defaultExtension) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val cached = getKotlinBinaryFromCache(file)
|
||||||
|
if (cached != null) {
|
||||||
|
return cached.isKotlinBinary
|
||||||
|
}
|
||||||
|
return getKotlinBinaryClass(file) != null
|
||||||
|
}
|
||||||
|
|
||||||
fun getKotlinBinaryClass(file: VirtualFile, fileContent: ByteArray? = null): KotlinJvmBinaryClass? {
|
fun getKotlinBinaryClass(file: VirtualFile, fileContent: ByteArray? = null): KotlinJvmBinaryClass? {
|
||||||
val cached = getKotlinBinaryFromCache(file)
|
val cached = getKotlinBinaryFromCache(file)
|
||||||
if (cached != null && !cached.isKotlinBinary) {
|
if (cached != null && !cached.isKotlinBinary) {
|
||||||
|
|||||||
+2
-14
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.decompiler.classFile
|
package org.jetbrains.kotlin.idea.decompiler.classFile
|
||||||
|
|
||||||
import com.intellij.ide.highlighter.JavaClassFileType
|
|
||||||
import com.intellij.openapi.components.ServiceManager
|
import com.intellij.openapi.components.ServiceManager
|
||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
@@ -36,22 +35,11 @@ val KOTLIN_COMPILED_FILE_ATTRIBUTE: String = "kotlin-compiled-file".apply {
|
|||||||
|
|
||||||
val KEY = Key.create<IsKotlinBinary>(KOTLIN_COMPILED_FILE_ATTRIBUTE)
|
val KEY = Key.create<IsKotlinBinary>(KOTLIN_COMPILED_FILE_ATTRIBUTE)
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this file is a compiled Kotlin class file (not necessarily ABI-compatible with the current plugin)
|
|
||||||
*/
|
|
||||||
fun isKotlinJvmCompiledFile(file: VirtualFile): Boolean {
|
|
||||||
if (file.extension != JavaClassFileType.INSTANCE!!.defaultExtension) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return IDEKotlinBinaryClassCache.getKotlinBinaryClassHeaderData(file) != null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this file is a compiled Kotlin class file ABI-compatible with the current plugin
|
* Checks if this file is a compiled Kotlin class file ABI-compatible with the current plugin
|
||||||
*/
|
*/
|
||||||
fun isKotlinWithCompatibleAbiVersion(file: VirtualFile): Boolean {
|
fun isKotlinWithCompatibleAbiVersion(file: VirtualFile): Boolean {
|
||||||
if (!isKotlinJvmCompiledFile(file)) return false
|
if (!IDEKotlinBinaryClassCache.isKotlinJvmCompiledFile(file)) return false
|
||||||
|
|
||||||
val kotlinClass = IDEKotlinBinaryClassCache.getKotlinBinaryClassHeaderData(file)
|
val kotlinClass = IDEKotlinBinaryClassCache.getKotlinBinaryClassHeaderData(file)
|
||||||
return kotlinClass != null && kotlinClass.classHeader.metadataVersion.isCompatible()
|
return kotlinClass != null && kotlinClass.classHeader.metadataVersion.isCompatible()
|
||||||
@@ -62,7 +50,7 @@ fun isKotlinWithCompatibleAbiVersion(file: VirtualFile): Boolean {
|
|||||||
* which should NOT be decompiled (and, as a result, shown under the library in the Project view, be searchable via Find class, etc.)
|
* 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 {
|
fun isKotlinInternalCompiledFile(file: VirtualFile): Boolean {
|
||||||
if (!isKotlinJvmCompiledFile(file)) {
|
if (!IDEKotlinBinaryClassCache.isKotlinJvmCompiledFile(file)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ import org.jetbrains.kotlin.types.isFlexible
|
|||||||
class KotlinClassFileDecompiler : ClassFileDecompilers.Full() {
|
class KotlinClassFileDecompiler : ClassFileDecompilers.Full() {
|
||||||
private val stubBuilder = KotlinClsStubBuilder()
|
private val stubBuilder = KotlinClsStubBuilder()
|
||||||
|
|
||||||
override fun accepts(file: VirtualFile) = isKotlinJvmCompiledFile(file)
|
override fun accepts(file: VirtualFile) = IDEKotlinBinaryClassCache.isKotlinJvmCompiledFile(file)
|
||||||
|
|
||||||
override fun getStubBuilder() = stubBuilder
|
override fun getStubBuilder() = stubBuilder
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user