Convert CachePathTransformer to Kotlin

bzip2
Graham 5 years ago
parent 3e0e7824e0
commit a3e5a19811
  1. 47
      bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.java
  2. 46
      bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.kt

@ -1,47 +0,0 @@
package dev.openrs2.bundler.transform;
import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class CachePathTransformer extends Transformer {
private static final Logger logger = LoggerFactory.getLogger(CachePathTransformer.class);
private int paths;
@Override
protected void preTransform(ClassPath classPath) {
paths = 0;
}
@Override
protected boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
for (var insn : method.instructions) {
if (insn.getOpcode() != Opcodes.LDC) {
continue;
}
var ldc = (LdcInsnNode) insn;
if (ldc.cst.equals(".jagex_cache_") || ldc.cst.equals(".file_store_")) {
ldc.cst = ".openrs2_cache_";
paths++;
} else if (ldc.cst.equals("jagex_")) {
ldc.cst = ".openrs2_";
paths++;
}
}
return false;
}
@Override
protected void postTransform(ClassPath classPath) {
logger.info("Updated {} cache paths", paths);
}
}

@ -0,0 +1,46 @@
package dev.openrs2.bundler.transform
import com.github.michaelbull.logging.InlineLogger
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodNode
class CachePathTransformer : Transformer() {
private var paths = 0
override fun preTransform(classPath: ClassPath) {
paths = 0
}
override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean {
for (insn in method.instructions) {
if (insn !is LdcInsnNode) {
continue
}
when (insn.cst) {
".jagex_cache_", ".file_store_" -> {
insn.cst = ".openrs2_cache_"
paths++
}
"jagex_" -> {
insn.cst = ".openrs2_"
paths++
}
}
}
return false
}
override fun postTransform(classPath: ClassPath) {
logger.info { "Updated $paths cache paths" }
}
companion object {
private val logger = InlineLogger()
}
}
Loading…
Cancel
Save