From 55085ceb4f5d5788287ed365743c61dec4634eac Mon Sep 17 00:00:00 2001 From: Softonik Date: Mon, 22 Jan 2024 03:03:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B8=D1=81=D1=82=D0=BA=D0=B0:=20Value?= =?UTF-8?q?=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=87=D0=B8=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/service.go | 49 -------------------------------------- pkg/service/value.go | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 49 deletions(-) create mode 100644 pkg/service/value.go diff --git a/pkg/service/service.go b/pkg/service/service.go index 48b5c93..ca647d4 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -606,52 +606,3 @@ func handleReturnStmt(stmt *ast.ReturnStmt) string { code += ";" return code } - -func handleValueSpec(spec ast.Spec) string { - s := spec.(*ast.ValueSpec) - code := "" - code += handleValueSpecType(s.Type) - code += " " - code += handleValueSpecNames(s.Names) - if s.Values != nil { - code += " = " - code += handleValueSpecValues(s.Values) - } - return code -} - -func handleValueSpecNames(names []*ast.Ident) string { - code := "" - for _, name := range names { - code += handleIdent(name) - } - return code -} - -func handleValueSpecType(expr ast.Expr) string { - code := "" - switch t := expr.(type) { - case *ast.SelectorExpr: - code += handleSelectorExpr(t) - case *ast.Ident: - code += handleIdent(t) - } - return code -} - -func handleValueSpecValues(values []ast.Expr) string { - code := "" - for _, value := range values { - switch v := value.(type) { - case *ast.BasicLit: - code += handleBasicLit(v) - case *ast.BinaryExpr: - code += handleBinaryExpr(v) - case *ast.SelectorExpr: - code += handleSelectorExpr(value) - case *ast.CallExpr: - code += handleCallExpr(v) - } - } - return code -} diff --git a/pkg/service/value.go b/pkg/service/value.go new file mode 100644 index 0000000..33fc618 --- /dev/null +++ b/pkg/service/value.go @@ -0,0 +1,54 @@ +package service + +import ( + "go/ast" +) + +func handleValueSpec(spec ast.Spec) string { + s := spec.(*ast.ValueSpec) + code := "" + code += handleValueSpecType(s.Type) + code += " " + code += handleValueSpecNames(s.Names) + if s.Values != nil { + code += " = " + code += handleValueSpecValues(s.Values) + } + return code +} + +func handleValueSpecNames(names []*ast.Ident) string { + code := "" + for _, name := range names { + code += handleIdent(name) + } + return code +} + +func handleValueSpecType(expr ast.Expr) string { + code := "" + switch t := expr.(type) { + case *ast.SelectorExpr: + code += handleSelectorExpr(t) + case *ast.Ident: + code += handleIdent(t) + } + return code +} + +func handleValueSpecValues(values []ast.Expr) string { + code := "" + for _, value := range values { + switch v := value.(type) { + case *ast.BasicLit: + code += handleBasicLit(v) + case *ast.BinaryExpr: + code += handleBinaryExpr(v) + case *ast.SelectorExpr: + code += handleSelectorExpr(value) + case *ast.CallExpr: + code += handleCallExpr(v) + } + } + return code +}