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