From 0db60dd3db91d491a8e69cb78e70b342a4e92be6 Mon Sep 17 00:00:00 2001 From: xxj <346944475@qq.com> Date: Thu, 15 Sep 2022 11:01:04 +0800 Subject: [PATCH] Update myast.go --- myast/myast.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/myast/myast.go b/myast/myast.go index e6a0fd5..1021f92 100644 --- a/myast/myast.go +++ b/myast/myast.go @@ -59,7 +59,7 @@ func (a *structAnalys) ParserStruct(astPkg *ast.Package, structName string) (inf } info.Name = structName - info.Items = a.structFieldInfo(astPkg, st) + info.Items = a.structFieldInfo(astPkg, st, info.Name) return } } @@ -71,7 +71,7 @@ func (a *structAnalys) ParserStruct(astPkg *ast.Package, structName string) (inf return nil } -func (a *structAnalys) structFieldInfo(astPkg *ast.Package, sinfo *ast.StructType) (items []mydoc.ElementInfo) { +func (a *structAnalys) structFieldInfo(astPkg *ast.Package, sinfo *ast.StructType, structName string) (items []mydoc.ElementInfo) { if sinfo == nil || sinfo.Fields == nil { return } @@ -116,13 +116,13 @@ func (a *structAnalys) structFieldInfo(astPkg *ast.Package, sinfo *ast.StructTyp case *ast.SelectorExpr: // 非本文件包 a.dealSelectorExpr(x, &info, importMP) case *ast.Ident: - a.dealIdent(astPkg, x, &info) + a.dealIdent(astPkg, x, &info, structName) case *ast.StarExpr: switch x1 := x.X.(type) { case *ast.SelectorExpr: // 非本文件包 a.dealSelectorExpr(x1, &info, importMP) case *ast.Ident: - a.dealIdent(astPkg, x1, &info) + a.dealIdent(astPkg, x1, &info, structName) } case *ast.InterfaceType: info.Type = "Interface" @@ -134,10 +134,10 @@ func (a *structAnalys) structFieldInfo(astPkg *ast.Package, sinfo *ast.StructTyp case *ast.SelectorExpr: // 非本文件包 a.dealSelectorExpr(x, &info, importMP) case *ast.Ident: - a.dealIdent(astPkg, x, &info) + a.dealIdent(astPkg, x, &info, structName) } case *ast.Ident: // 本文件 - a.dealIdent(astPkg, exp, &info) + a.dealIdent(astPkg, exp, &info, structName) case *ast.MapType: // map key := "" value := "" @@ -196,9 +196,11 @@ func (a *structAnalys) dealSelectorExpr(exp *ast.SelectorExpr, info *mydoc.Eleme } } -func (a *structAnalys) dealIdent(astPkg *ast.Package, exp *ast.Ident, info *mydoc.ElementInfo) { // 本文件 +func (a *structAnalys) dealIdent(astPkg *ast.Package, exp *ast.Ident, info *mydoc.ElementInfo, structName string) { // 本文件 info.Type = exp.Name if !tools.IsInternalType(info.Type) { // 非基础类型 - info.TypeRef = a.ParserStruct(astPkg, info.Type) + if structName != info.Type { + info.TypeRef = a.ParserStruct(astPkg, info.Type) + } } }