Open-source multiplayer game server compatible with the RuneScape client https://www.openrs2.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
openrs2/asm/src/main/java/org/openrs2/asm/MemberRef.kt

43 lines
1.6 KiB

package org.openrs2.asm
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 data class MemberRef(val owner: String, val name: String, val desc: String) : Comparable<MemberRef> {
public constructor(clazz: ClassNode, field: FieldNode) : this(clazz.name, field.name, field.desc)
public constructor(clazz: ClassNode, method: MethodNode) : this(clazz.name, method.name, method.desc)
public constructor(fieldInsn: FieldInsnNode) : this(fieldInsn.owner, fieldInsn.name, fieldInsn.desc)
public constructor(methodInsn: MethodInsnNode) : this(methodInsn.owner, methodInsn.name, methodInsn.desc)
public constructor(owner: String, desc: MemberDesc) : this(owner, desc.name, desc.desc)
override fun compareTo(other: MemberRef): Int {
var result = owner.compareTo(other.owner)
if (result != 0) {
return result
}
result = name.compareTo(other.name)
if (result != 0) {
return result
}
return desc.compareTo(other.desc)
}
override fun toString(): String {
return "$owner.$name $desc"
}
public companion object {
private val STRING_REGEX = Regex("([^.]+)[.]([^ ]+) (.+)")
public fun fromString(str: String): MemberRef {
val result = STRING_REGEX.matchEntire(str)
require(result != null)
return MemberRef(result.groupValues[1], result.groupValues[2], result.groupValues[3])
}
}
}