@ -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 Transform er {
public final class ClassForNameRemapp er {
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 */
}
}
}
}