Skip to content

Commit

Permalink
Merge pull request #267 from xtonyjiang/cleanup
Browse files Browse the repository at this point in the history
Run go mod tidy and clean up some unused fields/logic
  • Loading branch information
LandonTClipp authored May 28, 2020
2 parents 5b00589 + 56d4f1c commit a08c526
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions mockery/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"
"sort"
"strings"
"sync"

"github.com/rs/zerolog"
"golang.org/x/tools/go/packages"
Expand All @@ -25,7 +24,6 @@ type parserEntry struct {
type Parser struct {
entries []*parserEntry
entriesByFileName map[string]*parserEntry
packages []*packages.Package
parserPackages []*types.Package
conf packages.Config
}
Expand Down Expand Up @@ -117,7 +115,6 @@ func (p *Parser) Parse(ctx context.Context, path string) error {
p.entries = append(p.entries, &entry)
p.entriesByFileName[f] = &entry
}
p.packages = append(p.packages, pkg)
}

return nil
Expand Down Expand Up @@ -148,25 +145,19 @@ func (nv *NodeVisitor) Visit(node ast.Node) ast.Visitor {
}

func (p *Parser) Load() error {
var wg sync.WaitGroup
wg.Add(1)
go func() {
for _, entry := range p.entries {
nv := NewNodeVisitor()
ast.Walk(nv, entry.syntax)
entry.interfaces = nv.DeclaredInterfaces()
}
wg.Done()
}()
wg.Wait()
for _, entry := range p.entries {
nv := NewNodeVisitor()
ast.Walk(nv, entry.syntax)
entry.interfaces = nv.DeclaredInterfaces()
}
return nil
}

func (p *Parser) Find(name string) (*Interface, error) {
for _, entry := range p.entries {
for _, iface := range entry.interfaces {
if iface == name {
list := p.packageInterfaces(entry.pkg.Types, entry.syntax, entry.fileName, []string{name}, nil)
list := p.packageInterfaces(entry.pkg.Types, entry.fileName, []string{name}, nil)
if len(list) > 0 {
return list[0], nil
}
Expand Down Expand Up @@ -204,8 +195,7 @@ func (p *Parser) Interfaces() []*Interface {
ifaces := make(sortableIFaceList, 0)
for _, entry := range p.entries {
declaredIfaces := entry.interfaces
astFile := entry.syntax
ifaces = p.packageInterfaces(entry.pkg.Types, astFile, entry.fileName, declaredIfaces, ifaces)
ifaces = p.packageInterfaces(entry.pkg.Types, entry.fileName, declaredIfaces, ifaces)
}

sort.Sort(ifaces)
Expand All @@ -214,7 +204,6 @@ func (p *Parser) Interfaces() []*Interface {

func (p *Parser) packageInterfaces(
pkg *types.Package,
file *ast.File,
fileName string,
declaredInterfaces []string,
ifaces []*Interface) []*Interface {
Expand Down Expand Up @@ -247,7 +236,6 @@ func (p *Parser) packageInterfaces(
FileName: fileName,
Type: iface.Complete(),
NamedType: typ,
File: file,
}

ifaces = append(ifaces, elem)
Expand Down

0 comments on commit a08c526

Please sign in to comment.