From d57cf15bd3a9e8afe7c51f340a39ef25e0c81b40 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 7 Mar 2020 20:47:22 +0000 Subject: [PATCH] Add superClassAndInterfaces method to reduce duplication Signed-off-by: Graham --- .../openrs2/asm/classpath/ClassMetadata.kt | 10 +++++ .../dev/openrs2/asm/classpath/ClassPath.kt | 38 +------------------ 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt b/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt index 1ef61bc506..08d639c302 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt @@ -11,6 +11,16 @@ abstract class ClassMetadata { abstract val fields: List abstract val methods: List + val superClassAndInterfaces: List + get() { + val clazz = superClass + return if (clazz != null) { + listOf(clazz).plus(superInterfaces) + } else { + superInterfaces + } + } + abstract fun getFieldAccess(field: MemberDesc): Int? abstract fun getMethodAccess(method: MemberDesc): Int? 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 4ade6ecbec..eb545af37d 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt @@ -117,8 +117,7 @@ class ClassPath( val ancestorsBuilder = mutableSetOf() - val superClass = clazz.superClass - if (superClass != null) { + for (superClass in clazz.superClassAndInterfaces) { val fields = populateInheritedFieldSets(ancestorCache, disjointSet, superClass) for (field in fields) { 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) { disjointSet.add(MemberRef(clazz.name, field)) ancestorsBuilder.add(field) @@ -184,8 +167,7 @@ class ClassPath( val ancestorsBuilder = mutableSetOf() - val superClass = clazz.superClass - if (superClass != null) { + for (superClass in clazz.superClassAndInterfaces) { val methods = populateInheritedMethodSets(ancestorCache, disjointSet, superClass) for (method in methods) { 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) { disjointSet.add(MemberRef(clazz.name, method)) ancestorsBuilder.add(method)