Чистка: Value обработчики вынесены в отдельный файл
Этот коммит содержится в:
родитель
7aef2b730b
коммит
55085ceb4f
2 изменённых файлов: 54 добавлений и 49 удалений
|
@ -606,52 +606,3 @@ func handleReturnStmt(stmt *ast.ReturnStmt) string {
|
||||||
code += ";"
|
code += ";"
|
||||||
return 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
|
|
||||||
}
|
|
||||||
|
|
54
pkg/service/value.go
Обычный файл
54
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
|
||||||
|
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче