From 446a72abc517f31bb44a14ff9c77a9e56e90d7fe Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 12 Oct 2019 18:02:35 +0100 Subject: [PATCH] Make package-private classes, methods and fields public This will make refactoring the client code into packages easier. --- .../deob/transform/AccessTransformer.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.java index d0d336f701..e26df09e05 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.java @@ -5,6 +5,7 @@ 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.FieldNode; import org.objectweb.asm.tree.MethodNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,15 +13,39 @@ import org.slf4j.LoggerFactory; public final class AccessTransformer extends Transformer { private static final Logger logger = LoggerFactory.getLogger(AccessTransformer.class); - private int redundantFinals; + private int redundantFinals, packagePrivate; @Override protected void preTransform(ClassPath classPath) { redundantFinals = 0; + packagePrivate = 0; + } + + @Override + protected boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) { + if ((clazz.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)) == 0) { + clazz.access |= Opcodes.ACC_PUBLIC; + packagePrivate++; + } + return false; + } + + @Override + protected boolean transformField(ClassPath classPath, Library library, ClassNode clazz, FieldNode field) { + if ((field.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)) == 0) { + field.access |= Opcodes.ACC_PUBLIC; + packagePrivate++; + } + return false; } @Override protected boolean preTransformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) { + if ((method.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)) == 0) { + method.access |= Opcodes.ACC_PUBLIC; + packagePrivate++; + } + if ((method.access & Opcodes.ACC_FINAL) == 0) { return false; } @@ -35,5 +60,6 @@ public final class AccessTransformer extends Transformer { @Override protected void postTransform(ClassPath classPath) { logger.info("Removed {} redundant final modifiers", redundantFinals); + logger.info("Made {} package-private classes, fields and methods public", packagePrivate); } }