From e5af4548150d37a53d415bee408a76ed6108cd0a Mon Sep 17 00:00:00 2001 From: Graham Date: Mon, 23 Dec 2019 17:14:18 +0000 Subject: [PATCH] Convert ClassMetadata to Kotlin The dependency/interface properties are translated to getDependency and getInterface. I don't know if it is possible to fix this, but it won't matter when the rest of the codebase is converted to Kotlin. --- .../asm/classpath/AsmClassMetadata.java | 4 +-- .../openrs2/asm/classpath/ClassMetadata.java | 34 ------------------- .../openrs2/asm/classpath/ClassMetadata.kt | 26 ++++++++++++++ .../classpath/ReflectionClassMetadata.java | 4 +-- .../dev/openrs2/deob/remap/TypedRemapper.java | 8 ++--- 5 files changed, 34 insertions(+), 42 deletions(-) delete mode 100644 asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.java create mode 100644 asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java index 5f3a15a95d..2e4450f932 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java +++ b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java @@ -22,12 +22,12 @@ public final class AsmClassMetadata extends ClassMetadata { } @Override - public boolean isDependency() { + public boolean getDependency() { return dependency; } @Override - public boolean isInterface() { + public boolean getInterface() { return (clazz.access & Opcodes.ACC_INTERFACE) != 0; } diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.java b/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.java deleted file mode 100644 index 1dbf737116..0000000000 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.openrs2.asm.classpath; - -import java.util.Objects; - -import com.google.common.collect.ImmutableList; -import dev.openrs2.asm.MemberDesc; - -public abstract class ClassMetadata { - public abstract String getName(); - public abstract boolean isDependency(); - public abstract boolean isInterface(); - public abstract ClassMetadata getSuperClass(); - public abstract ImmutableList getSuperInterfaces(); - public abstract ImmutableList getFields(); - public abstract ImmutableList getMethods(); - public abstract boolean isNative(MemberDesc method); - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - var that = (ClassMetadata) o; - return getName().equals(that.getName()); - } - - @Override - public int hashCode() { - return Objects.hash(getName()); - } -} diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt b/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt new file mode 100644 index 0000000000..2574d50d2f --- /dev/null +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt @@ -0,0 +1,26 @@ +package dev.openrs2.asm.classpath + +import dev.openrs2.asm.MemberDesc + +abstract class ClassMetadata { + abstract val name: String + abstract val dependency: Boolean + abstract val `interface`: Boolean + abstract val superClass: ClassMetadata? + abstract val superInterfaces: List + abstract val fields: List + abstract val methods: List + + abstract fun isNative(method: MemberDesc): Boolean + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is ClassMetadata) return false + + return name == other.name + } + + override fun hashCode(): Int { + return name.hashCode() + } +} diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.java b/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.java index 7aad28b100..ab753b03d0 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.java +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.java @@ -22,12 +22,12 @@ public final class ReflectionClassMetadata extends ClassMetadata { } @Override - public boolean isDependency() { + public boolean getDependency() { return true; } @Override - public boolean isInterface() { + public boolean getInterface() { return clazz.isInterface(); } diff --git a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java index 086682a779..f7037b72c3 100644 --- a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java +++ b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java @@ -91,7 +91,7 @@ public final class TypedRemapper extends Remapper { private static String populateClassMapping(Map mapping, Map prefixes, ClassMetadata clazz) { var name = clazz.getName(); - if (mapping.containsKey(name) || EXCLUDED_CLASSES.contains(name) || clazz.isDependency()) { + if (mapping.containsKey(name) || EXCLUDED_CLASSES.contains(name) || clazz.getDependency()) { return mapping.getOrDefault(name, name); } @@ -103,7 +103,7 @@ public final class TypedRemapper extends Remapper { superName = superName.substring(superName.lastIndexOf('/') + 1); mappedName += generateName(prefixes, superName + "_Sub"); - } else if (clazz.isInterface()) { + } else if (clazz.getInterface()) { mappedName += generateName(prefixes, "Interface"); } else { mappedName += generateName(prefixes, "Class"); @@ -128,7 +128,7 @@ public final class TypedRemapper extends Remapper { break; } - if (clazz.isDependency()) { + if (clazz.getDependency()) { skip = true; break; } @@ -185,7 +185,7 @@ public final class TypedRemapper extends Remapper { return true; } - if (clazz.isDependency()) { + if (clazz.getDependency()) { return true; }