Skip to content

Commit

Permalink
feat: <python> add default node support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 11, 2020
1 parent 7aa7cb0 commit d06ed8f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class PythonFullIdentListener(var fileName: String) : PythonAstBaseListener() {
private var codeFile: CodeFile = CodeFile(FullName = fileName)

private var currentNode: CodeDataStruct = CodeDataStruct()
private var defaultNode: CodeDataStruct = CodeDataStruct(
NodeName = "default"
)

override fun enterClassdef(ctx: PythonParser.ClassdefContext?) {
hasEnterClass = true
Expand Down Expand Up @@ -39,11 +42,16 @@ class PythonFullIdentListener(var fileName: String) : PythonAstBaseListener() {
}

override fun exitFuncdef(ctx: PythonParser.FuncdefContext?) {
currentNode.Functions += currentFunction
if (currentNode.NodeName == "") {
defaultNode.Functions += currentFunction
} else {
currentNode.Functions += currentFunction
}
currentFunction = CodeFunction()
}

fun getNodeInfo(): CodeFile {
this.codeFile.DataStructures += defaultNode
return this.codeFile
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,17 @@ class MyServer(IInterface):
assertEquals(codeFile.DataStructures[0].Functions.size, 1)
assertEquals(codeFile.DataStructures[0].Functions[0].Name, "show")
}

@Test
internal fun shouldPutFuncToDefaultWhenNoNode() {
val code = """
def show(self):
print('Hello, World 2!')
"""

val codeFile = PythonAnalyser().analysis(code, "")
assertEquals(codeFile.DataStructures[0].NodeName, "default")
assertEquals(codeFile.DataStructures[0].Functions[0].Name, "show")
}
}

0 comments on commit d06ed8f

Please sign in to comment.