@@ -8,6 +8,7 @@ import io.github.danielnaczo.python3parser.model.expr.atoms.Name
8
8
import io.github.danielnaczo.python3parser.model.expr.atoms.Num
9
9
import io.github.danielnaczo.python3parser.model.expr.atoms.Str
10
10
import io.github.danielnaczo.python3parser.model.mods.Module
11
+ import io.github.danielnaczo.python3parser.model.stmts.Statement
11
12
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.ClassDef
12
13
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.functionStmts.FunctionDef
13
14
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.functionStmts.parameters.Parameter
@@ -86,8 +87,7 @@ class PythonMethodBody(private val ast: FunctionDef): PythonMethod {
86
87
}
87
88
88
89
override fun asString (): String {
89
- val modulePrettyPrintVisitor = ModulePrettyPrintVisitor ()
90
- return modulePrettyPrintVisitor.visitModule(Module (listOf (ast)), IndentationPrettyPrint (0 ))
90
+ return astToString(ast)
91
91
}
92
92
93
93
override fun ast (): FunctionDef {
@@ -98,6 +98,11 @@ class PythonMethodBody(private val ast: FunctionDef): PythonMethod {
98
98
fun typeAsStringToClassId (typeAsString : String ): ClassId = ClassId (typeAsString)
99
99
100
100
fun annotationToString (annotation : Optional <Expression >): String? =
101
- if (annotation.isPresent) (annotation.get() as ? Name )?.id?.name else null
101
+ if (annotation.isPresent) astToString (annotation.get()) else null
102
102
}
103
103
}
104
+
105
+ fun astToString (stmt : Statement ): String {
106
+ val modulePrettyPrintVisitor = ModulePrettyPrintVisitor ()
107
+ return modulePrettyPrintVisitor.visitModule(Module (listOf (stmt)), IndentationPrettyPrint (0 ))
108
+ }
0 commit comments