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

bzip2
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
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
get() = clazz.interfaces.map { classPath[it] }.toList()
get() = clazz.interfaces.map { classPath[it]!! }.toList()
override val fields
get() = clazz.fields.map { MemberDesc(it) }.toList()

@ -13,20 +13,30 @@ class ClassPath(
private val dependencies: List<Library>,
val libraries: List<Library>
) {
private val cache = mutableMapOf<String, ClassMetadata>()
private val cache = mutableMapOf<String, ClassMetadata?>()
val libraryClasses: List<ClassMetadata>
get() {
val classes = mutableListOf<ClassMetadata>()
for (library in libraries) {
for (clazz in library) {
classes.add(get(clazz.name))
classes.add(get(clazz.name)!!)
}
}
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) {
val clazz = library[name]
if (clazz != null) {
@ -44,7 +54,7 @@ class ClassPath(
val clazz = try {
runtime.loadClass(name.toBinaryClassName())
} catch (ex: ClassNotFoundException) {
throw IllegalArgumentException("Unknown class $name")
return@computeIfAbsent null
}
return@computeIfAbsent ReflectionClassMetadata(this, clazz)
@ -75,7 +85,7 @@ class ClassPath(
for (library in libraries) {
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 (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
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
get() = clazz.interfaces.map { classPath[it.asmName] }.toList()
get() = clazz.interfaces.map { classPath[it.asmName]!! }.toList()
override val fields
get() = clazz.declaredFields.map { MemberDesc(it.name, Type.getDescriptor(it.type)) }.toList()

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

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

Loading…
Cancel
Save