From 3c7989455b6c5691b078817363fcc9d9da8045d6 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 29 Feb 2020 14:11:28 +0000 Subject: [PATCH] Add ClassNameExtensions --- asm/src/main/java/dev/openrs2/asm/ClassNameExtensions.kt | 9 +++++++++ asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt | 5 ++--- .../dev/openrs2/asm/classpath/ReflectionClassMetadata.kt | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 asm/src/main/java/dev/openrs2/asm/ClassNameExtensions.kt diff --git a/asm/src/main/java/dev/openrs2/asm/ClassNameExtensions.kt b/asm/src/main/java/dev/openrs2/asm/ClassNameExtensions.kt new file mode 100644 index 0000000000..2df1840e7d --- /dev/null +++ b/asm/src/main/java/dev/openrs2/asm/ClassNameExtensions.kt @@ -0,0 +1,9 @@ +package dev.openrs2.asm + +fun String.toBinaryClassName(): String { + return replace('/', '.') +} + +fun String.toInternalClassName(): String { + return replace('.', '/') +} diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt b/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt index cea22f12bd..58028e5eef 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt @@ -2,6 +2,7 @@ package dev.openrs2.asm.classpath import dev.openrs2.asm.MemberDesc import dev.openrs2.asm.MemberRef +import dev.openrs2.asm.toBinaryClassName import dev.openrs2.common.collect.DisjointSet import dev.openrs2.common.collect.ForestDisjointSet import org.objectweb.asm.commons.Remapper @@ -40,10 +41,8 @@ class ClassPath( } } - val reflectionName = name.replace('/', '.') - val clazz = try { - runtime.loadClass(reflectionName) + runtime.loadClass(name.toBinaryClassName()) } catch (ex: ClassNotFoundException) { throw IllegalArgumentException("Unknown class $name") } diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt b/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt index e8ca3eddc7..d39ad2444d 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt @@ -1,10 +1,11 @@ package dev.openrs2.asm.classpath import dev.openrs2.asm.MemberDesc +import dev.openrs2.asm.toInternalClassName import org.objectweb.asm.Type private val Class<*>.asmName: String - get() = name.replace('.', '/') + get() = name.toInternalClassName() class ReflectionClassMetadata(private val classPath: ClassPath, private val clazz: Class<*>) : ClassMetadata() { override val name: String