Add superClassAndInterfaces method to reduce duplication

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent 5103eb15a4
commit d57cf15bd3
  1. 10
      asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt
  2. 38
      asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt

@ -11,6 +11,16 @@ abstract class ClassMetadata {
abstract val fields: List<MemberDesc> abstract val fields: List<MemberDesc>
abstract val methods: List<MemberDesc> abstract val methods: List<MemberDesc>
val superClassAndInterfaces: List<ClassMetadata>
get() {
val clazz = superClass
return if (clazz != null) {
listOf(clazz).plus(superInterfaces)
} else {
superInterfaces
}
}
abstract fun getFieldAccess(field: MemberDesc): Int? abstract fun getFieldAccess(field: MemberDesc): Int?
abstract fun getMethodAccess(method: MemberDesc): Int? abstract fun getMethodAccess(method: MemberDesc): Int?

@ -117,8 +117,7 @@ class ClassPath(
val ancestorsBuilder = mutableSetOf<MemberDesc>() val ancestorsBuilder = mutableSetOf<MemberDesc>()
val superClass = clazz.superClass for (superClass in clazz.superClassAndInterfaces) {
if (superClass != null) {
val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superClass) val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superClass)
for (field in fields) { for (field in fields) {
val access = clazz.getFieldAccess(field) val access = clazz.getFieldAccess(field)
@ -134,22 +133,6 @@ class ClassPath(
} }
} }
for (superInterface in clazz.superInterfaces) {
val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superInterface)
for (field in fields) {
val access = clazz.getFieldAccess(field)
if (access != null && access and Opcodes.ACC_STATIC != 0) {
continue
}
val partition1 = disjointSet.add(MemberRef(clazz.name, field))
val partition2 = disjointSet.add(MemberRef(superInterface.name, field))
disjointSet.union(partition1, partition2)
ancestorsBuilder.add(field)
}
}
for (field in clazz.fields) { for (field in clazz.fields) {
disjointSet.add(MemberRef(clazz.name, field)) disjointSet.add(MemberRef(clazz.name, field))
ancestorsBuilder.add(field) ancestorsBuilder.add(field)
@ -184,8 +167,7 @@ class ClassPath(
val ancestorsBuilder = mutableSetOf<MemberDesc>() val ancestorsBuilder = mutableSetOf<MemberDesc>()
val superClass = clazz.superClass for (superClass in clazz.superClassAndInterfaces) {
if (superClass != null) {
val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superClass) val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superClass)
for (method in methods) { for (method in methods) {
val access = clazz.getMethodAccess(method) val access = clazz.getMethodAccess(method)
@ -201,22 +183,6 @@ class ClassPath(
} }
} }
for (superInterface in clazz.superInterfaces) {
val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superInterface)
for (method in methods) {
val access = clazz.getMethodAccess(method)
if (access != null && access and Opcodes.ACC_STATIC != 0) {
continue
}
val partition1 = disjointSet.add(MemberRef(clazz.name, method))
val partition2 = disjointSet.add(MemberRef(superInterface.name, method))
disjointSet.union(partition1, partition2)
ancestorsBuilder.add(method)
}
}
for (method in clazz.methods) { for (method in clazz.methods) {
disjointSet.add(MemberRef(clazz.name, method)) disjointSet.add(MemberRef(clazz.name, method))
ancestorsBuilder.add(method) ancestorsBuilder.add(method)

Loading…
Cancel
Save