1
1
package com.github.oldmegit.goframehelper.callUtil.orm
2
2
3
3
import com.github.oldmegit.goframehelper.callUtil.CallUtil
4
+ import com.goide.parser.GoParser.ReferenceExpression
4
5
import com.goide.psi.*
5
6
import com.goide.psi.impl.GoPsiUtil
6
7
import com.intellij.psi.PsiComment
@@ -9,6 +10,7 @@ import com.intellij.psi.ResolveState
9
10
import com.intellij.psi.util.PsiTreeUtil
10
11
import com.intellij.util.ObjectUtils
11
12
13
+
12
14
object OrmUtil : CallUtil() {
13
15
override fun getData (psiElement : PsiElement ): Map <String , Set <PsiElement >> {
14
16
return try {
@@ -125,6 +127,7 @@ object OrmUtil : CallUtil() {
125
127
// handle type GoAssignmentStatement
126
128
// for example:
127
129
// db = db.Xxx
130
+ // db = dao.Xxx
128
131
private fun doAssignmentStatement (assignmentStatement : GoAssignmentStatement ): GoStatement ? {
129
132
for (expression in assignmentStatement.leftHandExprList.expressionList) {
130
133
val psiElementRoot = expression.reference?.resolve()
@@ -139,13 +142,23 @@ object OrmUtil : CallUtil() {
139
142
// db.Xxx or dao.Xxx
140
143
private fun doSimpleStatement (simpleStatement : GoSimpleStatement ): GoStatement ? {
141
144
val declaration = simpleStatement.shortVarDeclaration
145
+
142
146
// direct return if db := db.Xxx
143
147
if (declaration != null ) {
144
148
return simpleStatement
145
149
}
146
150
147
- // db.Xxx
151
+ // get GoReferenceExpression list
148
152
val list = PsiTreeUtil .findChildrenOfType(simpleStatement, GoReferenceExpression ::class .java)
153
+ for (one in list) {
154
+ // dao.Xxx
155
+ // if statement contain dao
156
+ if (one.text == " dao" ) {
157
+ return simpleStatement
158
+ }
159
+ }
160
+
161
+ // db.Xxx
149
162
val last = list.last()
150
163
if (last.resolve() is GoVarDefinition ) {
151
164
return getStatementContainDao(last.resolve() as GoVarDefinition )
0 commit comments