mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 18:29:53 +08:00
Use package path instead of name
This commit is contained in:
parent
4e5be36459
commit
8fd0e06c24
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
var packageCache = make(map[string]*ParsedPackage)
|
var packageCache = make(map[string]*ParsedPackage)
|
||||||
|
|
||||||
type packageName = string
|
type packagePath = string
|
||||||
type structName = string
|
type structName = string
|
||||||
|
|
||||||
type StructDef struct {
|
type StructDef struct {
|
||||||
@ -51,18 +51,19 @@ type Field struct {
|
|||||||
type ParsedPackage struct {
|
type ParsedPackage struct {
|
||||||
Pkg *ast.Package
|
Pkg *ast.Package
|
||||||
Name string
|
Name string
|
||||||
|
Path string
|
||||||
Dir string
|
Dir string
|
||||||
structCache map[structName]*StructDef
|
StructCache map[structName]*StructDef
|
||||||
}
|
}
|
||||||
|
|
||||||
type Project struct {
|
type Project struct {
|
||||||
Path string
|
Path string
|
||||||
BoundMethods map[packageName]map[structName][]*BoundMethod
|
BoundMethods map[packagePath]map[structName][]*BoundMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseProject(projectPath string) (*Project, error) {
|
func ParseProject(projectPath string) (*Project, error) {
|
||||||
result := &Project{
|
result := &Project{
|
||||||
BoundMethods: make(map[packageName]map[structName][]*BoundMethod),
|
BoundMethods: make(map[packagePath]map[structName][]*BoundMethod),
|
||||||
}
|
}
|
||||||
pkgs, err := result.parseDirectory(projectPath)
|
pkgs, err := result.parseDirectory(projectPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -100,8 +101,9 @@ func (p *Project) parseDirectory(dir string) (map[string]*ParsedPackage, error)
|
|||||||
parsedPackage := &ParsedPackage{
|
parsedPackage := &ParsedPackage{
|
||||||
Pkg: pkg,
|
Pkg: pkg,
|
||||||
Name: packageName,
|
Name: packageName,
|
||||||
|
Path: packageName,
|
||||||
Dir: getDirectoryForPackage(pkg),
|
Dir: getDirectoryForPackage(pkg),
|
||||||
structCache: make(map[structName]*StructDef),
|
StructCache: make(map[structName]*StructDef),
|
||||||
}
|
}
|
||||||
packageCache[dir] = parsedPackage
|
packageCache[dir] = parsedPackage
|
||||||
result[packageName] = parsedPackage
|
result[packageName] = parsedPackage
|
||||||
@ -265,12 +267,12 @@ func (p *Project) findApplicationNewCalls(pkgs map[string]*ParsedPackage) (err e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Project) addBoundMethods(packageName string, name string, boundMethods []*BoundMethod) {
|
func (p *Project) addBoundMethods(packagePath string, name string, boundMethods []*BoundMethod) {
|
||||||
_, ok := p.BoundMethods[packageName]
|
_, ok := p.BoundMethods[packagePath]
|
||||||
if !ok {
|
if !ok {
|
||||||
p.BoundMethods[packageName] = make(map[structName][]*BoundMethod)
|
p.BoundMethods[packagePath] = make(map[structName][]*BoundMethod)
|
||||||
}
|
}
|
||||||
p.BoundMethods[packageName][name] = boundMethods
|
p.BoundMethods[packagePath][name] = boundMethods
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Project) parseBoundStructMethods(name string, pkg *ParsedPackage) error {
|
func (p *Project) parseBoundStructMethods(name string, pkg *ParsedPackage) error {
|
||||||
@ -304,7 +306,7 @@ func (p *Project) parseBoundStructMethods(name string, pkg *ParsedPackage) error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.addBoundMethods(pkg.Name, name, methods)
|
p.addBoundMethods(pkg.Path, name, methods)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,7 +355,7 @@ func (p *Project) parseParameterType(field *ast.Field, pkg *ParsedPackage) *Para
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if result.IsStruct {
|
if result.IsStruct {
|
||||||
_, ok := pkg.structCache[result.Name]
|
_, ok := pkg.StructCache[result.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
p.getStructDef(result.Name, pkg)
|
p.getStructDef(result.Name, pkg)
|
||||||
}
|
}
|
||||||
@ -362,7 +364,7 @@ func (p *Project) parseParameterType(field *ast.Field, pkg *ParsedPackage) *Para
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Project) getStructDef(name string, pkg *ParsedPackage) {
|
func (p *Project) getStructDef(name string, pkg *ParsedPackage) {
|
||||||
_, ok := pkg.structCache[name]
|
_, ok := pkg.StructCache[name]
|
||||||
if ok {
|
if ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -382,7 +384,7 @@ func (p *Project) getStructDef(name string, pkg *ParsedPackage) {
|
|||||||
Name: name,
|
Name: name,
|
||||||
DocComment: typeDecl.Doc.Text(),
|
DocComment: typeDecl.Doc.Text(),
|
||||||
}
|
}
|
||||||
pkg.structCache[name] = result
|
pkg.StructCache[name] = result
|
||||||
result.Fields = p.parseStructFields(structType, pkg)
|
result.Fields = p.parseStructFields(structType, pkg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,7 +415,7 @@ func (p *Project) parseStructFields(structType *ast.StructType, pkg *ParsedPacka
|
|||||||
for _, thisField := range theseFields {
|
for _, thisField := range theseFields {
|
||||||
paramType := p.parseParameterType(field, pkg)
|
paramType := p.parseParameterType(field, pkg)
|
||||||
if paramType.IsStruct {
|
if paramType.IsStruct {
|
||||||
_, ok := pkg.structCache[paramType.Name]
|
_, ok := pkg.StructCache[paramType.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
p.getStructDef(paramType.Name, pkg)
|
p.getStructDef(paramType.Name, pkg)
|
||||||
}
|
}
|
||||||
@ -446,8 +448,9 @@ func (p *Project) getParsedPackageFromName(packageName string, currentPackage *P
|
|||||||
return &ParsedPackage{
|
return &ParsedPackage{
|
||||||
Pkg: pkg,
|
Pkg: pkg,
|
||||||
Name: packageName,
|
Name: packageName,
|
||||||
|
Path: path,
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
structCache: make(map[string]*StructDef),
|
StructCache: make(map[string]*StructDef),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -966,7 +966,7 @@ func TestParseDirectory(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"services": {
|
"github.com/wailsapp/wails/v3/internal/parser/testdata/struct_literal_multiple_other/services": {
|
||||||
"OtherService": {
|
"OtherService": {
|
||||||
{
|
{
|
||||||
Name: "Yay",
|
Name: "Yay",
|
||||||
|
Loading…
Reference in New Issue
Block a user