refactor: use magic to hide lint on non-public, inline api

- remove all YukiPrivateApi and @PublishedApi
This commit is contained in:
2023-09-27 18:01:55 +08:00
parent 5093caf46e
commit 6704b06dfa
44 changed files with 63 additions and 250 deletions

View File

@@ -13,7 +13,7 @@ You can use the **Chrome Translation Plugin** to translate entire pages for refe
# CurrentClass <span class="symbol">- class</span>
```kotlin:no-line-numbers
class CurrentClass internal constructor(internal val classSet: Class<*>, internal val instance: Any)
class CurrentClass internal constructor(private val classSet: Class<*>, internal val instance: Any)
```
**Change Records**
@@ -129,7 +129,7 @@ inline fun method(initiate: MethodConditions): MethodFinder.Result.Instance
## SuperClass <span class="symbol">- class</span>
```kotlin:no-line-numbers
inner class SuperClass internal constructor(internal val superClassSet: Class<*>)
inner class SuperClass internal constructor(private val superClassSet: Class<*>)
```
**Change Records**

View File

@@ -13,7 +13,7 @@ You can use the **Chrome Translation Plugin** to translate entire pages for refe
# ConstructorRules <span class="symbol">- class</span>
```kotlin:no-line-numbers
class ConstructorRules internal constructor(internal val rulesData: ConstructorRulesData) : BaseRules
class ConstructorRules internal constructor(private val rulesData: ConstructorRulesData) : BaseRules
```
**Change Records**

View File

@@ -13,7 +13,7 @@ You can use the **Chrome Translation Plugin** to translate entire pages for refe
# FieldRules <span class="symbol">- class</span>
```kotlin:no-line-numbers
class FieldRules internal constructor(internal val rulesData: FieldRulesData) : BaseRules
class FieldRules internal constructor(private val rulesData: FieldRulesData) : BaseRules
```
**Change Records**

View File

@@ -13,7 +13,7 @@ You can use the **Chrome Translation Plugin** to translate entire pages for refe
# MemberRules <span class="symbol">- class</span>
```kotlin:no-line-numbers
class MemberRules internal constructor(internal val rulesData: MemberRulesData) : BaseRules
class MemberRules internal constructor(private val rulesData: MemberRulesData) : BaseRules
```
**Change Records**

View File

@@ -13,7 +13,7 @@ You can use the **Chrome Translation Plugin** to translate entire pages for refe
# MethodRules <span class="symbol">- class</span>
```kotlin:no-line-numbers
class MethodRules internal constructor(internal val rulesData: MethodRulesData) : BaseRules
class MethodRules internal constructor(private val rulesData: MethodRulesData) : BaseRules
```
**Change Records**

View File

