Skip to content

Commit 5826e52

Browse files
committed
refactor(java-context-collection): simplify and optimize framework detection logic for improved performance and maintainability.
1 parent 306cccf commit 5826e52

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

java/src/main/kotlin/cc/unitmesh/idea/context/JavaContextCollection.kt

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
package cc.unitmesh.idea.context
22

33
import cc.unitmesh.devti.context.SimpleClassStructure
4-
import cc.unitmesh.devti.context.builder.ClassContextBuilder
54
import com.intellij.openapi.diagnostic.logger
6-
import com.intellij.openapi.util.NlsSafe
75
import com.intellij.psi.*
86
import com.intellij.psi.impl.source.PsiClassReferenceType
9-
import com.intellij.psi.search.GlobalSearchScope
10-
import com.intellij.psi.search.SearchScope
11-
import com.intellij.psi.search.searches.MethodReferencesSearch
12-
import com.intellij.psi.search.searches.ReferencesSearch
137

148
object JavaContextCollection {
159
private val logger = logger<JavaContextCollection>()
@@ -55,7 +49,7 @@ object JavaContextCollection {
5549
return psiStructureCache[clazz]!!
5650
}
5751

58-
if (isJavaBuiltin(qualifiedName) == true || isPopularFrameworks(qualifiedName) == true) {
52+
if (isJavaBuiltin(qualifiedName) == true || isPopularFramework(qualifiedName) == true) {
5953
return null
6054
}
6155

@@ -85,7 +79,7 @@ object JavaContextCollection {
8579
val resolve = (field.type as PsiClassType).resolve() ?: return@mapNotNull null
8680
if (resolve.qualifiedName == qualifiedName) return@mapNotNull null
8781

88-
if (isJavaBuiltin(resolve.qualifiedName) == true || isPopularFrameworks(resolve.qualifiedName) == true) {
82+
if (isJavaBuiltin(resolve.qualifiedName) == true || isPopularFramework(resolve.qualifiedName) == true) {
8983
return@mapNotNull null
9084
}
9185

@@ -109,14 +103,17 @@ object JavaContextCollection {
109103
return simpleClassStructure
110104
}
111105

112-
private fun isPopularFrameworks(qualifiedName: @NlsSafe String?): Boolean? {
113-
return qualifiedName?.startsWith("org.springframework") == true ||
114-
qualifiedName?.startsWith("org.apache") == true ||
115-
qualifiedName?.startsWith("org.hibernate") == true ||
116-
qualifiedName?.startsWith("org.slf4j") == true ||
117-
qualifiedName?.startsWith("org.apache") == true ||
118-
qualifiedName?.startsWith("org.junit") == true ||
119-
qualifiedName?.startsWith("org.mockito") == true
106+
private val popularFrameworks = listOf(
107+
"org.springframework",
108+
"org.apache",
109+
"org.hibernate",
110+
"org.slf4j",
111+
"org.junit",
112+
"org.mockito"
113+
)
114+
115+
private fun isPopularFramework(qualifiedName: String?): Boolean {
116+
return popularFrameworks.any { qualifiedName?.startsWith(it) == true }
120117
}
121118

122119
/**

0 commit comments

Comments
 (0)