Skip to content

Commit f9319d1

Browse files
committed
refactor(context): simplify initialization of method and class context in VariableContext.kt
Removed unnecessary init block and directly initialized methodContext and classContext. Also removed unused import statement.
1 parent 1dcf6bf commit f9319d1

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/main/kotlin/cc/unitmesh/devti/context/VariableContext.kt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cc.unitmesh.devti.context
22

33
import cc.unitmesh.devti.context.base.NamedElementContext
4-
import com.google.gson.Gson
54
import com.intellij.openapi.application.runReadAction
65
import com.intellij.psi.PsiElement
76
import com.intellij.psi.PsiReference
@@ -18,20 +17,16 @@ class VariableContext(
1817
) : NamedElementContext(
1918
root, text, name
2019
) {
21-
private val methodContext: MethodContext?
22-
private val classContext: ClassContext?
20+
private val methodContext: MethodContext? = if (includeMethodContext && enclosingMethod != null) {
21+
MethodContextProvider(false, false).from(enclosingMethod)
22+
} else {
23+
null
24+
}
2325

24-
init {
25-
methodContext = if (includeMethodContext && enclosingMethod != null) {
26-
MethodContextProvider(false, false).from(enclosingMethod)
27-
} else {
28-
null
29-
}
30-
classContext = if (includeClassContext && enclosingClass != null) {
31-
ClassContextProvider(false).from(enclosingClass)
32-
} else {
33-
null
34-
}
26+
private val classContext: ClassContext? = if (includeClassContext && enclosingClass != null) {
27+
ClassContextProvider(false).from(enclosingClass)
28+
} else {
29+
null
3530
}
3631

3732
fun shortFormat(): String = runReadAction { root.text ?: ""}

0 commit comments

Comments
 (0)