From c92a73bb212901eeef5b313ef4bf41817e60a8ba Mon Sep 17 00:00:00 2001 From: tangcent Date: Sun, 15 Dec 2024 21:31:37 +0800 Subject: [PATCH] refactor: replace nullable properties with lateinit for improved initialization in CommentResolver (#1178) --- .../plugin/api/export/core/CommentResolver.kt | 46 +++++++++--------- .../build/kotlin/pluginadapterjar-classes.txt | 0 plugin-adapter/build/libs/plugin-adapter.jar | Bin 0 -> 261 bytes plugin-adapter/build/tmp/jar/MANIFEST.MF | 2 + 4 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 plugin-adapter/build/kotlin/pluginadapterjar-classes.txt create mode 100644 plugin-adapter/build/libs/plugin-adapter.jar create mode 100644 plugin-adapter/build/tmp/jar/MANIFEST.MF diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/CommentResolver.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/CommentResolver.kt index 79916f73b..f17788883 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/CommentResolver.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/CommentResolver.kt @@ -22,19 +22,19 @@ import com.itangcent.utils.emptyIf class CommentResolver { @Inject - protected val logger: Logger? = null + protected lateinit var logger: Logger @Inject - protected val ruleComputer: RuleComputer? = null + protected lateinit var ruleComputer: RuleComputer @Inject - protected val jvmClassHelper: JvmClassHelper? = null + protected lateinit var jvmClassHelper: JvmClassHelper @Inject - protected val psiClassHelper: PsiClassHelper? = null + protected lateinit var psiClassHelper: PsiClassHelper @Inject - protected val duckTypeHelper: DuckTypeHelper? = null + protected lateinit var duckTypeHelper: DuckTypeHelper fun resolveCommentForType(duckType: DuckType, context: PsiElement): String? { @@ -42,29 +42,29 @@ class CommentResolver { return null } - if (jvmClassHelper!!.isEnum(duckType)) { + if (jvmClassHelper.isEnum(duckType)) { if (duckType is SingleUnresolvedDuckType) { return resolveCommentForType(duckType.psiType(), context) } - val convertTo = ruleComputer!!.computer(ClassRuleKeys.ENUM_CONVERT, duckType, context) + val convertTo = ruleComputer.computer(ClassRuleKeys.ENUM_CONVERT, duckType, context) if (convertTo.notNullOrBlank()) { if (convertTo!!.contains("#")) { - val options = psiClassHelper!!.resolveEnumOrStatic(convertTo, context, "") + val options = psiClassHelper.resolveEnumOrStatic(convertTo, context, "") if (options.notNullOrEmpty()) { return KVUtils.getOptionDesc(options!!) } } else { - val resolveClass = duckTypeHelper!!.resolveClass(convertTo, context) + val resolveClass = duckTypeHelper.resolveClass(convertTo, context) if (resolveClass == null) { - logger!!.error("failed to resolve class:$convertTo") + logger.warn("Failed to resolve class: $convertTo") return null } - val constants = psiClassHelper!!.parseEnumConstant(resolveClass) + val constants = psiClassHelper.parseEnumConstant(resolveClass) if (constants.isEmpty()) { - logger!!.error("nothing be found at:$convertTo") + logger.debug("No constants found at: $convertTo") return null } @@ -75,10 +75,10 @@ class CommentResolver { if (duckType is SingleDuckType) { val enumClass = duckType.psiClass() - val constants = psiClassHelper!!.resolveEnumOrStatic(context, enumClass, null, "") {} + val constants = psiClassHelper.resolveEnumOrStatic(context, enumClass, null, "") {} .emptyIf { psiClassHelper.parseEnumConstant(enumClass) } if (constants.isEmpty()) { - logger!!.error("nothing be found for:${duckType.canonicalText()}") + logger.debug("No constants found for: ${duckType.canonicalText()}") return null } @@ -91,25 +91,25 @@ class CommentResolver { fun resolveCommentForType(psiType: PsiType, context: PsiElement): String? { - if (jvmClassHelper!!.isEnum(psiType)) { + if (jvmClassHelper.isEnum(psiType)) { - val convertTo = ruleComputer!!.computer(ClassRuleKeys.ENUM_CONVERT, psiType, context) + val convertTo = ruleComputer.computer(ClassRuleKeys.ENUM_CONVERT, psiType, context) if (convertTo.notNullOrBlank()) { if (convertTo!!.contains("#")) { - val options = psiClassHelper!!.resolveEnumOrStatic(convertTo, context, "") + val options = psiClassHelper.resolveEnumOrStatic(convertTo, context, "") if (options.notNullOrEmpty()) { return KVUtils.getOptionDesc(options!!) } } else { - val resolveClass = duckTypeHelper!!.resolveClass(convertTo, context) + val resolveClass = duckTypeHelper.resolveClass(convertTo, context) if (resolveClass == null) { - logger!!.error("failed to resolve class:$convertTo") + logger.warn("Failed to resolve class: $convertTo") return null } - val constants = psiClassHelper!!.parseEnumConstant(resolveClass) + val constants = psiClassHelper.parseEnumConstant(resolveClass) if (constants.isEmpty()) { - logger!!.error("nothing be found at:$convertTo") + logger.debug("No constants found at: $convertTo") return null } @@ -118,9 +118,9 @@ class CommentResolver { } val enumClass = jvmClassHelper.resolveClassInType(psiType)!! - val constants = psiClassHelper!!.resolveEnumOrStatic(context, enumClass, null, "") {} + val constants = psiClassHelper.resolveEnumOrStatic(context, enumClass, null, "") {} if (constants.isNullOrEmpty()) { - logger!!.error("nothing be found for:${psiType.canonicalText}") + logger.debug("No constants found for: ${psiType.canonicalText}") return null } diff --git a/plugin-adapter/build/kotlin/pluginadapterjar-classes.txt b/plugin-adapter/build/kotlin/pluginadapterjar-classes.txt new file mode 100644 index 000000000..e69de29bb diff --git a/plugin-adapter/build/libs/plugin-adapter.jar b/plugin-adapter/build/libs/plugin-adapter.jar new file mode 100644 index 0000000000000000000000000000000000000000..abc9510332ae2c6b25198cc6e8423eb8c4ce33ff GIT binary patch literal 261 zcmWIWW@Zs#VBp|j_`WDPk^u;qKm-tQ0~t1dKY=Ub+yi&Ilno`;EM5sr;na80S#kh5@E(|FVI9F t5MX%g2%_PxK-Y%u3XozDSkkBoB;neS+!Wx=$_7%w1ca49x(vi&004pHGS2`2 literal 0 HcmV?d00001 diff --git a/plugin-adapter/build/tmp/jar/MANIFEST.MF b/plugin-adapter/build/tmp/jar/MANIFEST.MF new file mode 100644 index 000000000..59499bce4 --- /dev/null +++ b/plugin-adapter/build/tmp/jar/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +