Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wsy9981999 committed Sep 30, 2023
1 parent 3fea152 commit ee5fb7a
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions parser/parse_pkg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package parser

import (
"go/parser"
"go/token"
"os"
"path/filepath"
"strings"
Expand All @@ -9,7 +11,6 @@ import (
)

func ParsePackage(pkg string) (*api.GoPkg, error) {

dir, err := os.ReadDir(pkg)
if err != nil {
return nil, err
Expand All @@ -21,7 +22,12 @@ func ParsePackage(pkg string) (*api.GoPkg, error) {
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".go") {
continue
}
parse, err := Parse(filepath.Join(pkg, entry.Name()))
set := token.NewFileSet()
file, err := parser.ParseFile(set, filepath.Join(pkg, entry.Name()), nil, 0)
if err != nil {
return nil, err
}
parse, err := parse(file, true)
if err != nil {
return nil, err
}
Expand All @@ -35,6 +41,18 @@ func ParsePackage(pkg string) (*api.GoPkg, error) {
imports[n] = goImport
}
}

for _, goFunc := range funcs {
for _, goStruct := range structs {
if isConstructor(goFunc, goStruct) {
goStruct.Constructor = goFunc
break
}
if IsMethod(goFunc, goStruct) {
goStruct.Funs = append(goStruct.Funs, goFunc)
}
}
}
goPkg := api.NewGoPkg()
goPkg.GoStructs = structs
goPkg.Func = funcs
Expand Down Expand Up @@ -78,6 +96,17 @@ func ParsePackages(pkgs map[string]*api.GoPkg, re bool, pkg ...string) error {
for name, imports := range file.Imports {
goPkg.Imports[name] = imports
}
for _, goFunc := range goPkg.Func {
for _, goStruct := range goPkg.GoStructs {
if isConstructor(goFunc, goStruct) {
goStruct.Constructor = goFunc
break
}
if IsMethod(goFunc, goStruct) {
goStruct.Funs = append(goStruct.Funs, goFunc)
}
}
}
pkgs[s] = goPkg

}
Expand Down

0 comments on commit ee5fb7a

Please sign in to comment.