Replace ClassForNameTransformer

This commit stops ClassForNameTransformer from extending Transformer and
renames it. I think this makes sense, as we don't use it like a normal
Transformer.
bzip2
Graham 5 years ago
parent b97294457a
commit 46f908bdb0
  1. 5
      asm/src/main/java/dev/openrs2/asm/classpath/Library.java
  2. 20
      asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.java

@ -15,7 +15,7 @@ import java.util.jar.JarOutputStream;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; 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.DeterministicJarOutputStream;
import dev.openrs2.util.io.SkipOutputStream; import dev.openrs2.util.io.SkipOutputStream;
import org.apache.harmony.pack200.Pack200; import org.apache.harmony.pack200.Pack200;
@ -115,13 +115,12 @@ public final class Library implements Iterable<ClassNode> {
} }
public void remap(Remapper remapper) { public void remap(Remapper remapper) {
var transformer = new ClassForNameTransformer(remapper);
var classNames = new HashSet<String>(); var classNames = new HashSet<String>();
for (var clazz : classes.values()) { for (var clazz : classes.values()) {
for (var method : clazz.methods) { for (var method : clazz.methods) {
if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) { if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) {
transformer.transformCode(clazz, method); ClassForNameRemapper.remap(remapper, method);
} }
} }

@ -1,16 +1,15 @@
package dev.openrs2.asm.transform; package dev.openrs2.asm.remap;
import java.util.List; import java.util.List;
import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.InsnMatcher;
import org.objectweb.asm.commons.Remapper; import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode; 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 final InsnMatcher INVOKE_MATCHER = InsnMatcher.compile("LDC INVOKESTATIC");
private static boolean isClassForName(List<AbstractInsnNode> match) { private static boolean isClassForName(List<AbstractInsnNode> match) {
@ -25,22 +24,17 @@ public final class ClassForNameTransformer extends Transformer {
invokestatic.desc.equals("(Ljava/lang/String;)Ljava/lang/Class;"); invokestatic.desc.equals("(Ljava/lang/String;)Ljava/lang/Class;");
} }
private final Remapper remapper; public static void remap(Remapper remapper, MethodNode method) {
INVOKE_MATCHER.match(method).filter(ClassForNameRemapper::isClassForName).forEach(match -> {
public ClassForNameTransformer(Remapper remapper) {
this.remapper = remapper;
}
@Override
public boolean transformCode(ClassNode clazz, MethodNode method) {
INVOKE_MATCHER.match(method).filter(ClassForNameTransformer::isClassForName).forEach(match -> {
var ldc = (LdcInsnNode) match.get(0); var ldc = (LdcInsnNode) match.get(0);
var name = remapper.map((String) ldc.cst); var name = remapper.map((String) ldc.cst);
if (name != null) { if (name != null) {
ldc.cst = name; ldc.cst = name;
} }
}); });
}
return false; private ClassForNameRemapper() {
/* empty */
} }
} }
Loading…
Cancel
Save