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
|
||||
}
|
||||
for _, nn := range n.Uses {
|
||||
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(useNameParts), alias)
|
||||
}
|
||||
nsr.AddAlias(useType, nn, nil)
|
||||
}
|
||||
case *stmt.GroupUse:
|
||||
useType := ""
|
||||
@ -89,6 +74,14 @@ func (nsr *NsResolver) EnterNode(w walker.Walkable) bool {
|
||||
useType = n.UseType.(*node.Identifier).Value
|
||||
}
|
||||
for _, nn := range n.UseList {
|
||||
nsr.AddAlias(useType, nn, n.Prefix.(*name.Name).Parts)
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -103,14 +96,8 @@ func (nsr *NsResolver) EnterNode(w walker.Walkable) bool {
|
||||
alias = use.Alias.(*node.Identifier).Value
|
||||
}
|
||||
|
||||
aliasName := concatNameParts(n.Prefix.(*name.Name).Parts, useNameParts)
|
||||
nsr.Namespace.AddAlias(useType, aliasName, alias)
|
||||
nsr.Namespace.AddAlias(useType, concatNameParts(prefix, useNameParts), alias)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// GetChildrenVisitor is invoked at every node parameter that contains children nodes
|
||||
|
Loading…
Reference in New Issue
Block a user