Skip to content

Commit

Permalink
feat: <go> add basic struct func call support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 12, 2020
1 parent d988c39 commit f2fc942
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() {
codeFunction.MultipleReturns = this.buildReturnTypeFromSignature(codeFunction, ctx.signature())
codeFunction.Parameters = this.buildParameters(ctx.signature().parameters())

val receiverName = this.getStructNameFromReceiver(ctx.receiver().parameters())!!

this.addReceiverToStruct(receiverName, codeFunction)
currentFunction = codeFunction
}

override fun exitMethodDecl(ctx: GoParser.MethodDeclContext?) {
// defaultNode.Functions += currentFunction
// currentFunction = CodeFunction()
val receiverName = this.getStructNameFromReceiver(ctx!!.receiver().parameters())!!
this.addReceiverToStruct(receiverName, currentFunction)
currentFunction = CodeFunction()
}

private fun addReceiverToStruct(receiverName: String, codeFunction: CodeFunction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,29 @@ func get(x int, y int) (int, int) {
assertEquals(codeFile.DataStructures[0].Functions[0].Parameters[0].TypeType, "int")
}

@Test
internal fun shouldIdentifyStructFuncCall() {
var code = """
package main
import "fmt"
type Animal struct {
Age int
}
func (a *Animal) Move() {
fmt.Println("Animal moved")
}
"""
val codeFile = GoAnalyser().analysis(code, "")
assertEquals(codeFile.DataStructures.size, 1)
assertEquals(codeFile.DataStructures[0].Functions.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls[0].NodeName, "fmt.Println")
assertEquals(codeFile.DataStructures[0].Functions[0].FunctionCalls[0].Parameters.size, 1)
}

@Test
internal fun shouldIdentifyFuncCall() {
var code = """
Expand Down

0 comments on commit f2fc942

Please # to comment.