From de13d9d1d727d92c148a1b1186806d8bf9a814a8 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 9 Nov 2022 08:29:43 +0800 Subject: [PATCH] feat(go): fix null issues --- .../chapi/ast/goast/GoFullIdentListener.kt | 17 ++++++++++------- .../kotlin/chapi/ast/goast/GoAnalyserTest.kt | 3 +-- 2 files changed, 11 insertions(+), 9 deletions(-) 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 d41e78e1..0559eec3 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 @@ -105,6 +105,7 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() { "StructTypeContext" -> { buildStruct(identifyName, typeChild) } + else -> { } @@ -171,14 +172,16 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() { NodeName = primaryExprCtx.getChild(0).text ) val argumentsContext = primaryExprCtx.getChild(1) as GoParser.ArgumentsContext - for (expressionContext in argumentsContext.expressionList().expression()) { - val codeProperty = CodeProperty( - TypeValue = expressionContext.text, - TypeType = "" - ) - codeCall.Parameters += codeProperty + + if (argumentsContext.expressionList() != null) { + for (expressionContext in argumentsContext.expressionList().expression()) { + codeCall.Parameters += CodeProperty( + TypeValue = expressionContext.text, + TypeType = "" + ) + } + currentFunction.FunctionCalls += codeCall } - currentFunction.FunctionCalls += codeCall } } } diff --git a/chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoAnalyserTest.kt b/chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoAnalyserTest.kt index a1df1568..46fd0b29 100644 --- a/chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoAnalyserTest.kt +++ b/chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoAnalyserTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test internal class GoAnalyserTest { @Test fun analysis() { - var helloworld = """ + val helloworld = """ package main import "fmt" func main() { @@ -17,7 +17,6 @@ func main() { } @Test - @Ignore fun analysis2() { val helloworldApi = """package main