fix: fix empty self function issues

上级 350b13b5
......@@ -162,30 +162,34 @@ func BuildFunction(x *ast.FuncDecl) *trial.CodeFunction {
func BuildMethodCall(codeFunc *trial.CodeFunction, item ast.Stmt) {
switch it := item.(type) {
case *ast.ExprStmt:
switch expr := it.X.(type) {
case *ast.CallExpr:
selector, selName := BuildExpr(expr.Fun.(ast.Expr))
call := trial.CodeCall{
Package: "",
Type: "",
Class: selector,
MethodName: selName,
}
BuildMethodCallExprStmt(it, codeFunc)
default:
fmt.Println("methodCall", reflect.TypeOf(it))
}
}
for _, arg := range expr.Args {
value, kind := BuildExpr(arg.(ast.Expr))
property := &trial.CodeProperty{
TypeName: value,
TypeType: kind,
}
func BuildMethodCallExprStmt(it *ast.ExprStmt, codeFunc *trial.CodeFunction) {
switch expr := it.X.(type) {
case *ast.CallExpr:
selector, selName := BuildExpr(expr.Fun.(ast.Expr))
call := trial.CodeCall{
Package: "",
Type: "",
Class: selector,
MethodName: selName,
}
call.Parameters = append(call.Parameters, *property)
for _, arg := range expr.Args {
value, kind := BuildExpr(arg.(ast.Expr))
property := &trial.CodeProperty{
TypeName: value,
TypeType: kind,
}
codeFunc.MethodCalls = append(codeFunc.MethodCalls, call)
call.Parameters = append(call.Parameters, *property)
}
default:
fmt.Println("methodCall", reflect.TypeOf(it))
codeFunc.MethodCalls = append(codeFunc.MethodCalls, call)
}
}
......@@ -197,6 +201,8 @@ func BuildExpr(expr ast.Expr) (string, string) {
return selector, selName
case *ast.BasicLit:
return x.Value, x.Kind.String()
case *ast.Ident:
return x.Name, x.Obj.Kind.String()
default:
fmt.Println("BuildExpr", reflect.TypeOf(x))
}
......
{
"ClassNodes": null,
"DataStructures": null,
"FullName": "testdata/nested_method.code",
"Imports": [
"fmt"
],
"Members": [
{
"ClassNodes": null,
"DataStructID": "default",
"FileID": "",
"ID": "",
"MethodNodes": [
{
"Annotations": null,
"Creators": null,
"InnerFunctions": null,
"MethodCalls": [
{
"Class": "",
"MethodName": "",
"Package": "",
"Parameters": [
{
"Modifiers": null,
"Name": "",
"TypeName": "\"Hello World!\"",
"TypeType": "STRING"
}
],
"Type": ""
}
],
"Modifiers": null,
"Name": "f",
"Override": false,
"Parameters": null,
"ReturnTypes": null
}
],
"Name": "",
"Namespace": null,
"Position": {
"StartLine": 0,
"StartLinePosition": 0,
"StopLine": 0,
"StopLinePosition": 0
},
"Type": "method"
}
],
"PackageName": "testdata"
"ClassNodes": null,
"DataStructures": null,
"FullName": "testdata/nested_method.code",
"Imports": [
"fmt"
],
"Members": [
{
"ClassNodes": null,
"DataStructID": "default",
"FileID": "",
"ID": "",
"MethodNodes": [
{
"Annotations": null,
"Creators": null,
"InnerFunctions": null,
"MethodCalls": [
{
"Class": "foo",
"MethodName": "var",
"Package": "",
"Parameters": [
{
"Modifiers": null,
"Name": "",
"TypeName": "\"Hello World!\"",
"TypeType": "STRING"
}
],
"Type": ""
}
],
"Modifiers": null,
"Name": "f",
"Override": false,
"Parameters": null,
"ReturnTypes": null
}
],
"Name": "",
"Namespace": null,
"Position": {
"StartLine": 0,
"StartLinePosition": 0,
"StopLine": 0,
"StopLinePosition": 0
},
"Type": "method"
}
],
"PackageName": "testdata"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册