Skip to content

Commit

Permalink
fix: fix crash issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 25, 2022
1 parent 3ff74d2 commit e103097
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() {
return structTypeCtx.fieldDecl()
.map { field ->
CodeField(
TypeType = field.type_().text,
TypeValue = field.identifierList().text
TypeType = field.type_()?.text ?: "",
TypeValue = field.identifierList()?.text ?: ""
)
}.toTypedArray()
}
Expand Down
26 changes: 22 additions & 4 deletions chapi-ast-go/src/test/kotlin/chapi/ast/goast/GoAnalyserTest.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package chapi.ast.goast

import chapi.domain.core.CodeCall
import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeFunction
import chapi.domain.core.CodeProperty
import chapi.domain.core.*
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import java.io.File
import kotlin.test.assertEquals

internal class GoAnalyserTest {
Expand Down Expand Up @@ -39,4 +38,23 @@ func main() {
)
assertEquals(Json.encodeToString(value), Json.encodeToString(expect))
}

@Test
@Disabled
fun analysisByDir() {
val dir = "/iam"
val codeContainer = GoAnalyser().analysisByDir(dir)
println(codeContainer)
}
}

private fun GoAnalyser.analysisByDir(dir: String): List<CodeContainer> {
val codeContainers = mutableListOf<CodeContainer>()
val files = File(dir).walkTopDown().filter { it.isFile && it.extension == "go" }.toList()
files.forEach {
println(it.absolutePath)
val codeContainer = analysis(it.readText(), it.name)
codeContainers.add(codeContainer)
}
return codeContainers
}

0 comments on commit e103097

Please sign in to comment.