Skip to content

Commit e103097

Browse files
committed
fix: fix crash issues
1 parent 3ff74d2 commit e103097

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() {
118118
return structTypeCtx.fieldDecl()
119119
.map { field ->
120120
CodeField(
121-
TypeType = field.type_().text,
122-
TypeValue = field.identifierList().text
121+
TypeType = field.type_()?.text ?: "",
122+
TypeValue = field.identifierList()?.text ?: ""
123123
)
124124
}.toTypedArray()
125125
}

chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoAnalyserTest.kt

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package chapi.ast.goast
22

3-
import chapi.domain.core.CodeCall
4-
import chapi.domain.core.CodeDataStruct
5-
import chapi.domain.core.CodeFunction
6-
import chapi.domain.core.CodeProperty
3+
import chapi.domain.core.*
74
import kotlinx.serialization.encodeToString
85
import kotlinx.serialization.json.Json
6+
import org.junit.jupiter.api.Disabled
97
import org.junit.jupiter.api.Test
8+
import java.io.File
109
import kotlin.test.assertEquals
1110

1211
internal class GoAnalyserTest {
@@ -39,4 +38,23 @@ func main() {
3938
)
4039
assertEquals(Json.encodeToString(value), Json.encodeToString(expect))
4140
}
41+
42+
@Test
43+
@Disabled
44+
fun analysisByDir() {
45+
val dir = "/iam"
46+
val codeContainer = GoAnalyser().analysisByDir(dir)
47+
println(codeContainer)
48+
}
49+
}
50+
51+
private fun GoAnalyser.analysisByDir(dir: String): List<CodeContainer> {
52+
val codeContainers = mutableListOf<CodeContainer>()
53+
val files = File(dir).walkTopDown().filter { it.isFile && it.extension == "go" }.toList()
54+
files.forEach {
55+
println(it.absolutePath)
56+
val codeContainer = analysis(it.readText(), it.name)
57+
codeContainers.add(codeContainer)
58+
}
59+
return codeContainers
4260
}

0 commit comments

Comments
 (0)