Convert MemberDesc and MemberRef to Kotlin

bzip2
Graham 5 years ago
parent eec9279a2c
commit e4fe120bf7
  1. 68
      asm/src/main/java/dev/openrs2/asm/MemberDesc.java
  2. 18
      asm/src/main/java/dev/openrs2/asm/MemberDesc.kt
  3. 75
      asm/src/main/java/dev/openrs2/asm/MemberRef.java
  4. 15
      asm/src/main/java/dev/openrs2/asm/MemberRef.kt

@ -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);
}
}

@ -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"
}
}

@ -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);
}
}

@ -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"
}
}
Loading…
Cancel
Save