Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/org/vineflower/ijplugin/VineflowerInvoker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this? This condition is inverted

// 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<Nothing, Nothing>()
Expand Down