diff --git a/pkg/service/service.go b/pkg/service/service.go index ca647d4..fc715a4 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -472,23 +472,6 @@ func handleIfStmt(stmt *ast.IfStmt) string { return code } -func handleImportSpec(spec ast.Spec) string { - s := spec.(*ast.ImportSpec) - code := "" - if s.Name != nil { - name := handleIdent(s.Name) - if val, ok := mapping[name]; ok { - name = val - } - if name != "" { - if name != "controller" { - code = "#include <" + name + ".h>\n" - } - } - } - return code -} - func handleSelectorExpr(expr ast.Expr) string { s := expr.(*ast.SelectorExpr) code := "" @@ -504,21 +487,6 @@ func handleSelectorExpr(expr ast.Expr) string { return code } -func handleSpecs(specs []ast.Spec) string { - code := "" - for _, spec := range specs { - switch spec.(type) { - case *ast.ImportSpec: - code += handleImportSpec(spec) - case *ast.ValueSpec: - code += handleValueSpec(spec) + ";" - case *ast.TypeSpec: - code += handleTypeSpec(spec) - } - } - return code -} - func handleStmt(stmt ast.Stmt, standaloneAssignment bool) string { code := "" switch s := stmt.(type) { diff --git a/pkg/service/spec.go b/pkg/service/spec.go new file mode 100644 index 0000000..c69edc3 --- /dev/null +++ b/pkg/service/spec.go @@ -0,0 +1,37 @@ +package service + +import ( + "go/ast" +) + +func handleSpecs(specs []ast.Spec) string { + code := "" + for _, spec := range specs { + switch spec.(type) { + case *ast.ImportSpec: + code += handleImportSpec(spec) + case *ast.ValueSpec: + code += handleValueSpec(spec) + ";" + case *ast.TypeSpec: + code += handleTypeSpec(spec) + } + } + return code +} + +func handleImportSpec(spec ast.Spec) string { + s := spec.(*ast.ImportSpec) + code := "" + if s.Name != nil { + name := handleIdent(s.Name) + if val, ok := mapping[name]; ok { + name = val + } + if name != "" { + if name != "controller" { + code = "#include <" + name + ".h>\n" + } + } + } + return code +}