Skip to content

Commit ef2ae12

Browse files
committed
fixed bug with annotation parsing
1 parent 43986dd commit ef2ae12

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

utbot-python/src/main/kotlin/org/utbot/python/code/PythonCodeAPI.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import io.github.danielnaczo.python3parser.model.expr.atoms.Name
88
import io.github.danielnaczo.python3parser.model.expr.atoms.Num
99
import io.github.danielnaczo.python3parser.model.expr.atoms.Str
1010
import io.github.danielnaczo.python3parser.model.mods.Module
11+
import io.github.danielnaczo.python3parser.model.stmts.Statement
1112
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.ClassDef
1213
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.functionStmts.FunctionDef
1314
import io.github.danielnaczo.python3parser.model.stmts.compoundStmts.functionStmts.parameters.Parameter
@@ -86,8 +87,7 @@ class PythonMethodBody(private val ast: FunctionDef): PythonMethod {
8687
}
8788

8889
override fun asString(): String {
89-
val modulePrettyPrintVisitor = ModulePrettyPrintVisitor()
90-
return modulePrettyPrintVisitor.visitModule(Module(listOf(ast)), IndentationPrettyPrint(0))
90+
return astToString(ast)
9191
}
9292

9393
override fun ast(): FunctionDef {
@@ -98,6 +98,11 @@ class PythonMethodBody(private val ast: FunctionDef): PythonMethod {
9898
fun typeAsStringToClassId(typeAsString: String): ClassId = ClassId(typeAsString)
9999

100100
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
102102
}
103103
}
104+
105+
fun astToString(stmt: Statement): String {
106+
val modulePrettyPrintVisitor = ModulePrettyPrintVisitor()
107+
return modulePrettyPrintVisitor.visitModule(Module(listOf(stmt)), IndentationPrettyPrint(0))
108+
}

0 commit comments

Comments
 (0)