diff --git a/pkg/service/class.go b/pkg/service/class.go index fe21824..3a0a352 100644 --- a/pkg/service/class.go +++ b/pkg/service/class.go @@ -120,7 +120,7 @@ func (c *class) methodImplementationToString(m *ast.FuncDecl) (code string) { code += c.name + "::" code += m.Name.String() + "(" code += handleFuncDeclParams(m.Type) - code += ") {" + code += ") {\n" if len(m.Recv.List) > 0 { n := m.Recv.List[0].Names if len(n) > 0 { @@ -130,9 +130,7 @@ func (c *class) methodImplementationToString(m *ast.FuncDecl) (code string) { } code += handleBlockStmt(m.Body) isInMethod = false - code += "}" - - code += "\n" + code += "}\n" return } diff --git a/pkg/service/func.go b/pkg/service/func.go index 8a14c5e..b553fea 100644 --- a/pkg/service/func.go +++ b/pkg/service/func.go @@ -53,9 +53,9 @@ func handleFunctionDeclaration(fd *ast.FuncDecl) string { addFunctionDeclaration(ft + " " + name + "(" + fp + ");") - code += ") {" + code += ") {\n" code += handleBlockStmt(fd.Body) - code += "}" + code += "}\n" return code } func shouldSkipFunction(t *ast.FuncType) (res bool) { diff --git a/pkg/service/stmt.go b/pkg/service/stmt.go index 037faf3..4dc2bbd 100644 --- a/pkg/service/stmt.go +++ b/pkg/service/stmt.go @@ -16,6 +16,7 @@ func handleBlockStmt(body *ast.BlockStmt) string { } for _, stmt := range body.List { code += handleStmt(stmt, false) + code += "\n" } return code } @@ -174,7 +175,7 @@ func handleForStmt(stmt *ast.ForStmt) string { code += ";" code += handleStmt(stmt.Post, true) } - code += ") {" + code += ") {\n" code += handleBlockStmt(stmt.Body) code += "}" return code @@ -183,10 +184,10 @@ func handleForStmt(stmt *ast.ForStmt) string { func handleIfStmt(stmt *ast.IfStmt) string { cond := handleExpr(stmt.Cond) body := handleBlockStmt(stmt.Body) - code := fmt.Sprintf(`if (%s) { %s }`, cond, body) + code := fmt.Sprintf("if (%s) {\n %s }\n", cond, body) if stmt.Else != nil { tail := handleBlockStmt(stmt.Else.(*ast.BlockStmt)) - code += fmt.Sprintf(" else { %s }", tail) + code += fmt.Sprintf(" else {\n %s }\n", tail) } return code }