From 0d386153a25c84a6bfaecd62c9a43c8b595c8969 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Fri, 22 Sep 2023 17:12:28 +0800 Subject: [PATCH] style: optimize code --- .../annotation/CauseProblemsApi.kt | 2 +- .../annotation/YukiPrivateApi.kt | 2 +- .../yukireflection/bean/CurrentClass.kt | 2 +- .../factory/ReflectionFactory.kt | 32 +++++++++++++-- .../finder/classes/data/ClassRulesData.kt | 10 ++--- .../finder/classes/rules/MethodRules.kt | 6 ++- .../finder/members/MethodFinder.kt | 7 +++- .../members/data/ConstructorRulesData.kt | 2 +- .../finder/members/data/MethodRulesData.kt | 6 +-- .../finder/tools/ReflectionTool.kt | 23 ++++++++--- .../type/android/ComponentTypeFactory.kt | 2 +- .../type/android/GraphicsTypeFactory.kt | 29 ++++++++++++-- .../type/android/ViewTypeFactory.kt | 40 +++++++++++++++++-- .../type/java/VariableTypeFactory.kt | 2 +- .../yukireflection/utils/UtilsFactory.kt | 2 +- 15 files changed, 135 insertions(+), 32 deletions(-) diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/annotation/CauseProblemsApi.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/annotation/CauseProblemsApi.kt index 49879ea..18e35a6 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/annotation/CauseProblemsApi.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/annotation/CauseProblemsApi.kt @@ -26,7 +26,7 @@ * This file is created by fankes on 2022/4/3. * This file is Modified by fankes on 2023/1/21. */ -@file:Suppress("OPT_IN_IS_NOT_ENABLED", "EXPERIMENTAL_IS_NOT_ENABLED", "unused") +@file:Suppress("unused") package com.highcapable.yukireflection.annotation diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/annotation/YukiPrivateApi.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/annotation/YukiPrivateApi.kt index 8d573ea..3536c04 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/annotation/YukiPrivateApi.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/annotation/YukiPrivateApi.kt @@ -26,7 +26,7 @@ * This file is created by fankes on 2022/4/3. * This file is Modified by fankes on 2023/1/21. */ -@file:Suppress("OPT_IN_IS_NOT_ENABLED", "EXPERIMENTAL_IS_NOT_ENABLED") +@file:Suppress("unused") package com.highcapable.yukireflection.annotation diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/bean/CurrentClass.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/bean/CurrentClass.kt index 2b3b602..00bc00b 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/bean/CurrentClass.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/bean/CurrentClass.kt @@ -150,7 +150,7 @@ class CurrentClass @PublishedApi internal constructor(@PublishedApi internal val inline fun method(initiate: MethodConditions) = superClassSet.method(initiate).result { if (isShutErrorPrinting) ignored() }.get(instance) - override fun toString() = "CurrentClass super [${superClassSet}]" + override fun toString() = "CurrentClass super [$superClassSet]" } override fun toString() = "CurrentClass [$classSet]" diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/factory/ReflectionFactory.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/factory/ReflectionFactory.kt index 1f47770..07e84f7 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/factory/ReflectionFactory.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/factory/ReflectionFactory.kt @@ -39,10 +39,36 @@ import com.highcapable.yukireflection.finder.members.ConstructorFinder import com.highcapable.yukireflection.finder.members.FieldFinder import com.highcapable.yukireflection.finder.members.MethodFinder import com.highcapable.yukireflection.finder.tools.ReflectionTool -import com.highcapable.yukireflection.finder.type.factory.* -import com.highcapable.yukireflection.type.java.* +import com.highcapable.yukireflection.finder.type.factory.ClassConditions +import com.highcapable.yukireflection.finder.type.factory.ConstructorConditions +import com.highcapable.yukireflection.finder.type.factory.FieldConditions +import com.highcapable.yukireflection.finder.type.factory.MethodConditions +import com.highcapable.yukireflection.finder.type.factory.ModifierConditions +import com.highcapable.yukireflection.type.java.AnyClass +import com.highcapable.yukireflection.type.java.BooleanClass +import com.highcapable.yukireflection.type.java.BooleanType +import com.highcapable.yukireflection.type.java.ByteClass +import com.highcapable.yukireflection.type.java.ByteType +import com.highcapable.yukireflection.type.java.CharClass +import com.highcapable.yukireflection.type.java.CharType +import com.highcapable.yukireflection.type.java.DoubleClass +import com.highcapable.yukireflection.type.java.DoubleType +import com.highcapable.yukireflection.type.java.FloatClass +import com.highcapable.yukireflection.type.java.FloatType +import com.highcapable.yukireflection.type.java.IntClass +import com.highcapable.yukireflection.type.java.IntType +import com.highcapable.yukireflection.type.java.LongClass +import com.highcapable.yukireflection.type.java.LongType +import com.highcapable.yukireflection.type.java.ShortClass +import com.highcapable.yukireflection.type.java.ShortType +import com.highcapable.yukireflection.type.java.UnitClass +import com.highcapable.yukireflection.type.java.UnitType import dalvik.system.BaseDexClassLoader -import java.lang.reflect.* +import java.lang.reflect.Constructor +import java.lang.reflect.Field +import java.lang.reflect.Member +import java.lang.reflect.Method +import java.lang.reflect.ParameterizedType /** * 写出当前 [ClassLoader] 下所有 [Class] 名称数组 diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/classes/data/ClassRulesData.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/classes/data/ClassRulesData.kt index 142872d..d776ba6 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/classes/data/ClassRulesData.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/classes/data/ClassRulesData.kt @@ -172,11 +172,11 @@ internal class ClassRulesData internal constructor( override val isInitialize get() = super.isInitialize || fromPackages.isNotEmpty() || fullName != null || simpleName != null || singleName != null || - fullNameConditions != null || simpleNameConditions != null || singleNameConditions != null || isAnonymousClass != null || - isNoExtendsClass != null || isNoImplementsClass != null || extendsClass.isNotEmpty() || enclosingClass.isNotEmpty() || - memberRules.isNotEmpty() || fieldRules.isNotEmpty() || methodRules.isNotEmpty() || constroctorRules.isNotEmpty() + fullNameConditions != null || simpleNameConditions != null || singleNameConditions != null || isAnonymousClass != null || + isNoExtendsClass != null || isNoImplementsClass != null || extendsClass.isNotEmpty() || enclosingClass.isNotEmpty() || + memberRules.isNotEmpty() || fieldRules.isNotEmpty() || methodRules.isNotEmpty() || constroctorRules.isNotEmpty() override fun toString() = "[$fromPackages][$fullName][$simpleName][$singleName][$fullNameConditions][$simpleNameConditions]" + - "[$singleNameConditions][$modifiers][$isAnonymousClass][$isNoExtendsClass][$isNoImplementsClass][$extendsClass][$implementsClass]" + - "[$enclosingClass][$memberRules][$fieldRules][$methodRules][$constroctorRules]" + super.toString() + "[$singleNameConditions][$modifiers][$isAnonymousClass][$isNoExtendsClass][$isNoImplementsClass][$extendsClass][$implementsClass]" + + "[$enclosingClass][$memberRules][$fieldRules][$methodRules][$constroctorRules]" + super.toString() } \ No newline at end of file diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/classes/rules/MethodRules.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/classes/rules/MethodRules.kt index 9f89df7..ed6bc74 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/classes/rules/MethodRules.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/classes/rules/MethodRules.kt @@ -34,7 +34,11 @@ import com.highcapable.yukireflection.bean.VariousClass import com.highcapable.yukireflection.finder.classes.rules.base.BaseRules import com.highcapable.yukireflection.finder.classes.rules.result.MemberRulesResult import com.highcapable.yukireflection.finder.members.data.MethodRulesData -import com.highcapable.yukireflection.finder.type.factory.* +import com.highcapable.yukireflection.finder.type.factory.CountConditions +import com.highcapable.yukireflection.finder.type.factory.ModifierConditions +import com.highcapable.yukireflection.finder.type.factory.NameConditions +import com.highcapable.yukireflection.finder.type.factory.ObjectConditions +import com.highcapable.yukireflection.finder.type.factory.ObjectsConditions import com.highcapable.yukireflection.type.defined.UndefinedType import com.highcapable.yukireflection.type.defined.VagueType import java.lang.reflect.Method diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/MethodFinder.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/MethodFinder.kt index a5a3e95..dc953b5 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/MethodFinder.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/MethodFinder.kt @@ -37,7 +37,12 @@ import com.highcapable.yukireflection.finder.base.BaseFinder import com.highcapable.yukireflection.finder.base.MemberBaseFinder import com.highcapable.yukireflection.finder.members.data.MethodRulesData import com.highcapable.yukireflection.finder.tools.ReflectionTool -import com.highcapable.yukireflection.finder.type.factory.* +import com.highcapable.yukireflection.finder.type.factory.CountConditions +import com.highcapable.yukireflection.finder.type.factory.MethodConditions +import com.highcapable.yukireflection.finder.type.factory.ModifierConditions +import com.highcapable.yukireflection.finder.type.factory.NameConditions +import com.highcapable.yukireflection.finder.type.factory.ObjectConditions +import com.highcapable.yukireflection.finder.type.factory.ObjectsConditions import com.highcapable.yukireflection.log.yLoggerW import com.highcapable.yukireflection.type.defined.UndefinedType import com.highcapable.yukireflection.type.defined.VagueType diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/data/ConstructorRulesData.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/data/ConstructorRulesData.kt index 97481c4..16bc2a5 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/data/ConstructorRulesData.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/data/ConstructorRulesData.kt @@ -62,7 +62,7 @@ internal class ConstructorRulesData internal constructor( override val isInitialize get() = super.isInitializeOfSuper || paramTypes != null || paramTypesConditions != null || paramCount >= 0 || - paramCountRange.isEmpty().not() || paramCountConditions != null + paramCountRange.isEmpty().not() || paramCountConditions != null override fun toString() = "[$paramTypes][$paramTypesConditions][$paramCount][$paramCountRange]" + super.toString() } \ No newline at end of file diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/data/MethodRulesData.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/data/MethodRulesData.kt index afdb389..4e9f2cb 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/data/MethodRulesData.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/members/data/MethodRulesData.kt @@ -76,9 +76,9 @@ internal class MethodRulesData internal constructor( override val isInitialize get() = super.isInitializeOfSuper || name.isNotBlank() || nameConditions != null || paramTypes != null || paramTypesConditions != null || - paramCount >= 0 || paramCountRange.isEmpty().not() || paramCountConditions != null || - returnType != null || returnTypeConditions != null + paramCount >= 0 || paramCountRange.isEmpty().not() || paramCountConditions != null || + returnType != null || returnTypeConditions != null override fun toString() = "[$name][$nameConditions][$paramTypes][$paramTypesConditions][$paramCount]" + - "[$paramCountRange][$returnType][$returnTypeConditions]" + super.toString() + "[$paramCountRange][$returnType][$returnTypeConditions]" + super.toString() } \ No newline at end of file diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/tools/ReflectionTool.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/tools/ReflectionTool.kt index 1a3e11a..3950469 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/tools/ReflectionTool.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/finder/tools/ReflectionTool.kt @@ -32,7 +32,12 @@ package com.highcapable.yukireflection.finder.tools import android.util.ArrayMap import com.highcapable.yukireflection.YukiReflection -import com.highcapable.yukireflection.factory.* +import com.highcapable.yukireflection.factory.classOf +import com.highcapable.yukireflection.factory.current +import com.highcapable.yukireflection.factory.field +import com.highcapable.yukireflection.factory.hasClass +import com.highcapable.yukireflection.factory.hasExtends +import com.highcapable.yukireflection.factory.toClass import com.highcapable.yukireflection.finder.base.data.BaseRulesData import com.highcapable.yukireflection.finder.classes.data.ClassRulesData import com.highcapable.yukireflection.finder.members.data.ConstructorRulesData @@ -46,13 +51,19 @@ import com.highcapable.yukireflection.type.java.DalvikBaseDexClassLoader import com.highcapable.yukireflection.type.java.NoClassDefFoundErrorClass import com.highcapable.yukireflection.type.java.NoSuchFieldErrorClass import com.highcapable.yukireflection.type.java.NoSuchMethodErrorClass -import com.highcapable.yukireflection.utils.* +import com.highcapable.yukireflection.utils.conditions +import com.highcapable.yukireflection.utils.findLastIndex +import com.highcapable.yukireflection.utils.lastIndex +import com.highcapable.yukireflection.utils.let +import com.highcapable.yukireflection.utils.runOrFalse +import com.highcapable.yukireflection.utils.takeIf +import com.highcapable.yukireflection.utils.value import dalvik.system.BaseDexClassLoader import java.lang.reflect.Constructor import java.lang.reflect.Field import java.lang.reflect.Member import java.lang.reflect.Method -import java.util.* +import java.util.Enumeration import kotlin.math.abs /** @@ -539,7 +550,7 @@ internal object ReflectionTool { * @return [Boolean] 返回是否成立 */ private fun Pair?.compare(need: Int, last: Int) = this == null || ((first >= 0 && first == need && second) || - (first < 0 && abs(first) == (last - need) && second) || (last == need && second.not())) + (first < 0 && abs(first) == (last - need) && second) || (last == need && second.not())) /** * 比较位置下标的前后顺序 @@ -550,8 +561,8 @@ internal object ReflectionTool { private fun Pair?.compare(need: Int, last: Int, result: (Boolean) -> Unit) { if (this == null) return ((first >= 0 && first == need && second) || - (first < 0 && abs(first) == (last - need) && second) || - (last == need && second.not())).also(result) + (first < 0 && abs(first) == (last - need) && second) || + (last == need && second.not())).also(result) } /** diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/ComponentTypeFactory.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/ComponentTypeFactory.kt index b29692a..84ce962 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/ComponentTypeFactory.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/ComponentTypeFactory.kt @@ -30,7 +30,7 @@ package com.highcapable.yukireflection.type.android -import android.app.* +import android.app.* // ktlint-disable no-wildcard-imports import android.appwidget.AppWidgetHost import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/GraphicsTypeFactory.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/GraphicsTypeFactory.kt index a71f6bf..09d4851 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/GraphicsTypeFactory.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/GraphicsTypeFactory.kt @@ -30,10 +30,33 @@ package com.highcapable.yukireflection.type.android -import android.graphics.* -import android.graphics.drawable.* +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Canvas +import android.graphics.ColorMatrix +import android.graphics.ColorMatrixColorFilter +import android.graphics.Matrix +import android.graphics.NinePatch +import android.graphics.Outline +import android.graphics.Paint +import android.graphics.Point +import android.graphics.PointF +import android.graphics.Rect +import android.graphics.RectF +import android.graphics.Typeface +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.ColorDrawable +import android.graphics.drawable.Drawable +import android.graphics.drawable.GradientDrawable +import android.graphics.drawable.Icon import android.os.Build -import android.text.* +import android.text.Editable +import android.text.GetChars +import android.text.Spannable +import android.text.SpannableStringBuilder +import android.text.TextPaint +import android.text.TextUtils +import android.text.TextWatcher import android.util.Size import android.util.SizeF import com.highcapable.yukireflection.factory.classOf diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/ViewTypeFactory.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/ViewTypeFactory.kt index 9eeabd1..1f9575a 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/ViewTypeFactory.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/android/ViewTypeFactory.kt @@ -30,17 +30,51 @@ package com.highcapable.yukireflection.type.android -import android.animation.* +import android.animation.Animator +import android.animation.AnimatorSet +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import android.animation.ValueAnimator import android.appwidget.AppWidgetHostView import android.util.AttributeSet -import android.view.* +import android.view.GestureDetector +import android.view.LayoutInflater +import android.view.MotionEvent +import android.view.Surface +import android.view.SurfaceView +import android.view.TextureView +import android.view.View +import android.view.ViewGroup +import android.view.ViewParent +import android.view.ViewPropertyAnimator +import android.view.ViewStructure +import android.view.ViewStub import android.view.animation.AlphaAnimation import android.view.animation.Animation import android.view.animation.TranslateAnimation import android.webkit.WebView import android.webkit.WebViewClient -import android.widget.* +import android.widget.ArrayAdapter +import android.widget.AutoCompleteTextView +import android.widget.BaseAdapter +import android.widget.Button +import android.widget.CheckBox +import android.widget.CompoundButton +import android.widget.EditText +import android.widget.FrameLayout +import android.widget.ImageButton +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.ListAdapter +import android.widget.ListView +import android.widget.ProgressBar +import android.widget.RelativeLayout +import android.widget.RemoteViews import android.widget.RemoteViews.RemoteView +import android.widget.TextClock +import android.widget.TextView +import android.widget.VideoView +import android.widget.ViewAnimator import com.highcapable.yukireflection.factory.classOf /** diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/java/VariableTypeFactory.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/java/VariableTypeFactory.kt index 949448e..55349b4 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/java/VariableTypeFactory.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/type/java/VariableTypeFactory.kt @@ -40,7 +40,7 @@ import dalvik.system.InMemoryDexClassLoader import dalvik.system.PathClassLoader import org.json.JSONArray import org.json.JSONObject -import java.io.* +import java.io.* // ktlint-disable no-wildcard-imports import java.lang.ref.Reference import java.lang.ref.WeakReference import java.lang.reflect.Constructor diff --git a/yukireflection-core/src/main/java/com/highcapable/yukireflection/utils/UtilsFactory.kt b/yukireflection-core/src/main/java/com/highcapable/yukireflection/utils/UtilsFactory.kt index 769c7e5..141b4d4 100644 --- a/yukireflection-core/src/main/java/com/highcapable/yukireflection/utils/UtilsFactory.kt +++ b/yukireflection-core/src/main/java/com/highcapable/yukireflection/utils/UtilsFactory.kt @@ -199,7 +199,7 @@ internal class Conditions(internal var value: T) { */ private val result by lazy { optConditions.takeIf { it.isNotEmpty() }?.any { it } == true || - andConditions.takeIf { it.isNotEmpty() }?.any { it.not() }?.not() == true + andConditions.takeIf { it.isNotEmpty() }?.any { it.not() }?.not() == true } /**