refactor: rename build to append

上级 3cb2e493
...@@ -52,9 +52,9 @@ func (n *CocagoParser) Visitor(f *ast.File, fset *token.FileSet, fileName string ...@@ -52,9 +52,9 @@ func (n *CocagoParser) Visitor(f *ast.File, fset *token.FileSet, fileName string
currentStruct = trial.CodeDataStruct{} currentStruct = trial.CodeDataStruct{}
currentStruct.Name = x.Name.String() currentStruct.Name = x.Name.String()
case *ast.StructType: case *ast.StructType:
BuildStructType(currentStruct, x, &currentFile) AddStructType(currentStruct, x, &currentFile)
case *ast.FuncDecl: case *ast.FuncDecl:
BuildFunction(currentStruct, x, currentFile) AddFunction(currentStruct, x, currentFile)
} }
return true return true
}) })
...@@ -62,10 +62,7 @@ func (n *CocagoParser) Visitor(f *ast.File, fset *token.FileSet, fileName string ...@@ -62,10 +62,7 @@ func (n *CocagoParser) Visitor(f *ast.File, fset *token.FileSet, fileName string
return &currentFile return &currentFile
} }
func BuildFunction(currentStruct trial.CodeDataStruct, x *ast.FuncDecl, currentFile trial.CodeFile) { func AddFunction(currentStruct trial.CodeDataStruct, x *ast.FuncDecl, currentFile trial.CodeFile) {
codeFunc := &trial.CodeFunction{
Name: x.Name.String(),
}
recv := "" recv := ""
for _, item := range x.Recv.List { for _, item := range x.Recv.List {
switch x := item.Type.(type) { switch x := item.Type.(type) {
...@@ -74,17 +71,7 @@ func BuildFunction(currentStruct trial.CodeDataStruct, x *ast.FuncDecl, currentF ...@@ -74,17 +71,7 @@ func BuildFunction(currentStruct trial.CodeDataStruct, x *ast.FuncDecl, currentF
} }
} }
if x.Type.Params != nil { codeFunc := BuildFunction(x)
fieldList := x.Type.Params.List
properties := BuildFieldToProperty(fieldList)
codeFunc.Parameters = append(codeFunc.Parameters, properties...)
}
if x.Type.Results != nil {
fieldList := x.Type.Results.List
properties := BuildFieldToProperty(fieldList)
codeFunc.ReturnTypes = append(codeFunc.Parameters, properties...)
}
if recv != "" { if recv != "" {
member := GetMemberFromFile(currentFile, recv) member := GetMemberFromFile(currentFile, recv)
...@@ -99,6 +86,25 @@ func BuildFunction(currentStruct trial.CodeDataStruct, x *ast.FuncDecl, currentF ...@@ -99,6 +86,25 @@ func BuildFunction(currentStruct trial.CodeDataStruct, x *ast.FuncDecl, currentF
} }
} }
func BuildFunction(x *ast.FuncDecl) *trial.CodeFunction {
codeFunc := &trial.CodeFunction{
Name: x.Name.String(),
}
if x.Type.Params != nil {
fieldList := x.Type.Params.List
properties := BuildFieldToProperty(fieldList)
codeFunc.Parameters = append(codeFunc.Parameters, properties...)
}
if x.Type.Results != nil {
fieldList := x.Type.Results.List
properties := BuildFieldToProperty(fieldList)
codeFunc.ReturnTypes = append(codeFunc.Parameters, properties...)
}
return codeFunc
}
func createMember() { func createMember() {
} }
...@@ -128,7 +134,7 @@ func BuildFieldToProperty(fieldList []*ast.Field) []trial.CodeProperty { ...@@ -128,7 +134,7 @@ func BuildFieldToProperty(fieldList []*ast.Field) []trial.CodeProperty {
return properties return properties
} }
func BuildStructType(currentStruct trial.CodeDataStruct, x *ast.StructType, currentFile *trial.CodeFile) { func AddStructType(currentStruct trial.CodeDataStruct, x *ast.StructType, currentFile *trial.CodeFile) {
member := trial.CodeMember{ member := trial.CodeMember{
DataStructID: currentStruct.Name, DataStructID: currentStruct.Name,
Type: "struct", Type: "struct",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册