Skip to content

Commit

Permalink
feat: <go> add basic return type support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 12, 2020
1 parent 88557dc commit 457648d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() {

val result = ctx.signature().result()
if (result != null) {
println("enterMethodDecl -> " + result.text)
val returnType = CodeProperty(
TypeType = result.text,
TypeValue = ""
)
codeFunction.MultipleReturns += returnType
}

this.buildParameters(ctx.signature().parameters())

val receiverName = this.getTypeNameFromReceiver(ctx.receiver().parameters())!!
Expand All @@ -80,8 +85,6 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() {
when (typeChild::class.java.simpleName) {
"StructTypeContext" -> {
buildStruct(identifyName, typeChild)


}
else -> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,30 @@ func (a *Animal) Move() {
val codeFile = GoAnalyser().analysis(code, "")
assertEquals(codeFile.DataStructures.size, 1)
assertEquals(codeFile.DataStructures[0].NodeName, "Animal")
println(codeFile.DataStructures[0])
assertEquals(codeFile.DataStructures[0].Fields.size, 1)
assertEquals(codeFile.DataStructures[0].Functions.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].Name, "Move")
}

@Test
internal fun shouldIdentifyStructFunctionReturnType() {
var code = """
package main
import "fmt"
type Animal struct {
Age int
}
func (a *Animal) Move() string {
return ""
}
"""

val codeFile = GoAnalyser().analysis(code, "")
assertEquals(codeFile.DataStructures.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].MultipleReturns.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].MultipleReturns[0].TypeType, "string")
}
}

0 comments on commit 457648d

Please sign in to comment.