refactor: rename build to append

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