@@ -281,7 +281,7 @@ field {
## Result <span class="symbol">- class</span>
```kotlin:no-line-numbers
inner class Result internal constructor(internal val isNoSuch: Boolean, private val throwable: Throwable?) : BaseResult
inner class Result internal constructor(internal val isNoSuch: Boolean, internal val throwable: Throwable?) : BaseResult
```
**Change Records**

View File

@@ -431,7 +431,7 @@ method {
## Result <span class="symbol">- class</span>
```kotlin:no-line-numbers
inner class Result internal constructor(internal val isNoSuch: Boolean, private val throwable: Throwable?) : BaseResult
inner class Result internal constructor(internal val isNoSuch: Boolean, internal val throwable: Throwable?) : BaseResult
```
**Change Records**

View File

@@ -5,7 +5,7 @@ pageClass: code-page
# CurrentClass <span class="symbol">- class</span>
```kotlin:no-line-numbers
class CurrentClass internal constructor(internal val classSet: Class<*>, internal val instance: Any)
class CurrentClass internal constructor(private val classSet: Class<*>, internal val instance: Any)
```
**变更记录**
@@ -121,7 +121,7 @@ inline fun method(initiate: MethodConditions): MethodFinder.Result.Instance
## SuperClass <span class="symbol">- class</span>
```kotlin:no-line-numbers
inner class SuperClass internal constructor(internal val superClassSet: Class<*>)
inner class SuperClass internal constructor(private val superClassSet: Class<*>)
```
**变更记录**

View File

@@ -5,7 +5,7 @@ pageClass: code-page
# ConstructorRules <span class="symbol">- class</span>
```kotlin:no-line-numbers
class ConstructorRules internal constructor(internal val rulesData: ConstructorRulesData) : BaseRules
class ConstructorRules internal constructor(private val rulesData: ConstructorRulesData) : BaseRules
```
**变更记录**

View File

@@ -5,7 +5,7 @@ pageClass: code-page
# FieldRules <span class="symbol">- class</span>
```kotlin:no-line-numbers
class FieldRules internal constructor(internal val rulesData: FieldRulesData) : BaseRules
class FieldRules internal constructor(private val rulesData: FieldRulesData) : BaseRules
```
**变更记录**

View File

@@ -5,7 +5,7 @@ pageClass: code-page
# MemberRules <span class="symbol">- class</span>
```kotlin:no-line-numbers
class MemberRules internal constructor(internal val rulesData: MemberRulesData) : BaseRules
class MemberRules internal constructor(private val rulesData: MemberRulesData) : BaseRules
```
**变更记录**

View File

@@ -5,7 +5,7 @@ pageClass: code-page
# MethodRules <span class="symbol">- class</span>
```kotlin:no-line-numbers
class MethodRules internal constructor(internal val rulesData: MethodRulesData) : BaseRules
class MethodRules internal constructor(private val rulesData: MethodRulesData) : BaseRules
```
**变更记录**

View File

@@ -273,7 +273,7 @@ field {
## Result <span class="symbol">- class</span>
```kotlin:no-line-numbers
inner class Result internal constructor(internal val isNoSuch: Boolean, private val throwable: Throwable?) : BaseResult
inner class Result internal constructor(internal val isNoSuch: Boolean, internal val throwable: Throwable?) : BaseResult
```
**变更记录**

View File

@@ -423,7 +423,7 @@ method {
## Result <span class="symbol">- class</span>
```kotlin:no-line-numbers
inner class Result internal constructor(internal val isNoSuch: Boolean, private val throwable: Throwable?) : BaseResult
inner class Result internal constructor(internal val isNoSuch: Boolean, internal val throwable: Throwable?) : BaseResult
```
**变更记录**

View File

@@ -11,7 +11,6 @@ project.url=https://github.com/fankes/YukiReflection
project.groupName=com.highcapable.yukireflection
project.yukireflection-core.moduleName=api
project.yukireflection-core.version="1.0.2"
project.yukireflection-core.kotlin-optIn.YukiPrivateApi=${project.groupName}.annotation.YukiPrivateApi
project.licence.name=MIT
project.licence.url=https://github.com/fankes/YukiReflection/blob/master/LICENSE
project.developer.id="0"

View File

@@ -10,21 +10,10 @@ java {
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
sourceSets {
all {
languageSettings {
optIn(property.project.yukireflection.core.kotlin.optIn.yukiPrivateApi)
}
}
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs = listOf(
"-opt-in=${property.project.yukireflection.core.kotlin.optIn.yukiPrivateApi}",
"-Xno-param-assertions",
"-Xno-call-assertions",
"-Xno-receiver-assertions"

View File

@@ -1,56 +0,0 @@
/*
* YukiReflection - An efficient Reflection API for Java and Android built in Kotlin.
* Copyright (C) 2019-2023 HighCapable
* https://github.com/fankes/YukiReflection
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* This file is created by fankes on 2022/4/3.
* This file is modified by fankes on 2023/1/21.
*/
@file:Suppress("unused")
package com.highcapable.yukireflection.annotation
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@MustBeDocumented
@Target(
AnnotationTarget.CLASS,
AnnotationTarget.CONSTRUCTOR,
AnnotationTarget.FUNCTION,
AnnotationTarget.ANNOTATION_CLASS,
AnnotationTarget.PROPERTY,
AnnotationTarget.FIELD,
AnnotationTarget.LOCAL_VARIABLE,
AnnotationTarget.VALUE_PARAMETER,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.TYPEALIAS
)
@Retention(AnnotationRetention.BINARY)
/**
* - ❗标记为不规范使用可能会引发问题的 API
*
* 此功能用于规范代码调用域 - 非调用域内的 API 将会在 IDE 中显示警告
*
* 此功能除继承和接口外不应该在这里被调用
*/
annotation class CauseProblemsApi

View File

@@ -1,54 +0,0 @@
/*
* YukiReflection - An efficient Reflection API for Java and Android built in Kotlin.
* Copyright (C) 2019-2023 HighCapable
* https://github.com/fankes/YukiReflection
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* This file is created by fankes on 2022/4/3.
* This file is modified by fankes on 2023/1/21.
*/
@file:Suppress("unused")
package com.highcapable.yukireflection.annotation
@RequiresOptIn(level = RequiresOptIn.Level.ERROR)
@MustBeDocumented
@Target(
AnnotationTarget.CLASS,
AnnotationTarget.CONSTRUCTOR,
AnnotationTarget.FUNCTION,
AnnotationTarget.ANNOTATION_CLASS,
AnnotationTarget.PROPERTY,
AnnotationTarget.FIELD,
AnnotationTarget.LOCAL_VARIABLE,
AnnotationTarget.VALUE_PARAMETER,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.TYPEALIAS
)
@Retention(AnnotationRetention.BINARY)
/**
* - ❗标记功能为私有功能性 API
*
* 此功能除继承和接口外不应该在这里被调用
*/
internal annotation class YukiPrivateApi

View File

@@ -26,7 +26,7 @@
* This file is created by fankes on 2022/4/4.
* This file is modified by fankes on 2023/1/21.
*/
@file:Suppress("unused")
@file:Suppress("unused", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
package com.highcapable.yukireflection.bean
@@ -43,11 +43,10 @@ import com.highcapable.yukireflection.finder.type.factory.MethodConditions
* @param classSet 当前实例的 [Class]
* @param instance 当前实例本身
*/
class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val classSet: Class<*>, @PublishedApi internal val instance: Any) {
class CurrentClass internal constructor(private val classSet: Class<*>, internal val instance: Any) {
/** 是否开启忽略错误警告功能 */
@PublishedApi
internal var isShutErrorPrinting = false
internal var isIgnoreErrorLogs = false
/**
* 获得当前 [classSet] 的 [Class.getName]
@@ -89,14 +88,14 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val
* @param initiate 查找方法体
* @return [FieldFinder.Result.Instance]
*/
inline fun field(initiate: FieldConditions) = classSet.field(initiate).result { if (isShutErrorPrinting) ignored() }.get(instance)
inline fun field(initiate: FieldConditions) = classSet.field(initiate).result { if (isIgnoreErrorLogs) ignored() }.get(instance)
/**
* 调用当前实例中的方法
* @param initiate 查找方法体
* @return [MethodFinder.Result.Instance]
*/
inline fun method(initiate: MethodConditions) = classSet.method(initiate).result { if (isShutErrorPrinting) ignored() }.get(instance)
inline fun method(initiate: MethodConditions) = classSet.method(initiate).result { if (isIgnoreErrorLogs) ignored() }.get(instance)
/**
* 当前类的父类实例的类操作对象
@@ -104,7 +103,7 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val
* - ❗请使用 [superClass] 方法来获取 [SuperClass]
* @param superClassSet 父类 [Class] 对象
*/
inner class SuperClass internal constructor(@PublishedApi internal val superClassSet: Class<*>) {
inner class SuperClass internal constructor(private val superClassSet: Class<*>) {
/**
* 获得当前 [classSet] 中父类的 [Class.getName]
@@ -140,15 +139,14 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val
* @param initiate 查找方法体
* @return [FieldFinder.Result.Instance]
*/
inline fun field(initiate: FieldConditions) = superClassSet.field(initiate).result { if (isShutErrorPrinting) ignored() }.get(instance)
inline fun field(initiate: FieldConditions) = superClassSet.field(initiate).result { if (isIgnoreErrorLogs) ignored() }.get(instance)
/**
* 调用父类实例中的方法
* @param initiate 查找方法体
* @return [MethodFinder.Result.Instance]
*/
inline fun method(initiate: MethodConditions) =
superClassSet.method(initiate).result { if (isShutErrorPrinting) ignored() }.get(instance)
inline fun method(initiate: MethodConditions) = superClassSet.method(initiate).result { if (isIgnoreErrorLogs) ignored() }.get(instance)
override fun toString() = "CurrentClass super [$superClassSet]"
}

View File

@@ -26,7 +26,7 @@
* This file is created by fankes on 2022/9/20.
* This file is modified by fankes on 2023/1/21.
*/
@file:Suppress("unused", "UNCHECKED_CAST")
@file:Suppress("unused", "UNCHECKED_CAST", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
package com.highcapable.yukireflection.bean
@@ -36,7 +36,7 @@ import java.lang.reflect.ParameterizedType
* 当前 [Class] 的泛型父类操作对象
* @param type 类型声明实例
*/
class GenericClass internal constructor(@PublishedApi internal val type: ParameterizedType) {
class GenericClass internal constructor(private val type: ParameterizedType) {
/**
* 获得泛型参数数组下标的 [Class] 实例

View File

@@ -26,7 +26,7 @@
* This file is created by fankes on 2022/2/2.
* This file is modified by fankes on 2023/1/21.
*/
@file:Suppress("unused", "UNCHECKED_CAST")
@file:Suppress("unused", "UNCHECKED_CAST", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
package com.highcapable.yukireflection.factory
@@ -338,7 +338,7 @@ inline fun Class<*>.generic(initiate: GenericClass.() -> Unit) = generic()?.appl
* @return [CurrentClass]
*/
inline fun <reified T : Any> T.current(ignored: Boolean = false) =
CurrentClass(javaClass, instance = this).apply { isShutErrorPrinting = ignored }
CurrentClass(javaClass, instance = this).apply { isIgnoreErrorLogs = ignored }
/**
* 获得当前实例的类操作对象

View File

@@ -28,7 +28,6 @@
*/
package com.highcapable.yukireflection.finder.base
import com.highcapable.yukireflection.annotation.YukiPrivateApi
import com.highcapable.yukireflection.bean.VariousClass
import com.highcapable.yukireflection.factory.toClass
import com.highcapable.yukireflection.finder.base.data.BaseRulesData
@@ -42,20 +41,18 @@ import kotlin.math.abs
abstract class BaseFinder {
/** 当前查找条件规则数据 */
@PublishedApi
internal abstract val rulesData: BaseRulesData
/**
* 字节码、数组下标筛选数据类型
*/
@PublishedApi
internal enum class IndexConfigType { ORDER, MATCH }
/**
* 字节码、数组下标筛选实现类
* @param type 类型
*/
inner class IndexTypeCondition @PublishedApi internal constructor(private val type: IndexConfigType) {
inner class IndexTypeCondition internal constructor(private val type: IndexConfigType) {
/**
* 设置下标
@@ -124,8 +121,7 @@ abstract class BaseFinder {
* - ❗此功能交由方法体自动完成 - 你不应该手动调用此方法
* @return [BaseResult]
*/
@YukiPrivateApi
abstract fun build(): BaseResult
internal abstract fun build(): BaseResult
/**
* 返回只有异常的结果实现类
@@ -134,14 +130,12 @@ abstract class BaseFinder {
* @param throwable 异常
* @return [BaseResult]
*/
@YukiPrivateApi
abstract fun failure(throwable: Throwable?): BaseResult
internal abstract fun failure(throwable: Throwable?): BaseResult
/**
* 查找结果实现、处理类接口
*
* - ❗此功能交由方法体自动完成 - 你不应该手动继承此接口
*/
@YukiPrivateApi
interface BaseResult
internal interface BaseResult
}

View File

@@ -29,7 +29,6 @@
package com.highcapable.yukireflection.finder.base
import com.highcapable.yukireflection.YukiReflection
import com.highcapable.yukireflection.annotation.YukiPrivateApi
import com.highcapable.yukireflection.utils.debug.YukiLog
/**
@@ -77,6 +76,5 @@ abstract class ClassBaseFinder internal constructor(internal open val loaderSet:
YukiLog.error(msg = "NoClassDefFound happend in [$loaderSet]", e = e)
}
@YukiPrivateApi
override fun failure(throwable: Throwable?) = error("DexClassFinder does not contain this usage")
}

View File

@@ -43,10 +43,7 @@ import java.lang.reflect.Method
* @param tag 当前查找类的标识
* @param classSet 当前需要查找的 [Class] 实例
*/
abstract class MemberBaseFinder internal constructor(
private val tag: String,
@PublishedApi internal open val classSet: Class<*>? = null
) : BaseFinder() {
abstract class MemberBaseFinder internal constructor(private val tag: String, internal open val classSet: Class<*>? = null) : BaseFinder() {
internal companion object {
@@ -55,7 +52,6 @@ abstract class MemberBaseFinder internal constructor(
}
/** 是否使用了重查找功能 */
@PublishedApi
internal var isUsingRemedyPlan = false
/** 是否开启忽略错误警告功能 */

View File

@@ -45,7 +45,6 @@ import java.lang.reflect.Method
* @param orderIndex 字节码、数组顺序下标
* @param matchIndex 字节码、数组筛选下标
*/
@PublishedApi
internal abstract class BaseRulesData internal constructor(
var modifiers: ModifierConditions? = null,
var orderIndex: Pair<Int, Boolean>? = null,

View File

@@ -40,7 +40,6 @@ import java.lang.reflect.Member
*/
class CountRules private constructor(private val instance: Int) {
@PublishedApi
internal companion object {
/**
@@ -48,7 +47,6 @@ class CountRules private constructor(private val instance: Int) {
* @param instance 实例对象
* @return [CountRules]
*/
@PublishedApi
internal fun with(instance: Int) = CountRules(instance)
}

View File

@@ -44,7 +44,6 @@ import java.lang.reflect.Modifier
*/
class ModifierRules private constructor(private val instance: Any) {
@PublishedApi
internal companion object {
/** 当前实例数组 */
@@ -63,7 +62,6 @@ class ModifierRules private constructor(private val instance: Any) {
* @param value 唯一标识值 - 默认 0
* @return [ModifierRules]
*/
@PublishedApi
internal fun with(instance: Any, value: Long = 0) = ModifierRules(instance).apply { instances[value] = this }
}

View File

@@ -41,7 +41,6 @@ import java.lang.reflect.Member
*/
class NameRules private constructor(private val instance: String) {
@PublishedApi
internal companion object {
/**
@@ -49,7 +48,6 @@ class NameRules private constructor(private val instance: String) {
* @param instance 实例对象
* @return [NameRules]
*/
@PublishedApi
internal fun with(instance: String) = NameRules(instance)
}

View File

@@ -40,7 +40,6 @@ import java.lang.reflect.Member
*/
class ObjectRules private constructor(private val instance: Any) {
@PublishedApi
internal companion object {
/**
@@ -48,7 +47,6 @@ class ObjectRules private constructor(private val instance: Any) {
* @param instance 实例对象
* @return [ObjectRules]
*/
@PublishedApi
internal fun with(instance: Any) = ObjectRules(instance)
}

View File

@@ -26,14 +26,13 @@
* This file is created by fankes on 2022/9/4.
* This file is modified by fankes on 2023/1/25.
*/
@file:Suppress("unused", "MemberVisibilityCanBePrivate")
@file:Suppress("unused", "MemberVisibilityCanBePrivate", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
package com.highcapable.yukireflection.finder.classes
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import com.highcapable.yukireflection.annotation.YukiPrivateApi
import com.highcapable.yukireflection.factory.hasClass
import com.highcapable.yukireflection.factory.searchClass
import com.highcapable.yukireflection.factory.toClass
@@ -68,7 +67,7 @@ import java.lang.reflect.Method
* @param async 是否启用异步
* @param loaderSet 当前使用的 [ClassLoader] 实例
*/
class DexClassFinder @PublishedApi internal constructor(
class DexClassFinder internal constructor(
private val context: Context?,
internal var name: String,
internal var async: Boolean,
@@ -106,7 +105,6 @@ class DexClassFinder @PublishedApi internal constructor(
context.currentSp(versionName, versionCode)?.edit()?.clear()?.apply() ?: YukiLog.warn(msg = "Failed to clear DexClassFinder's cache")
}
@PublishedApi
override var rulesData = ClassRulesData()
/**
@@ -467,7 +465,6 @@ class DexClassFinder @PublishedApi internal constructor(
classes.takeIf { it.isNotEmpty() }?.forEach { classInstances.add(it) }
}
@YukiPrivateApi
override fun build() = runCatching {
if (loaderSet != null) {
/** 开始任务 */
@@ -500,8 +497,8 @@ class DexClassFinder @PublishedApi internal constructor(
* @param throwable 错误信息
*/
inner class Result internal constructor(
@PublishedApi internal var isNotFound: Boolean = false,
@PublishedApi internal var throwable: Throwable? = null
internal var isNotFound: Boolean = false,
internal var throwable: Throwable? = null
) : BaseResult {
/** 异步方法体回调结果 */

View File

@@ -62,7 +62,6 @@ import java.lang.reflect.Method
* @param methodRules [Method] 查找条件数据数组
* @param constroctorRules [Constructor] 查找条件数据数组
*/
@PublishedApi
internal class ClassRulesData internal constructor(
var fromPackages: ArrayList<PackageRulesData> = arrayListOf(),
var fullName: NameRulesData? = null,

View File

@@ -45,7 +45,7 @@ import java.lang.reflect.Constructor
* [Constructor] 查找条件实现类
* @param rulesData 当前查找条件规则数据
*/
class ConstructorRules internal constructor(@PublishedApi internal val rulesData: ConstructorRulesData) : BaseRules() {
class ConstructorRules internal constructor(private val rulesData: ConstructorRulesData) : BaseRules() {
/**
* 设置 [Constructor] 参数个数
@@ -160,6 +160,5 @@ class ConstructorRules internal constructor(@PublishedApi internal val rulesData
* 返回结果实现类
* @return [MemberRulesResult]
*/
@PublishedApi
internal fun build() = MemberRulesResult(rulesData)
}

View File

@@ -41,7 +41,7 @@ import java.lang.reflect.Field
* [Field] 查找条件实现类
* @param rulesData 当前查找条件规则数据
*/
class FieldRules internal constructor(@PublishedApi internal val rulesData: FieldRulesData) : BaseRules() {
class FieldRules internal constructor(private val rulesData: FieldRulesData) : BaseRules() {
/**
* 设置 [Field] 名称
@@ -105,6 +105,5 @@ class FieldRules internal constructor(@PublishedApi internal val rulesData: Fiel
* 返回结果实现类
* @return [MemberRulesResult]
*/
@PublishedApi
internal fun build() = MemberRulesResult(rulesData)
}

View File

@@ -38,7 +38,7 @@ import java.lang.reflect.Member
* [Member] 查找条件实现类
* @param rulesData 当前查找条件规则数据
*/
class MemberRules internal constructor(@PublishedApi internal val rulesData: MemberRulesData) : BaseRules() {
class MemberRules internal constructor(private val rulesData: MemberRulesData) : BaseRules() {
/**
* 设置 [Member] 标识符筛选条件
@@ -54,6 +54,5 @@ class MemberRules internal constructor(@PublishedApi internal val rulesData: Mem
* 返回结果实现类
* @return [MemberRulesResult]
*/
@PublishedApi
internal fun build() = MemberRulesResult(rulesData)
}

View File

@@ -47,7 +47,7 @@ import java.lang.reflect.Method
* [Method] 查找条件实现类
* @param rulesData 当前查找条件规则数据
*/
class MethodRules internal constructor(@PublishedApi internal val rulesData: MethodRulesData) : BaseRules() {
class MethodRules internal constructor(private val rulesData: MethodRulesData) : BaseRules() {
/**
* 设置 [Method] 名称
@@ -210,6 +210,5 @@ class MethodRules internal constructor(@PublishedApi internal val rulesData: Met
* 返回结果实现类
* @return [MemberRulesResult]
*/
@PublishedApi
internal fun build() = MemberRulesResult(rulesData)
}

View File

@@ -45,7 +45,6 @@ import java.lang.reflect.Member
*/
open class BaseRules internal constructor(internal var instance: DexClassFinder? = null) {
@PublishedApi
internal companion object {
/**
@@ -53,7 +52,6 @@ open class BaseRules internal constructor(internal var instance: DexClassFinder?
* @param instance 当前查找类实例
* @return [MemberRulesData]
*/
@PublishedApi
internal fun createMemberRules(instance: DexClassFinder) =
MemberRules(MemberRulesData().apply { instance.rulesData.memberRules.add(this) }).apply { this.instance = instance }
@@ -61,7 +59,6 @@ open class BaseRules internal constructor(internal var instance: DexClassFinder?
* 创建查找条件规则数据
* @return [FieldRulesData]
*/
@PublishedApi
internal fun createFieldRules(instance: DexClassFinder) =
FieldRules(FieldRulesData().apply { instance.rulesData.fieldRules.add(this) }).apply { this.instance = instance }
@@ -69,7 +66,6 @@ open class BaseRules internal constructor(internal var instance: DexClassFinder?
* 创建查找条件规则数据
* @return [MethodRulesData]
*/
@PublishedApi
internal fun createMethodRules(instance: DexClassFinder) =
MethodRules(MethodRulesData().apply { instance.rulesData.methodRules.add(this) }).apply { this.instance = instance }
@@ -77,7 +73,6 @@ open class BaseRules internal constructor(internal var instance: DexClassFinder?
* 创建查找条件规则数据
* @return [ConstructorRulesData]
*/
@PublishedApi
internal fun createConstructorRules(instance: DexClassFinder) =
ConstructorRules(ConstructorRulesData().apply { instance.rulesData.constroctorRules.add(this) }).apply { this.instance = instance }
}

View File

@@ -26,11 +26,10 @@
* This file is created by fankes on 2022/2/4.
* This file is modified by fankes on 2023/1/21.
*/
@file:Suppress("unused", "MemberVisibilityCanBePrivate", "UNCHECKED_CAST", "KotlinConstantConditions")
@file:Suppress("unused", "MemberVisibilityCanBePrivate", "UNCHECKED_CAST", "KotlinConstantConditions", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
package com.highcapable.yukireflection.finder.members
import com.highcapable.yukireflection.annotation.YukiPrivateApi
import com.highcapable.yukireflection.bean.VariousClass
import com.highcapable.yukireflection.factory.hasExtends
import com.highcapable.yukireflection.finder.base.BaseFinder
@@ -53,10 +52,8 @@ import java.lang.reflect.Constructor
* 可通过指定类型查找指定 [Constructor] 或一组 [Constructor]
* @param classSet 当前需要查找的 [Class] 实例
*/
class ConstructorFinder @PublishedApi internal constructor(@PublishedApi override val classSet: Class<*>? = null) :
MemberBaseFinder(tag = "Constructor", classSet) {
class ConstructorFinder internal constructor(override val classSet: Class<*>? = null) : MemberBaseFinder(tag = "Constructor", classSet) {
@PublishedApi
override var rulesData = ConstructorRulesData()
/** 当前使用的 [classSet] */
@@ -252,7 +249,6 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
}
}
@YukiPrivateApi
override fun build() = runCatching {
internalBuild()
Result()
@@ -261,7 +257,6 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
Result(isNoSuch = true, it)
}
@YukiPrivateApi
override fun failure(throwable: Throwable?) = Result(isNoSuch = true, throwable)
/**
@@ -269,11 +264,10 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
*
* 可累计失败次数直到查找成功
*/
inner class RemedyPlan @PublishedApi internal constructor() {
inner class RemedyPlan internal constructor() {
/** 失败尝试次数数组 */
@PublishedApi
internal val remedyPlans = HashSet<Pair<ConstructorFinder, Result>>()
private val remedyPlans = HashSet<Pair<ConstructorFinder, Result>>()
/**
* 创建需要重新查找的 [Constructor]
@@ -287,7 +281,6 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
Result().apply { remedyPlans.add(ConstructorFinder(classSet).apply(initiate) to this) }
/** 开始重查找 */
@PublishedApi
internal fun build() {
if (classSet == null) return
if (remedyPlans.isNotEmpty()) {
@@ -319,7 +312,7 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
*
* 可在这里处理是否成功的回调
*/
inner class Result @PublishedApi internal constructor() {
inner class Result internal constructor() {
/** 找到结果时的回调 */
internal var onFindCallback: (HashSet<Constructor<*>>.() -> Unit)? = null
@@ -340,8 +333,8 @@ class ConstructorFinder @PublishedApi internal constructor(@PublishedApi overrid
* @param throwable 错误信息
*/
inner class Result internal constructor(
@PublishedApi internal val isNoSuch: Boolean = false,
@PublishedApi internal val throwable: Throwable? = null
internal val isNoSuch: Boolean = false,
internal val throwable: Throwable? = null
) : BaseResult {
/**

View File

@@ -26,11 +26,10 @@
* This file is created by fankes on 2022/2/4.
* This file is modified by fankes on 2023/1/21.
*/
@file:Suppress("unused", "UNCHECKED_CAST", "MemberVisibilityCanBePrivate", "KotlinConstantConditions")
@file:Suppress("unused", "UNCHECKED_CAST", "MemberVisibilityCanBePrivate", "KotlinConstantConditions", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
package com.highcapable.yukireflection.finder.members
import com.highcapable.yukireflection.annotation.YukiPrivateApi
import com.highcapable.yukireflection.bean.CurrentClass
import com.highcapable.yukireflection.bean.VariousClass
import com.highcapable.yukireflection.factory.current
@@ -53,10 +52,8 @@ import java.lang.reflect.Field
* 可通过指定类型查找指定 [Field] 或一组 [Field]
* @param classSet 当前需要查找的 [Class] 实例
*/
class FieldFinder @PublishedApi internal constructor(@PublishedApi override val classSet: Class<*>? = null) :
MemberBaseFinder(tag = "Field", classSet) {
class FieldFinder internal constructor(override val classSet: Class<*>? = null) : MemberBaseFinder(tag = "Field", classSet) {
@PublishedApi
override var rulesData = FieldRulesData()
/** 当前使用的 [classSet] */
@@ -210,7 +207,6 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
}
}
@YukiPrivateApi
override fun build() = runCatching {
internalBuild()
Result()
@@ -219,7 +215,6 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
Result(isNoSuch = true, it)
}
@YukiPrivateApi
override fun failure(throwable: Throwable?) = Result(isNoSuch = true, throwable)
/**
@@ -227,11 +222,10 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
*
* 可累计失败次数直到查找成功
*/
inner class RemedyPlan @PublishedApi internal constructor() {
inner class RemedyPlan internal constructor() {
/** 失败尝试次数数组 */
@PublishedApi
internal val remedyPlans = HashSet<Pair<FieldFinder, Result>>()
private val remedyPlans = HashSet<Pair<FieldFinder, Result>>()
/**
* 创建需要重新查找的 [Field]
@@ -245,7 +239,6 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
inline fun field(initiate: FieldConditions) = Result().apply { remedyPlans.add(FieldFinder(classSet).apply(initiate) to this) }
/** 开始重查找 */
@PublishedApi
internal fun build() {
if (classSet == null) return
if (remedyPlans.isNotEmpty()) {
@@ -277,7 +270,7 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
*
* 可在这里处理是否成功的回调
*/
inner class Result @PublishedApi internal constructor() {
inner class Result internal constructor() {
/** 找到结果时的回调 */
internal var onFindCallback: (HashSet<Field>.() -> Unit)? = null
@@ -299,8 +292,8 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
* @param throwable 错误信息
*/
inner class Result internal constructor(
@PublishedApi internal val isNoSuch: Boolean = false,
private val throwable: Throwable? = null
internal val isNoSuch: Boolean = false,
internal val throwable: Throwable? = null
) : BaseResult {
/**
@@ -448,9 +441,7 @@ class FieldFinder @PublishedApi internal constructor(@PublishedApi override val
* - 若要直接获取不确定的实例对象 - 请调用 [any] 方法
* @return [Any] or null
*/
@PublishedApi
internal val self
get() = field?.get(instance)
private val self get() = field?.get(instance)
/**
* 获得当前 [Field] 自身 [self] 实例的类操作对象

View File

@@ -26,11 +26,10 @@
* This file is created by fankes on 2022/2/4.
* This file is modified by fankes on 2023/1/21.
*/
@file:Suppress("unused", "MemberVisibilityCanBePrivate", "UNCHECKED_CAST", "KotlinConstantConditions")
@file:Suppress("unused", "MemberVisibilityCanBePrivate", "UNCHECKED_CAST", "KotlinConstantConditions", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
package com.highcapable.yukireflection.finder.members
import com.highcapable.yukireflection.annotation.YukiPrivateApi
import com.highcapable.yukireflection.bean.VariousClass
import com.highcapable.yukireflection.factory.hasExtends
import com.highcapable.yukireflection.finder.base.BaseFinder
@@ -55,10 +54,8 @@ import java.lang.reflect.Method
* 可通过指定类型查找指定 [Method] 或一组 [Method]
* @param classSet 当前需要查找的 [Class] 实例
*/
class MethodFinder @PublishedApi internal constructor(@PublishedApi override val classSet: Class<*>? = null) :
MemberBaseFinder(tag = "Method", classSet) {
class MethodFinder internal constructor(override val classSet: Class<*>? = null) : MemberBaseFinder(tag = "Method", classSet) {
@PublishedApi
override var rulesData = MethodRulesData()
/** 当前使用的 [classSet] */
@@ -344,7 +341,6 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
}
}
@YukiPrivateApi
override fun build() = runCatching {
internalBuild()
Result()
@@ -353,7 +349,6 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
Result(isNoSuch = true, it)
}
@YukiPrivateApi
override fun failure(throwable: Throwable?) = Result(isNoSuch = true, throwable)
/**
@@ -361,11 +356,10 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
*
* 可累计失败次数直到查找成功
*/
inner class RemedyPlan @PublishedApi internal constructor() {
inner class RemedyPlan internal constructor() {
/** 失败尝试次数数组 */
@PublishedApi
internal val remedyPlans = HashSet<Pair<MethodFinder, Result>>()
private val remedyPlans = HashSet<Pair<MethodFinder, Result>>()
/**
* 创建需要重新查找的 [Method]
@@ -379,7 +373,6 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
inline fun method(initiate: MethodConditions) = Result().apply { remedyPlans.add(MethodFinder(classSet).apply(initiate) to this) }
/** 开始重查找 */
@PublishedApi
internal fun build() {
if (classSet == null) return
if (remedyPlans.isNotEmpty()) {
@@ -411,7 +404,7 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
*
* 可在这里处理是否成功的回调
*/
inner class Result @PublishedApi internal constructor() {
inner class Result internal constructor() {
/** 找到结果时的回调 */
internal var onFindCallback: (HashSet<Method>.() -> Unit)? = null
@@ -432,8 +425,8 @@ class MethodFinder @PublishedApi internal constructor(@PublishedApi override val
* @param throwable 错误信息
*/
inner class Result internal constructor(
@PublishedApi internal val isNoSuch: Boolean = false,
@PublishedApi internal val throwable: Throwable? = null
internal val isNoSuch: Boolean = false,
internal val throwable: Throwable? = null
) : BaseResult {
/**

View File

@@ -40,7 +40,6 @@ import java.lang.reflect.Constructor
* @param paramCountRange 参数个数范围
* @param paramCountConditions 参数个数条件
*/
@PublishedApi
internal class ConstructorRulesData internal constructor(
var paramTypes: Array<out Class<*>>? = null,
var paramTypesConditions: ObjectsConditions? = null,

View File

@@ -39,7 +39,6 @@ import java.lang.reflect.Field
* @param type 类型
* @param typeConditions 类型条件
*/
@PublishedApi
internal class FieldRulesData internal constructor(
var name: String = "",
var nameConditions: NameConditions? = null,

View File

@@ -40,7 +40,6 @@ import java.lang.reflect.Member
* @param matchCountRange 匹配的字节码个数范围
* @param matchCountConditions 匹配的字节码个数条件
*/
@PublishedApi
internal open class MemberRulesData internal constructor(
var isFindInSuper: Boolean = false,
var matchCount: Int = -1,

View File

@@ -46,7 +46,6 @@ import java.lang.reflect.Method
* @param returnType 返回值类型
* @param returnTypeConditions 返回值类型条件
*/
@PublishedApi
internal class MethodRulesData internal constructor(
var name: String = "",
var nameConditions: NameConditions? = null,

View File

@@ -68,7 +68,6 @@ import kotlin.math.abs
/**
* 这是一个对 [Class]、[Member] 查找的工具实现类
*/
@PublishedApi
internal object ReflectionTool {
/** 当前工具类的标签 */
@@ -125,7 +124,6 @@ internal object ReflectionTool {
* @return [Class]
* @throws NoClassDefFoundError 如果找不到 [Class] 或设置了错误的 [ClassLoader]
*/
@PublishedApi
internal fun findClassByName(name: String, loader: ClassLoader?, initialize: Boolean = false): Class<*> {
val uniqueCode = "[$name][$loader]"