Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace nullable properties with lateinit for improved initialization in CommentResolver #1178

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,49 @@ 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? {

if (!duckType.isSingle()) {
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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
Empty file.
Binary file added plugin-adapter/build/libs/plugin-adapter.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions plugin-adapter/build/tmp/jar/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

Loading