Skip to content

Commit e5e7406

Browse files
committed
Move away from reflection to call ByteCodeViewerManager.loadClassFileBytes
1 parent 72dcdc9 commit e5e7406

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/main/kotlin/platform/mixin/util/AsmUtil.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.demonwav.mcdev.util.loggerForTopLevel
3939
import com.demonwav.mcdev.util.mapToArray
4040
import com.demonwav.mcdev.util.realName
4141
import com.demonwav.mcdev.util.toJavaIdentifier
42+
import com.intellij.byteCodeViewer.ByteCodeViewerManager
4243
import com.intellij.codeEditor.JavaEditorFileSwapper
4344
import com.intellij.ide.highlighter.JavaFileType
4445
import com.intellij.openapi.module.Module
@@ -86,7 +87,6 @@ import com.llamalad7.mixinextras.expression.impl.utils.ExpressionASMUtils
8687
import java.io.PrintWriter
8788
import java.io.StringWriter
8889
import java.lang.reflect.InvocationTargetException
89-
import java.lang.reflect.Method
9090
import java.util.concurrent.ConcurrentHashMap
9191
import java.util.concurrent.ConcurrentMap
9292
import org.objectweb.asm.ClassReader
@@ -183,12 +183,6 @@ fun internalNameToShortName(internalName: String) = internalName.substringAfterL
183183
val ClassNode.shortName
184184
get() = internalNameToShortName(name)
185185

186-
private val LOAD_CLASS_FILE_BYTES: Method? = runCatching {
187-
com.intellij.byteCodeViewer.ByteCodeViewerManager::class.java
188-
.getDeclaredMethod("loadClassFileBytes", PsiClass::class.java)
189-
.let { it.isAccessible = true; it }
190-
}.getOrNull()
191-
192186
private val INNER_CLASS_NODES_KEY = Key.create<CachedValue<ConcurrentMap<String, ClassNode?>>>("mcdev.innerClassNodes")
193187

194188
/**
@@ -224,7 +218,7 @@ private val NODE_BY_PSI_CLASS_KEY = Key.create<CachedValue<ClassNode?>>("mcdev.n
224218
fun findClassNodeByPsiClass(psiClass: PsiClass, module: Module? = psiClass.findModule()): ClassNode? {
225219
return psiClass.lockedCached(NODE_BY_PSI_CLASS_KEY) {
226220
try {
227-
val bytes = LOAD_CLASS_FILE_BYTES?.invoke(null, psiClass) as? ByteArray
221+
val bytes = ByteCodeViewerManager.loadClassFileBytes(psiClass)
228222
if (bytes == null) {
229223
// find compiler output
230224
if (module == null) return@lockedCached null

0 commit comments

Comments
 (0)