rename NsResolver to NamespaceResolver
This commit is contained in:
parent
eb9e88f1a1
commit
a517a62f4c
2
main.go
2
main.go
@ -39,7 +39,7 @@ func main() {
|
|||||||
nodes, comments, positions = php7.Parse(src, path)
|
nodes, comments, positions = php7.Parse(src, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsResolver := visitor.NewNsResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
nodes.Walk(nsResolver)
|
nodes.Walk(nsResolver)
|
||||||
|
|
||||||
dumper := visitor.Dumper{
|
dumper := visitor.Dumper{
|
||||||
|
@ -13,22 +13,22 @@ import (
|
|||||||
"github.com/z7zmey/php-parser/walker"
|
"github.com/z7zmey/php-parser/walker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NsResolver visitor
|
// NamespaceResolver visitor
|
||||||
type NsResolver struct {
|
type NamespaceResolver struct {
|
||||||
Namespace *Namespace
|
Namespace *Namespace
|
||||||
ResolvedNames map[node.Node]string
|
ResolvedNames map[node.Node]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNsResolver NsResolver type constructor
|
// NewNamespaceResolver NamespaceResolver type constructor
|
||||||
func NewNsResolver() *NsResolver {
|
func NewNamespaceResolver() *NamespaceResolver {
|
||||||
return &NsResolver{
|
return &NamespaceResolver{
|
||||||
Namespace: NewNamespace(""),
|
Namespace: NewNamespace(""),
|
||||||
ResolvedNames: map[node.Node]string{},
|
ResolvedNames: map[node.Node]string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnterNode is invoked at every node in heirerchy
|
// EnterNode is invoked at every node in heirerchy
|
||||||
func (nsr *NsResolver) EnterNode(w walker.Walkable) bool {
|
func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool {
|
||||||
switch n := w.(type) {
|
switch n := w.(type) {
|
||||||
case *stmt.Namespace:
|
case *stmt.Namespace:
|
||||||
if n.NamespaceName == nil {
|
if n.NamespaceName == nil {
|
||||||
@ -193,12 +193,12 @@ func (nsr *NsResolver) EnterNode(w walker.Walkable) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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 *NamespaceResolver) GetChildrenVisitor(key string) walker.Visitor {
|
||||||
return nsr
|
return nsr
|
||||||
}
|
}
|
||||||
|
|
||||||
// LeaveNode is invoked after node process
|
// LeaveNode is invoked after node process
|
||||||
func (nsr *NsResolver) LeaveNode(w walker.Walkable) {
|
func (nsr *NamespaceResolver) LeaveNode(w walker.Walkable) {
|
||||||
switch n := w.(type) {
|
switch n := w.(type) {
|
||||||
case *stmt.Namespace:
|
case *stmt.Namespace:
|
||||||
if n.Stmts != nil {
|
if n.Stmts != nil {
|
||||||
@ -208,7 +208,7 @@ func (nsr *NsResolver) LeaveNode(w walker.Walkable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddAlias adds a new alias
|
// AddAlias adds a new alias
|
||||||
func (nsr *NsResolver) AddAlias(useType string, nn node.Node, prefix []node.Node) {
|
func (nsr *NamespaceResolver) 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 {
|
||||||
@ -228,7 +228,7 @@ func (nsr *NsResolver) AddAlias(useType string, nn node.Node, prefix []node.Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddNamespacedName adds namespaced name by node
|
// AddNamespacedName adds namespaced name by node
|
||||||
func (nsr *NsResolver) AddNamespacedName(nn node.Node, nodeName string) {
|
func (nsr *NamespaceResolver) AddNamespacedName(nn node.Node, nodeName string) {
|
||||||
if nsr.Namespace.Namespace == "" {
|
if nsr.Namespace.Namespace == "" {
|
||||||
nsr.ResolvedNames[nn] = nodeName
|
nsr.ResolvedNames[nn] = nodeName
|
||||||
} else {
|
} else {
|
||||||
@ -237,12 +237,12 @@ func (nsr *NsResolver) AddNamespacedName(nn node.Node, nodeName string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ResolveName adds a resolved fully qualified name by node
|
// ResolveName adds a resolved fully qualified name by node
|
||||||
func (nsr *NsResolver) ResolveName(nameNode node.Node, aliasType string) {
|
func (nsr *NamespaceResolver) ResolveName(nameNode node.Node, aliasType string) {
|
||||||
nsr.ResolvedNames[nameNode] = nsr.Namespace.ResolveName(nameNode, aliasType)
|
nsr.ResolvedNames[nameNode] = nsr.Namespace.ResolveName(nameNode, aliasType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveType adds a resolved fully qualified type name
|
// ResolveType adds a resolved fully qualified type name
|
||||||
func (nsr *NsResolver) ResolveType(n node.Node) {
|
func (nsr *NamespaceResolver) ResolveType(n node.Node) {
|
||||||
switch nn := n.(type) {
|
switch nn := n.(type) {
|
||||||
case *node.Nullable:
|
case *node.Nullable:
|
||||||
nsr.ResolveType(nn.Expr)
|
nsr.ResolveType(nn.Expr)
|
Loading…
Reference in New Issue
Block a user