diff --git a/src/main/kotlin/org/vineflower/ijplugin/VineflowerDecompilerBase.kt b/src/main/kotlin/org/vineflower/ijplugin/VineflowerDecompilerBase.kt index 7f4d7c6..48d6c22 100644 --- a/src/main/kotlin/org/vineflower/ijplugin/VineflowerDecompilerBase.kt +++ b/src/main/kotlin/org/vineflower/ijplugin/VineflowerDecompilerBase.kt @@ -59,6 +59,10 @@ abstract class VineflowerDecompilerBase : ClassFileDecompilers.Full() { abstract val sourceFileType: FileType override fun accepts(file: VirtualFile): Boolean { + if (file.extension != "class") { + return false + } + val state = VineflowerState.getInstance() if (!state.enabled || state.hadError) { return false diff --git a/src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt b/src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt index d2fb171..f984424 100644 --- a/src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt +++ b/src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt @@ -14,6 +14,7 @@ import com.intellij.openapi.vfs.readBytes import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiClass import com.intellij.psi.search.GlobalSearchScope +import com.intellij.util.ArrayUtil import java.io.File import java.util.concurrent.CompletableFuture import java.util.concurrent.LinkedBlockingQueue @@ -250,7 +251,14 @@ class VineflowerInvoker(classLoader: ClassLoader) { private val getCurrentDecompContext = classLoader.loadClass("org.jetbrains.java.decompiler.main.DecompilerContext") .getMethod("getCurrentContext") - fun getLanguage(bytes: ByteArray): String { + private val cafebabe = listOf(0xCA, 0xFE, 0xBA, 0xBE).map(Int::toByte).toByteArray() + + fun getLanguage(bytes: ByteArray): String? { + if (ArrayUtil.startsWith(bytes, cafebabe)) { + // Non-class file + return null + } + // ensure a decompilation context is available (otherwise the structclass constructor will fail) if (getCurrentDecompContext.invoke(null) == null) { val empty = emptyMap()