Skip to content

Commit

Permalink
Merge pull request #17 from goplus/revert-15-class
Browse files Browse the repository at this point in the history
Revert "gopmod: update IsClass api"
  • Loading branch information
xushiwei committed Aug 26, 2023
2 parents 5a7bdb1 + fa4eb11 commit 71818b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
34 changes: 4 additions & 30 deletions gopmod/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,15 @@ var (
// -----------------------------------------------------------------------------

func (p *Module) IsClass(ext string) (isProj bool, ok bool) {
_, isProj = p.projects[ext]
if isProj {
ok = true
return
c, ok := p.projects[ext]
if ok {
isProj = (ext == c.Ext)
}
_, ok = p.classes[ext]
return
}

func (p *Module) LookupClass(ext string) (c *Project, ok bool) {
c, ok = p.projects[ext]
if !ok {
c, ok = p.classes[ext]
}
return
}

type Kind int

const (
KindNone Kind = iota << 1
KindWork
KindProj
KindBoth = KindProj | KindWork
)

func (p *Module) ClassKind(ext string) (kind Kind) {
_, isProj := p.projects[ext]
if isProj {
kind = KindProj
}
_, isClass := p.classes[ext]
if isClass {
kind |= KindWork
}
return
}

Expand Down Expand Up @@ -137,7 +111,7 @@ func (p *Module) registerClassFrom(modVer module.Version, regcls func(c *Project
func (p *Module) registerClass(c *Project, regcls func(c *Project)) {
p.projects[c.Ext] = c
for _, w := range c.Works {
p.classes[w.Ext] = c
p.projects[w.Ext] = c
}
if regcls != nil {
regcls(c)
Expand Down
8 changes: 3 additions & 5 deletions gopmod/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ type depmodInfo struct {

type Module struct {
modload.Module
projects map[string]*Project // project ext -> project
classes map[string]*Project // class ext -> project
projects map[string]*Project // ext -> project
depmods []depmodInfo
}

Expand Down Expand Up @@ -176,10 +175,9 @@ func getDepMods(mod modload.Module) []depmodInfo {

// New creates a module from a modload.Module instance.
func New(mod modload.Module) *Module {
projects := make(map[string]*Project)
depmods := getDepMods(mod)
return &Module{projects: make(map[string]*Project),
classes: make(map[string]*Project),
depmods: depmods, Module: mod}
return &Module{projects: projects, depmods: depmods, Module: mod}
}

// Load loads a module from a local dir.
Expand Down

0 comments on commit 71818b1

Please sign in to comment.