From c02fe030fa20e6570d36422da58ebc5847516b5d Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 22 Dec 2019 14:25:02 +0000 Subject: [PATCH] Convert ClassForNameRemapper to Kotlin --- .../asm/remap/ClassForNameRemapper.java | 40 ------------------- .../openrs2/asm/remap/ClassForNameRemapper.kt | 35 ++++++++++++++++ 2 files changed, 35 insertions(+), 40 deletions(-) delete mode 100644 asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.java create mode 100644 asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.kt diff --git a/asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.java b/asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.java deleted file mode 100644 index 473e173ea0..0000000000 --- a/asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.java +++ /dev/null @@ -1,40 +0,0 @@ -package dev.openrs2.asm.remap; - -import java.util.List; - -import dev.openrs2.asm.InsnMatcher; -import org.objectweb.asm.commons.Remapper; -import org.objectweb.asm.tree.AbstractInsnNode; -import org.objectweb.asm.tree.LdcInsnNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; - -public final class ClassForNameRemapper { - private static final InsnMatcher INVOKE_MATCHER = InsnMatcher.compile("LDC INVOKESTATIC"); - - private static boolean isClassForName(List match) { - var ldc = (LdcInsnNode) match.get(0); - if (!(ldc.cst instanceof String)) { - return false; - } - - var invokestatic = (MethodInsnNode) match.get(1); - return invokestatic.owner.equals("java/lang/Class") && - invokestatic.name.equals("forName") && - invokestatic.desc.equals("(Ljava/lang/String;)Ljava/lang/Class;"); - } - - public static void remap(Remapper remapper, MethodNode method) { - INVOKE_MATCHER.match(method).filter(ClassForNameRemapper::isClassForName).forEach(match -> { - var ldc = (LdcInsnNode) match.get(0); - var name = remapper.map((String) ldc.cst); - if (name != null) { - ldc.cst = name; - } - }); - } - - private ClassForNameRemapper() { - /* empty */ - } -} diff --git a/asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.kt b/asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.kt new file mode 100644 index 0000000000..3daf74854c --- /dev/null +++ b/asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.kt @@ -0,0 +1,35 @@ +package dev.openrs2.asm.remap + +import dev.openrs2.asm.InsnMatcher +import org.objectweb.asm.commons.Remapper +import org.objectweb.asm.tree.AbstractInsnNode +import org.objectweb.asm.tree.LdcInsnNode +import org.objectweb.asm.tree.MethodInsnNode +import org.objectweb.asm.tree.MethodNode + +object ClassForNameRemapper { + private val INVOKE_MATCHER = InsnMatcher.compile("LDC INVOKESTATIC") + + private fun isClassForName(match: List): Boolean { + val ldc = match[0] as LdcInsnNode + if (ldc.cst !is String) { + return false + } + + val invokestatic = match[1] as MethodInsnNode + return invokestatic.owner == "java/lang/Class" + && invokestatic.name == "forName" + && invokestatic.desc == "(Ljava/lang/String;)Ljava/lang/Class;" + } + + @JvmStatic + fun remap(remapper: Remapper, method: MethodNode) { + INVOKE_MATCHER.match(method).filter(ClassForNameRemapper::isClassForName).forEach { + val ldc = it[0] as LdcInsnNode + val name = remapper.map(ldc.cst as String) + if (name != null) { + ldc.cst = name + } + } + } +}