diff --git a/chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt b/chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt index 134b6456..23a51350 100644 --- a/chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt +++ b/chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt @@ -366,6 +366,19 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() { private fun handleForPrimary(child: PrimaryExprContext, isForLocalVar: Boolean = false): String? { +// val possibleResult = handleForPrimary(first, isForLocalVar).orEmpty() + if (child.primaryExpr()?.text?.contains(".") == true) { + /// replace first.text to possibleResult + /// d.Field -> Dao.Field + val split = child.primaryExpr().text.split(".") + val withoutFirst = split.drop(1).joinToString(".") + // get first part and try to resolve in local var + val first = split.first() + if (localVars.containsKey(first)) { + return "${localVars[first]}.$withoutFirst" + } + } + val nodeName = when (val first = child.getChild(0)) { is GoParser.OperandContext -> { first.text diff --git a/chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoFullIdentListenerTest.kt b/chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoFullIdentListenerTest.kt index 642b6e75..f0180bae 100644 --- a/chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoFullIdentListenerTest.kt +++ b/chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoFullIdentListenerTest.kt @@ -546,10 +546,10 @@ func (d *Dao) GetLiveAchieve(ctx context.Context, uid int64) (achieve int64, err val functionCalls = codeFile.DataStructures.first().Functions.last().FunctionCalls val getExecFunc = functionCalls[0] - println(getExecFunc) + assertEquals(getExecFunc.FunctionName, "Userstatus") assertEquals(getExecFunc.Parameters.size, 2) - assertEquals(getExecFunc.NodeName, "Dao") + assertEquals(getExecFunc.NodeName, "Dao.rcClient") } }