Skip to content

Commit

Permalink
update access
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Mar 31, 2024
1 parent 9888ed6 commit d9d0cbe
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ abstract class ClassField(name: String, owner: Class<*>) : ClassMember(name, own

abstract val type: LazyClass

abstract val isTransient: Boolean

abstract fun get(src: Any? = null): Any?

abstract fun set(src: Any? = null, value: Any?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ abstract class ClassMember(val name: String, val owner: Class<*>) {

abstract val isStatic: Boolean

abstract val isFinal: Boolean

abstract val isPublic: Boolean

abstract val isProtected: Boolean

abstract val isPrivate: Boolean

fun getAnnotation(annotation: Class<out Annotation>): ClassAnnotation {
return annotations.first { it.source.name == annotation.name }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ abstract class ClassMethod(name: String, owner: Class<*>) : ClassMember(name, ow

abstract val parameter: List<LazyAnnotatedClass>

abstract val isNative: Boolean

abstract val isAbstract: Boolean

abstract val isVolatile: Boolean

abstract val isSynchronized: Boolean

abstract fun invoke(src: Any, vararg values: Any?): Any?

abstract fun invokeStatic(vararg values: Any?): Any?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ abstract class ClassStructure(
val constructors = LinkedList(constructors)

val name by lazy(LazyThreadSafetyMode.NONE) {
kotlin.runCatching { owner.name }.getOrNull()
runCatching { owner.name }.getOrNull()
}

val simpleName by lazy(LazyThreadSafetyMode.NONE) {
kotlin.runCatching { owner.simpleName }.getOrNull()
runCatching { owner.simpleName }.getOrNull()
}

abstract fun getField(name: String): ClassField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ class JavaClassStructure(
}

override fun getFieldSilently(name: String): ClassField? {
return kotlin.runCatching { getField(name) }.getOrNull()
return runCatching { getField(name) }.getOrNull()
}

override fun getMethodSilently(name: String, vararg parameter: Any?): ClassMethod? {
return kotlin.runCatching { getMethod(name, *parameter) }.getOrNull()
return runCatching { getMethod(name, *parameter) }.getOrNull()
}

override fun getMethodByTypeSilently(name: String, vararg parameter: Class<*>): ClassMethod? {
return kotlin.runCatching { getMethodByType(name, *parameter) }.getOrNull()
return runCatching { getMethodByType(name, *parameter) }.getOrNull()
}

override fun getConstructorSilently(vararg parameter: Any?): ClassConstructor? {
return kotlin.runCatching { getConstructor(*parameter) }.getOrNull()
return runCatching { getConstructor(*parameter) }.getOrNull()
}

override fun getConstructorByTypeSilently(vararg parameter: Class<*>): ClassConstructor? {
return kotlin.runCatching { getConstructorByType(*parameter) }.getOrNull()
return runCatching { getConstructorByType(*parameter) }.getOrNull()
}

override fun getAnnotation(annotation: Class<out Annotation>): ClassAnnotation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open class LazyClass(source: String) {

val name = source.replace('/', '.')

open val instance by lazy(LazyThreadSafetyMode.NONE) { kotlin.runCatching { Class.forName(name) }.getOrNull() }
open val instance by lazy(LazyThreadSafetyMode.NONE) { runCatching { Class.forName(name) }.getOrNull() }

override fun toString(): String {
return "LazyClass(name='$name')"
Expand Down
4 changes: 2 additions & 2 deletions analyser/src/main/kotlin/org/tabooproject/reflex/LazyEnum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.concurrent.ConcurrentHashMap
* @author 坏黑
* @since 2022/1/24 9:27 PM
*/
@Suppress("UNCHECKED_CAST", "TYPE_MISMATCH_WARNING")
@Suppress("UNCHECKED_CAST")
class LazyEnum(val source: LazyClass, val name: String) {

val instance by lazy(LazyThreadSafetyMode.NONE) {
Expand All @@ -23,7 +23,7 @@ class LazyEnum(val source: LazyClass, val name: String) {
val map = ConcurrentHashMap<String, Map<String, Enum<*>>>()

fun allOf(enumClass: Class<Enum<*>>): Map<String, Enum<*>> {
return map.computeIfAbsent(enumClass.name) { EnumSet.allOf(enumClass).associateBy { it.name } }
return map.computeIfAbsent(enumClass.name) { enumClass.enumConstants.associateBy { (it as Enum<*>).name } }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class AsmClassConstructor(
val access: Int,
val parameterAnnotations: Map<Int, ArrayList<AsmAnnotation>>,
override val annotations: List<ClassAnnotation>,
) :
JavaClassConstructor(name, owner) {
) : JavaClassConstructor(name, owner) {

val localParameter = AsmSignature.signatureToClass(descriptor).mapIndexed { idx, it ->
if (it is InstantClass) {
Expand All @@ -35,7 +34,19 @@ class AsmClassConstructor(
get() = localParameter

override val isStatic: Boolean
get() = Modifier.isStatic(access)
get() = true

override val isFinal: Boolean
get() = true

override val isPublic: Boolean
get() = Modifier.isPublic(access)

override val isProtected: Boolean
get() = Modifier.isProtected(access)

override val isPrivate: Boolean
get() = Modifier.isPrivate(access)

override fun toString(): String {
return "AsmClassConstructor(descriptor='$descriptor', access=$access) ${super.toString()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ class AsmClassField(name: String, owner: Class<*>, val descriptor: String, val a
override val isStatic: Boolean
get() = Modifier.isStatic(access)

override val isTransient: Boolean
get() = Modifier.isTransient(access)

override val isFinal: Boolean
get() = Modifier.isFinal(access)

override val isPublic: Boolean
get() = Modifier.isPublic(access)

override val isProtected: Boolean
get() = Modifier.isProtected(access)

override val isPrivate: Boolean
get() = Modifier.isPrivate(access)

init {
SignatureReader(descriptor).accept(object : SignatureWriter() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ class AsmClassMethod(
override val isStatic: Boolean
get() = Modifier.isStatic(access)

override val isFinal: Boolean
get() = Modifier.isFinal(access)

override val isPublic: Boolean
get() = Modifier.isPublic(access)

override val isProtected: Boolean
get() = Modifier.isProtected(access)

override val isPrivate: Boolean
get() = Modifier.isPrivate(access)

override val isNative: Boolean
get() = Modifier.isNative(access)

override val isAbstract: Boolean
get() = Modifier.isAbstract(access)

override val isVolatile: Boolean
get() = Modifier.isVolatile(access)

override val isSynchronized: Boolean
get() = Modifier.isSynchronized(access)

fun read() {
var visitParameterType = false
var visitReturnType = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.tabooproject.reflex.Internal
import org.tabooproject.reflex.JavaClassConstructor
import org.tabooproject.reflex.LazyAnnotatedClass
import java.lang.reflect.Constructor
import java.lang.reflect.Modifier

/**
* @author 坏黑
Expand All @@ -25,6 +26,18 @@ class InstantClassConstructor(owner: Class<*>, private val constructor: Construc
override val isStatic: Boolean
get() = true

override val isFinal: Boolean
get() = true

override val isPublic: Boolean
get() = Modifier.isPublic(constructor.modifiers)

override val isProtected: Boolean
get() = Modifier.isProtected(constructor.modifiers)

override val isPrivate: Boolean
get() = Modifier.isPrivate(constructor.modifiers)

override val parameter: List<LazyAnnotatedClass>
get() = parameterLocal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ class InstantClassField(owner: Class<*>, private val field: Field) : JavaClassFi
override val type: LazyClass
get() = InstantClass(this.field.type)

override val isTransient: Boolean
get() = Modifier.isTransient(this.field.modifiers)

override val isStatic: Boolean
get() = Modifier.isStatic(this.field.modifiers)

override val isFinal: Boolean
get() = Modifier.isFinal(this.field.modifiers)

override val isPublic: Boolean
get() = Modifier.isPublic(this.field.modifiers)

override val isProtected: Boolean
get() = Modifier.isProtected(this.field.modifiers)

override val isPrivate: Boolean
get() = Modifier.isPrivate(this.field.modifiers)

override val annotations: List<ClassAnnotation>
get() = annotationsLocal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ class InstantClassMethod(owner: Class<*>, private val method: Method) : JavaClas
override val isStatic: Boolean
get() = Modifier.isStatic(method.modifiers)

override val isFinal: Boolean
get() = Modifier.isFinal(method.modifiers)

override val isPublic: Boolean
get() = Modifier.isPublic(method.modifiers)

override val isProtected: Boolean
get() = Modifier.isProtected(method.modifiers)

override val isPrivate: Boolean
get() = Modifier.isPrivate(method.modifiers)

override val isNative: Boolean
get() = Modifier.isNative(method.modifiers)

override val isAbstract: Boolean
get() = Modifier.isAbstract(method.modifiers)

override val isVolatile: Boolean
get() = Modifier.isVolatile(method.modifiers)

override val isSynchronized: Boolean
get() = Modifier.isSynchronized(method.modifiers)

override fun toString(): String {
return "InstantClassMethod(method=$method)"
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
java
`maven-publish`
id("org.jetbrains.kotlin.jvm") version "1.5.10" apply false
id("org.jetbrains.kotlin.jvm") version "1.8.22" apply false
id("org.tabooproject.shrinkingkt") version "1.0.6" apply false
}

Expand Down
8 changes: 6 additions & 2 deletions reflex/src/main/kotlin/org/tabooproject/reflex/ReflexClass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ReflexClass(val structure: ClassStructure) {
try {
superclass?.getMethod(name, true, remap, *parameter) ?: throw ex
} catch (ex: NoSuchMethodException) {
interfaces.forEach { kotlin.runCatching { return it.getMethod(name, true, remap, *parameter) } }
interfaces.forEach { runCatching { return it.getMethod(name, true, remap, *parameter) } }
throw ex
}
} else {
Expand All @@ -61,8 +61,12 @@ class ReflexClass(val structure: ClassStructure) {
companion object {

private val analyseMap = ConcurrentHashMap<String, ReflexClass>()

fun of(clazz: Class<*>): ReflexClass {
return of(clazz, true)
}

fun of(clazz: Class<*>, saving: Boolean = true): ReflexClass {
fun of(clazz: Class<*>, saving: Boolean): ReflexClass {
if (saving && analyseMap.containsKey(clazz.name)) {
return analyseMap[clazz.name]!!
}
Expand Down

0 comments on commit d9d0cbe

Please sign in to comment.