Fix removal of empty classes only referenced by other empty classes

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent 81bbc71e29
commit c9a2b14dfa
  1. 19
      deob/src/main/java/dev/openrs2/deob/transform/EmptyClassTransformer.kt

@ -13,12 +13,18 @@ import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.TypeInsnNode import org.objectweb.asm.tree.TypeInsnNode
class EmptyClassTransformer : Transformer() { class EmptyClassTransformer : Transformer() {
private var removedClasses = 0
private val emptyClasses = mutableSetOf<String>() private val emptyClasses = mutableSetOf<String>()
private val referencedClasses = mutableSetOf<String>() private val referencedClasses = mutableSetOf<String>()
override fun preTransform(classPath: ClassPath) { override fun preTransform(classPath: ClassPath) {
removedClasses = 0
emptyClasses.clear() emptyClasses.clear()
}
override fun prePass(classPath: ClassPath): Boolean {
referencedClasses.clear() referencedClasses.clear()
return false
} }
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean { override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
@ -75,18 +81,23 @@ class EmptyClassTransformer : Transformer() {
return false return false
} }
override fun postTransform(classPath: ClassPath) { override fun postPass(classPath: ClassPath): Boolean {
var removed = 0 var changed = false
for (name in emptyClasses.subtract(referencedClasses)) { for (name in emptyClasses.subtract(referencedClasses)) {
for (library in classPath.libraries) { for (library in classPath.libraries) {
if (library.remove(name) != null) { if (library.remove(name) != null) {
removed++ removedClasses++
changed = true
} }
} }
} }
logger.info { "Removed $removed unused classes" } return changed
}
override fun postTransform(classPath: ClassPath) {
logger.info { "Removed $removedClasses unused classes" }
} }
companion object { companion object {

Loading…
Cancel
Save