From e4fe120bf7722445c6979bc0460814e4f3a01c5a Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 15 Dec 2019 19:54:48 +0000 Subject: [PATCH] Convert MemberDesc and MemberRef to Kotlin --- .../main/java/dev/openrs2/asm/MemberDesc.java | 68 ----------------- .../main/java/dev/openrs2/asm/MemberDesc.kt | 18 +++++ .../main/java/dev/openrs2/asm/MemberRef.java | 75 ------------------- .../main/java/dev/openrs2/asm/MemberRef.kt | 15 ++++ 4 files changed, 33 insertions(+), 143 deletions(-) delete mode 100644 asm/src/main/java/dev/openrs2/asm/MemberDesc.java create mode 100644 asm/src/main/java/dev/openrs2/asm/MemberDesc.kt delete mode 100644 asm/src/main/java/dev/openrs2/asm/MemberRef.java create mode 100644 asm/src/main/java/dev/openrs2/asm/MemberRef.kt diff --git a/asm/src/main/java/dev/openrs2/asm/MemberDesc.java b/asm/src/main/java/dev/openrs2/asm/MemberDesc.java deleted file mode 100644 index 2a282bbe89..0000000000 --- a/asm/src/main/java/dev/openrs2/asm/MemberDesc.java +++ /dev/null @@ -1,68 +0,0 @@ -package dev.openrs2.asm; - -import java.util.Objects; - -import org.objectweb.asm.tree.FieldInsnNode; -import org.objectweb.asm.tree.FieldNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; - -public final class MemberDesc { - private final String name, desc; - - public MemberDesc(FieldNode field) { - this(field.name, field.desc); - } - - public MemberDesc(MethodNode method) { - this(method.name, method.desc); - } - - public MemberDesc(FieldInsnNode fieldInsn) { - this(fieldInsn.name, fieldInsn.desc); - } - - public MemberDesc(MethodInsnNode methodInsn) { - this(methodInsn.name, methodInsn.desc); - } - - public MemberDesc(MemberRef memberRef) { - this(memberRef.getName(), memberRef.getDesc()); - } - - public MemberDesc(String name, String desc) { - this.name = name; - this.desc = desc; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - var memberDesc = (MemberDesc) o; - return name.equals(memberDesc.name) && - desc.equals(memberDesc.desc); - } - - @Override - public int hashCode() { - return Objects.hash(name, desc); - } - - @Override - public String toString() { - return String.format("%s %s", desc, name); - } -} diff --git a/asm/src/main/java/dev/openrs2/asm/MemberDesc.kt b/asm/src/main/java/dev/openrs2/asm/MemberDesc.kt new file mode 100644 index 0000000000..6a6279ebeb --- /dev/null +++ b/asm/src/main/java/dev/openrs2/asm/MemberDesc.kt @@ -0,0 +1,18 @@ +package dev.openrs2.asm + +import org.objectweb.asm.tree.FieldInsnNode +import org.objectweb.asm.tree.FieldNode +import org.objectweb.asm.tree.MethodInsnNode +import org.objectweb.asm.tree.MethodNode + +data class MemberDesc(val name: String, val desc: String) { + constructor(field: FieldNode) : this(field.name, field.desc) + constructor(method: MethodNode) : this(method.name, method.desc) + constructor(fieldInsn: FieldInsnNode) : this(fieldInsn.name, fieldInsn.desc) + constructor(methodInsn: MethodInsnNode) : this(methodInsn.name, methodInsn.desc) + constructor(memberRef: MemberRef) : this(memberRef.name, memberRef.desc) + + override fun toString(): String { + return "$desc $name" + } +} diff --git a/asm/src/main/java/dev/openrs2/asm/MemberRef.java b/asm/src/main/java/dev/openrs2/asm/MemberRef.java deleted file mode 100644 index 611e6d0fdb..0000000000 --- a/asm/src/main/java/dev/openrs2/asm/MemberRef.java +++ /dev/null @@ -1,75 +0,0 @@ -package dev.openrs2.asm; - -import java.util.Objects; - -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldInsnNode; -import org.objectweb.asm.tree.FieldNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; - -public final class MemberRef { - private final String owner, name, desc; - - public MemberRef(ClassNode clazz, FieldNode field) { - this(clazz.name, field.name, field.desc); - } - - public MemberRef(ClassNode clazz, MethodNode method) { - this(clazz.name, method.name, method.desc); - } - - public MemberRef(FieldInsnNode fieldInsn) { - this(fieldInsn.owner, fieldInsn.name, fieldInsn.desc); - } - - public MemberRef(MethodInsnNode methodInsn) { - this(methodInsn.owner, methodInsn.name, methodInsn.desc); - } - - public MemberRef(String owner, MemberDesc desc) { - this(owner, desc.getName(), desc.getDesc()); - } - - public MemberRef(String owner, String name, String desc) { - this.owner = owner; - this.name = name; - this.desc = desc; - } - - public String getOwner() { - return owner; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - var memberRef = (MemberRef) o; - return owner.equals(memberRef.owner) && - name.equals(memberRef.name) && - desc.equals(memberRef.desc); - } - - @Override - public int hashCode() { - return Objects.hash(owner, name, desc); - } - - @Override - public String toString() { - return String.format("%s %s.%s", desc, owner, name); - } -} diff --git a/asm/src/main/java/dev/openrs2/asm/MemberRef.kt b/asm/src/main/java/dev/openrs2/asm/MemberRef.kt new file mode 100644 index 0000000000..5bc0392d97 --- /dev/null +++ b/asm/src/main/java/dev/openrs2/asm/MemberRef.kt @@ -0,0 +1,15 @@ +package dev.openrs2.asm + +import org.objectweb.asm.tree.* + +data class MemberRef(val owner: String, val name: String, val desc: String) { + constructor(clazz: ClassNode, field: FieldNode) : this(clazz.name, field.name, field.desc) + constructor(clazz: ClassNode, method: MethodNode) : this(clazz.name, method.name, method.desc) + constructor(fieldInsn: FieldInsnNode) : this(fieldInsn.owner, fieldInsn.name, fieldInsn.desc) + constructor(methodInsn: MethodInsnNode) : this(methodInsn.owner, methodInsn.name, methodInsn.desc) + constructor(owner: String, desc: MemberDesc) : this(owner, desc.name, desc.desc) + + override fun toString(): String { + return "$desc $owner.$name" + } +}