From 8cac7a48b5948b353756ecb5f2db57dece568528 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 7 Mar 2020 20:29:27 +0000 Subject: [PATCH] Add getFieldAccess Signed-off-by: Graham --- .../main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt | 4 ++++ asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt | 1 + .../dev/openrs2/asm/classpath/ReflectionClassMetadata.kt | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt index 563277f5..8094df07 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt @@ -27,6 +27,10 @@ class AsmClassMetadata( override val methods get() = clazz.methods.map(::MemberDesc) + override fun getFieldAccess(field: MemberDesc): Int? { + return clazz.fields.find { it.name == field.name && it.desc == field.desc }?.access + } + override fun getMethodAccess(method: MemberDesc): Int? { return clazz.methods.find { it.name == method.name && it.desc == method.desc }?.access } 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 111565c5..1ef61bc5 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,7 @@ abstract class ClassMetadata { abstract val fields: List abstract val methods: List + abstract fun getFieldAccess(field: MemberDesc): Int? abstract fun getMethodAccess(method: MemberDesc): Int? fun isOverride(method: MemberDesc): Boolean { 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 231e6e3e..cbc83528 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt @@ -29,6 +29,11 @@ class ReflectionClassMetadata(private val classPath: ClassPath, private val claz override val methods get() = clazz.declaredMethods.map { MemberDesc(it.name, Type.getMethodDescriptor(it)) } + override fun getFieldAccess(field: MemberDesc): Int? { + return clazz.declaredFields.find { it.name == field.name && Type.getDescriptor(it.type) == field.desc } + ?.modifiers + } + override fun getMethodAccess(method: MemberDesc): Int? { return clazz.declaredMethods.find { it.name == method.name && Type.getMethodDescriptor(it) == method.desc } ?.modifiers