diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/Library.java b/asm/src/main/java/dev/openrs2/asm/classpath/Library.java index 90157443e0..2e1be25767 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/Library.java +++ b/asm/src/main/java/dev/openrs2/asm/classpath/Library.java @@ -15,7 +15,7 @@ import java.util.jar.JarOutputStream; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; -import dev.openrs2.asm.transform.ClassForNameTransformer; +import dev.openrs2.asm.remap.ClassForNameRemapper; import dev.openrs2.util.io.DeterministicJarOutputStream; import dev.openrs2.util.io.SkipOutputStream; import org.apache.harmony.pack200.Pack200; @@ -115,13 +115,12 @@ public final class Library implements Iterable { } public void remap(Remapper remapper) { - var transformer = new ClassForNameTransformer(remapper); var classNames = new HashSet(); for (var clazz : classes.values()) { for (var method : clazz.methods) { if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) { - transformer.transformCode(clazz, method); + ClassForNameRemapper.remap(remapper, method); } } diff --git a/asm/src/main/java/dev/openrs2/asm/transform/ClassForNameTransformer.java b/asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.java similarity index 67% rename from asm/src/main/java/dev/openrs2/asm/transform/ClassForNameTransformer.java rename to asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.java index 3741d20271..473e173ea0 100644 --- a/asm/src/main/java/dev/openrs2/asm/transform/ClassForNameTransformer.java +++ b/asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.java @@ -1,16 +1,15 @@ -package dev.openrs2.asm.transform; +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.ClassNode; import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; -public final class ClassForNameTransformer extends Transformer { +public final class ClassForNameRemapper { private static final InsnMatcher INVOKE_MATCHER = InsnMatcher.compile("LDC INVOKESTATIC"); private static boolean isClassForName(List match) { @@ -25,22 +24,17 @@ public final class ClassForNameTransformer extends Transformer { invokestatic.desc.equals("(Ljava/lang/String;)Ljava/lang/Class;"); } - private final Remapper remapper; - - public ClassForNameTransformer(Remapper remapper) { - this.remapper = remapper; - } - - @Override - public boolean transformCode(ClassNode clazz, MethodNode method) { - INVOKE_MATCHER.match(method).filter(ClassForNameTransformer::isClassForName).forEach(match -> { + 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; } }); + } - return false; + private ClassForNameRemapper() { + /* empty */ } }