Make ClassPath::get() return null if a class is not found

master
Graham 5 years ago
parent 59ac765ef8
commit fda857963b
  1. 4
      asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt
  2. 22
      asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt
  3. 4
      asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt
  4. 4
      deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt
  5. 2
      deob/src/main/java/dev/openrs2/deob/transform/OverrideTransformer.kt

@ -16,10 +16,10 @@ class AsmClassMetadata(
get() = clazz.access and Opcodes.ACC_INTERFACE != 0 get() = clazz.access and Opcodes.ACC_INTERFACE != 0
override val superClass override val superClass
get() = if (clazz.superName != null) classPath[clazz.superName] else null get() = if (clazz.superName != null) classPath[clazz.superName]!! else null
override val superInterfaces override val superInterfaces
get() = clazz.interfaces.map { classPath[it] }.toList() get() = clazz.interfaces.map { classPath[it]!! }.toList()
override val fields override val fields
get() = clazz.fields.map { MemberDesc(it) }.toList() get() = clazz.fields.map { MemberDesc(it) }.toList()

@ -13,20 +13,30 @@ class ClassPath(
private val dependencies: List<Library>, private val dependencies: List<Library>,
val libraries: List<Library> val libraries: List<Library>
) { ) {
private val cache = mutableMapOf<String, ClassMetadata>() private val cache = mutableMapOf<String, ClassMetadata?>()
val libraryClasses: List<ClassMetadata> val libraryClasses: List<ClassMetadata>
get() { get() {
val classes = mutableListOf<ClassMetadata>() val classes = mutableListOf<ClassMetadata>()
for (library in libraries) { for (library in libraries) {
for (clazz in library) { for (clazz in library) {
classes.add(get(clazz.name)) classes.add(get(clazz.name)!!)
} }
} }
return classes return classes
} }
operator fun get(name: String): ClassMetadata = cache.computeIfAbsent(name) { private inline fun computeIfAbsent(name: String, f: (String) -> ClassMetadata?): ClassMetadata? {
if (cache.containsKey(name)) {
return cache[name]
}
val clazz = f(name)
cache[name] = clazz
return clazz
}
operator fun get(name: String): ClassMetadata? = computeIfAbsent(name) {
for (library in libraries) { for (library in libraries) {
val clazz = library[name] val clazz = library[name]
if (clazz != null) { if (clazz != null) {
@ -44,7 +54,7 @@ class ClassPath(
val clazz = try { val clazz = try {
runtime.loadClass(name.toBinaryClassName()) runtime.loadClass(name.toBinaryClassName())
} catch (ex: ClassNotFoundException) { } catch (ex: ClassNotFoundException) {
throw IllegalArgumentException("Unknown class $name") return@computeIfAbsent null
} }
return@computeIfAbsent ReflectionClassMetadata(this, clazz) return@computeIfAbsent ReflectionClassMetadata(this, clazz)
@ -75,7 +85,7 @@ class ClassPath(
for (library in libraries) { for (library in libraries) {
for (clazz in library) { for (clazz in library) {
populateInheritedFieldSets(ancestorCache, disjointSet, get(clazz.name)) populateInheritedFieldSets(ancestorCache, disjointSet, get(clazz.name)!!)
} }
} }
@ -130,7 +140,7 @@ class ClassPath(
for (library in libraries) { for (library in libraries) {
for (clazz in library) { for (clazz in library) {
populateInheritedMethodSets(ancestorCache, disjointSet, get(clazz.name)) populateInheritedMethodSets(ancestorCache, disjointSet, get(clazz.name)!!)
} }
} }

@ -18,10 +18,10 @@ class ReflectionClassMetadata(private val classPath: ClassPath, private val claz
get() = clazz.isInterface get() = clazz.isInterface
override val superClass: ClassMetadata? override val superClass: ClassMetadata?
get() = if (clazz.superclass != null) classPath[clazz.superclass.asmName] else null get() = if (clazz.superclass != null) classPath[clazz.superclass.asmName]!! else null
override val superInterfaces override val superInterfaces
get() = clazz.interfaces.map { classPath[it.asmName] }.toList() get() = clazz.interfaces.map { classPath[it.asmName]!! }.toList()
override val fields override val fields
get() = clazz.declaredFields.map { MemberDesc(it.name, Type.getDescriptor(it.type)) }.toList() get() = clazz.declaredFields.map { MemberDesc(it.name, Type.getDescriptor(it.type)) }.toList()

@ -137,7 +137,7 @@ class TypedRemapper private constructor(
var skip = false var skip = false
for ((owner, name) in partition) { for ((owner, name) in partition) {
val clazz = classPath[owner] val clazz = classPath[owner]!!
if (name in EXCLUDED_FIELDS) { if (name in EXCLUDED_FIELDS) {
skip = true skip = true
@ -187,7 +187,7 @@ class TypedRemapper private constructor(
fun isMethodImmutable(classPath: ClassPath, partition: DisjointSet.Partition<MemberRef>): Boolean { fun isMethodImmutable(classPath: ClassPath, partition: DisjointSet.Partition<MemberRef>): Boolean {
for (method in partition) { for (method in partition) {
val clazz = classPath[method.owner] val clazz = classPath[method.owner]!!
if (method.name in EXCLUDED_METHODS) { if (method.name in EXCLUDED_METHODS) {
return true return true

@ -28,7 +28,7 @@ class OverrideTransformer : Transformer() {
return false return false
} }
if (!classPath[clazz.name].isOverride(MemberDesc(method))) { if (!classPath[clazz.name]!!.isOverride(MemberDesc(method))) {
return false return false
} }

Loading…
Cancel
Save