collect aliases
This commit is contained in:
parent
b9f158e7f4
commit
91eb67279d
@ -66,22 +66,7 @@ func (nsr *NsResolver) EnterNode(w walker.Walkable) bool {
|
|||||||
useType = n.UseType.(*node.Identifier).Value
|
useType = n.UseType.(*node.Identifier).Value
|
||||||
}
|
}
|
||||||
for _, nn := range n.Uses {
|
for _, nn := range n.Uses {
|
||||||
switch use := nn.(type) {
|
nsr.AddAlias(useType, nn, nil)
|
||||||
case *stmt.Use:
|
|
||||||
if use.UseType != nil {
|
|
||||||
useType = use.UseType.(*node.Identifier).Value
|
|
||||||
}
|
|
||||||
|
|
||||||
useNameParts := use.Use.(*name.Name).Parts
|
|
||||||
var alias string
|
|
||||||
if use.Alias == nil {
|
|
||||||
alias = useNameParts[len(useNameParts)-1].(*name.NamePart).Value
|
|
||||||
} else {
|
|
||||||
alias = use.Alias.(*node.Identifier).Value
|
|
||||||
}
|
|
||||||
|
|
||||||
nsr.Namespace.AddAlias(useType, concatNameParts(useNameParts), alias)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case *stmt.GroupUse:
|
case *stmt.GroupUse:
|
||||||
useType := ""
|
useType := ""
|
||||||
@ -89,30 +74,32 @@ func (nsr *NsResolver) EnterNode(w walker.Walkable) bool {
|
|||||||
useType = n.UseType.(*node.Identifier).Value
|
useType = n.UseType.(*node.Identifier).Value
|
||||||
}
|
}
|
||||||
for _, nn := range n.UseList {
|
for _, nn := range n.UseList {
|
||||||
switch use := nn.(type) {
|
nsr.AddAlias(useType, nn, n.Prefix.(*name.Name).Parts)
|
||||||
case *stmt.Use:
|
|
||||||
if use.UseType != nil {
|
|
||||||
useType = use.UseType.(*node.Identifier).Value
|
|
||||||
}
|
|
||||||
|
|
||||||
useNameParts := use.Use.(*name.Name).Parts
|
|
||||||
var alias string
|
|
||||||
if use.Alias == nil {
|
|
||||||
alias = useNameParts[len(useNameParts)-1].(*name.NamePart).Value
|
|
||||||
} else {
|
|
||||||
alias = use.Alias.(*node.Identifier).Value
|
|
||||||
}
|
|
||||||
|
|
||||||
aliasName := concatNameParts(n.Prefix.(*name.Name).Parts, useNameParts)
|
|
||||||
nsr.Namespace.AddAlias(useType, aliasName, alias)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nsr *NsResolver) AddAlias(useType string, nn node.Node, prefix []node.Node) {
|
||||||
|
switch use := nn.(type) {
|
||||||
|
case *stmt.Use:
|
||||||
|
if use.UseType != nil {
|
||||||
|
useType = use.UseType.(*node.Identifier).Value
|
||||||
|
}
|
||||||
|
|
||||||
|
useNameParts := use.Use.(*name.Name).Parts
|
||||||
|
var alias string
|
||||||
|
if use.Alias == nil {
|
||||||
|
alias = useNameParts[len(useNameParts)-1].(*name.NamePart).Value
|
||||||
|
} else {
|
||||||
|
alias = use.Alias.(*node.Identifier).Value
|
||||||
|
}
|
||||||
|
|
||||||
|
nsr.Namespace.AddAlias(useType, concatNameParts(prefix, useNameParts), alias)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetChildrenVisitor is invoked at every node parameter that contains children nodes
|
// GetChildrenVisitor is invoked at every node parameter that contains children nodes
|
||||||
func (nsr *NsResolver) GetChildrenVisitor(key string) walker.Visitor {
|
func (nsr *NsResolver) GetChildrenVisitor(key string) walker.Visitor {
|
||||||
return nsr
|
return nsr
|
||||||
|
Loading…
Reference in New Issue
Block a user