create TraitAdaptationList node

This commit is contained in:
z7zmey 2018-04-29 22:34:24 +03:00
parent 8fc4c60bfe
commit f8d9d6d7c2
14 changed files with 1492 additions and 1326 deletions

View File

@ -0,0 +1,42 @@
package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// TraitAdaptationList node
type TraitAdaptationList struct {
Adaptations []node.Node
}
// NewTraitAdaptationList node constructor
func NewTraitAdaptationList(Adaptations []node.Node) *TraitAdaptationList {
return &TraitAdaptationList{
Adaptations,
}
}
// Attributes returns node attributes as map
func (n *TraitAdaptationList) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *TraitAdaptationList) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Adaptations != nil {
vv := v.GetChildrenVisitor("Adaptations")
for _, nn := range n.Adaptations {
if nn != nil {
nn.Walk(vv)
}
}
}
v.LeaveNode(n)
}

View File

@ -7,15 +7,15 @@ import (
// TraitUse node // TraitUse node
type TraitUse struct { type TraitUse struct {
Traits []node.Node Traits []node.Node
Adaptations []node.Node TraitAdaptationList *TraitAdaptationList
} }
// NewTraitUse node constructor // NewTraitUse node constructor
func NewTraitUse(Traits []node.Node, Adaptations []node.Node) *TraitUse { func NewTraitUse(Traits []node.Node, InnerAdaptationList *TraitAdaptationList) *TraitUse {
return &TraitUse{ return &TraitUse{
Traits, Traits,
Adaptations, InnerAdaptationList,
} }
} }
@ -40,13 +40,9 @@ func (n *TraitUse) Walk(v walker.Visitor) {
} }
} }
if n.Adaptations != nil { if n.TraitAdaptationList != nil {
vv := v.GetChildrenVisitor("Adaptations") vv := v.GetChildrenVisitor("TraitAdaptationList")
for _, nn := range n.Adaptations { n.TraitAdaptationList.Walk(vv)
if nn != nil {
nn.Walk(vv)
}
}
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -2,9 +2,10 @@ package stmt_test
import ( import (
"bytes" "bytes"
"github.com/z7zmey/php-parser/node/name"
"testing" "testing"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt" "github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5" "github.com/z7zmey/php-parser/php5"
@ -106,6 +107,7 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
}, },
}, },
}, },
TraitAdaptationList: &stmt.TraitAdaptationList{},
}, },
}, },
}, },
@ -145,12 +147,14 @@ func TestTraitsUseModifier(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUseAlias{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUseAlias{
Method: &node.Identifier{Value: "one"}, Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
}, },
Modifier: &node.Identifier{Value: "public"},
}, },
}, },
}, },
@ -192,13 +196,15 @@ func TestTraitsUseAliasModifier(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUseAlias{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUseAlias{
Method: &node.Identifier{Value: "one"}, Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
Alias: &node.Identifier{Value: "two"},
}, },
Modifier: &node.Identifier{Value: "public"},
Alias: &node.Identifier{Value: "two"},
}, },
}, },
}, },
@ -240,39 +246,41 @@ func TestTraitsUseAdaptions(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUsePrecedence{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUsePrecedence{
Trait: &name.Name{ Ref: &stmt.TraitMethodRef{
Parts: []node.Node{ Trait: &name.Name{
&name.NamePart{Value: "Bar"}, Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
}, },
Method: &node.Identifier{Value: "one"},
}, },
Method: &node.Identifier{Value: "one"}, Insteadof: []node.Node{
}, &name.Name{
Insteadof: []node.Node{ Parts: []node.Node{
&name.Name{ &name.NamePart{Value: "Baz"},
Parts: []node.Node{ },
&name.NamePart{Value: "Baz"},
}, },
}, &name.Name{
&name.Name{ Parts: []node.Node{
Parts: []node.Node{ &name.NamePart{Value: "Quux"},
&name.NamePart{Value: "Quux"}, },
}, },
}, },
}, },
}, &stmt.TraitUseAlias{
&stmt.TraitUseAlias{ Ref: &stmt.TraitMethodRef{
Ref: &stmt.TraitMethodRef{ Trait: &name.Name{
Trait: &name.Name{ Parts: []node.Node{
Parts: []node.Node{ &name.NamePart{Value: "Baz"},
&name.NamePart{Value: "Baz"}, },
}, },
Method: &node.Identifier{Value: "one"},
}, },
Method: &node.Identifier{Value: "one"}, Alias: &node.Identifier{Value: "two"},
}, },
Alias: &node.Identifier{Value: "two"},
}, },
}, },
}, },

View File

@ -92,10 +92,10 @@ var nodesToTest = []struct {
PhpDocComment: "/** */", PhpDocComment: "/** */",
ClassName: &node.Identifier{}, ClassName: &node.Identifier{},
Modifiers: []node.Node{&stmt.Expression{}}, Modifiers: []node.Node{&stmt.Expression{}},
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
Extends: &node.Identifier{}, Extends: &node.Identifier{},
Implements: []node.Node{&stmt.Expression{}}, Implements: []node.Node{&stmt.Expression{}},
Stmts: []node.Node{&stmt.Expression{}}, Stmts: []node.Node{&stmt.Expression{}},
}, },
[]string{"ClassName", "Modifiers", "ArgumentList", "Extends", "Implements", "Stmts"}, []string{"ClassName", "Modifiers", "ArgumentList", "Extends", "Implements", "Stmts"},
map[string]interface{}{"PhpDocComment": "/** */"}, map[string]interface{}{"PhpDocComment": "/** */"},
@ -408,10 +408,10 @@ var nodesToTest = []struct {
}, },
{ {
&stmt.TraitUse{ &stmt.TraitUse{
Traits: []node.Node{&stmt.Expression{}}, Traits: []node.Node{&stmt.Expression{}},
Adaptations: []node.Node{&stmt.Expression{}}, TraitAdaptationList: &stmt.TraitAdaptationList{},
}, },
[]string{"Traits", "Adaptations"}, []string{"Traits", "TraitAdaptationList"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
@ -479,6 +479,13 @@ var nodesToTest = []struct {
[]string{"Stmts"}, []string{"Stmts"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{
&stmt.TraitAdaptationList{
Adaptations: []node.Node{&stmt.TraitUsePrecedence{}},
},
[]string{"Adaptations"},
map[string]interface{}{},
},
} }
type visitorMock struct { type visitorMock struct {

File diff suppressed because it is too large Load Diff

View File

@ -243,6 +243,7 @@ import (
%type <node> trait_method_reference_fully_qualified trait_method_reference trait_modifiers member_modifier method %type <node> trait_method_reference_fully_qualified trait_method_reference trait_modifiers member_modifier method
%type <node> static_scalar_value static_operation %type <node> static_scalar_value static_operation
%type <node> ctor_arguments function_call_parameter_list %type <node> ctor_arguments function_call_parameter_list
%type <node> trait_adaptations
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations %type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
%type <list> inner_statement_list global_var_list static_var_list encaps_list isset_variables non_empty_array_pair_list %type <list> inner_statement_list global_var_list static_var_list encaps_list isset_variables non_empty_array_pair_list
@ -259,7 +260,7 @@ import (
%type <simpleIndirectReference> simple_indirect_reference %type <simpleIndirectReference> simple_indirect_reference
%type <foreachVariable> foreach_variable foreach_optional_arg %type <foreachVariable> foreach_variable foreach_optional_arg
%type <nodesWithEndToken> switch_case_list method_body trait_adaptations %type <nodesWithEndToken> switch_case_list method_body
%type <boolWithToken> is_reference is_variadic %type <boolWithToken> is_reference is_variadic
%type <altSyntaxNode> while_statement for_statement foreach_statement %type <altSyntaxNode> while_statement for_statement foreach_statement
@ -1550,8 +1551,16 @@ class_statement:
trait_use_statement: trait_use_statement:
T_USE trait_list trait_adaptations T_USE trait_list trait_adaptations
{ {
$$ = stmt.NewTraitUse($2, $3.nodes) var adaptationList *stmt.TraitAdaptationList
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3.endToken)) switch n := $3.(type) {
case *stmt.TraitAdaptationList:
adaptationList = n
default:
adaptationList = nil
}
$$ = stmt.NewTraitUse($2, adaptationList)
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $3))
yylex.(*Parser).comments.AddComments($$, $1.Comments()) yylex.(*Parser).comments.AddComments($$, $1.Comments())
} }
; ;
@ -1565,9 +1574,17 @@ trait_list:
trait_adaptations: trait_adaptations:
';' ';'
{ $$ = &nodesWithEndToken{nil, $1} } {
$$ = stmt.NewNop()
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenPosition($1))
}
| '{' trait_adaptation_list '}' | '{' trait_adaptation_list '}'
{ $$ = &nodesWithEndToken{$2, $3} } {
$$ = stmt.NewTraitAdaptationList($2)
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
}
; ;
trait_adaptation_list: trait_adaptation_list:

View File

@ -1455,6 +1455,7 @@ func TestPhp5(t *testing.T) {
}, },
}, },
}, },
TraitAdaptationList: &stmt.TraitAdaptationList{},
}, },
}, },
}, },
@ -1475,12 +1476,14 @@ func TestPhp5(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUseAlias{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUseAlias{
Method: &node.Identifier{Value: "one"}, Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
}, },
Modifier: &node.Identifier{Value: "public"},
}, },
}, },
}, },
@ -1503,13 +1506,15 @@ func TestPhp5(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUseAlias{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUseAlias{
Method: &node.Identifier{Value: "one"}, Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
Alias: &node.Identifier{Value: "two"},
}, },
Modifier: &node.Identifier{Value: "public"},
Alias: &node.Identifier{Value: "two"},
}, },
}, },
}, },
@ -1532,39 +1537,41 @@ func TestPhp5(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUsePrecedence{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUsePrecedence{
Trait: &name.Name{ Ref: &stmt.TraitMethodRef{
Parts: []node.Node{ Trait: &name.Name{
&name.NamePart{Value: "Bar"}, Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
}, },
Method: &node.Identifier{Value: "one"},
}, },
Method: &node.Identifier{Value: "one"}, Insteadof: []node.Node{
}, &name.Name{
Insteadof: []node.Node{ Parts: []node.Node{
&name.Name{ &name.NamePart{Value: "Baz"},
Parts: []node.Node{ },
&name.NamePart{Value: "Baz"},
}, },
}, &name.Name{
&name.Name{ Parts: []node.Node{
Parts: []node.Node{ &name.NamePart{Value: "Quux"},
&name.NamePart{Value: "Quux"}, },
}, },
}, },
}, },
}, &stmt.TraitUseAlias{
&stmt.TraitUseAlias{ Ref: &stmt.TraitMethodRef{
Ref: &stmt.TraitMethodRef{ Trait: &name.Name{
Trait: &name.Name{ Parts: []node.Node{
Parts: []node.Node{ &name.NamePart{Value: "Baz"},
&name.NamePart{Value: "Baz"}, },
}, },
Method: &node.Identifier{Value: "one"},
}, },
Method: &node.Identifier{Value: "one"}, Alias: &node.Identifier{Value: "two"},
}, },
Alias: &node.Identifier{Value: "two"},
}, },
}, },
}, },

File diff suppressed because it is too large Load Diff

View File

@ -264,12 +264,13 @@ import (
%type <node> isset_variable type return_type type_expr %type <node> isset_variable type return_type type_expr
%type <node> class_modifier %type <node> class_modifier
%type <node> argument_list ctor_arguments %type <node> argument_list ctor_arguments
%type <node> trait_adaptations
%type <node> member_modifier %type <node> member_modifier
%type <node> use_type %type <node> use_type
%type <foreachVariable> foreach_variable %type <foreachVariable> foreach_variable
%type <nodesWithEndToken> method_body switch_case_list trait_adaptations %type <nodesWithEndToken> method_body switch_case_list
%type <list> encaps_list backticks_expr namespace_name catch_name_list catch_list class_const_list %type <list> encaps_list backticks_expr namespace_name catch_name_list catch_list class_const_list
%type <list> const_list echo_expr_list for_exprs non_empty_for_exprs global_var_list %type <list> const_list echo_expr_list for_exprs non_empty_for_exprs global_var_list
@ -1864,10 +1865,20 @@ class_statement:
} }
| T_USE name_list trait_adaptations | T_USE name_list trait_adaptations
{ {
$$ = stmt.NewTraitUse($2, $3.nodes) var adaptationList *stmt.TraitAdaptationList
switch n := $3.(type) {
case *stmt.TraitAdaptationList:
adaptationList = n
default:
adaptationList = nil
yylex.(*Parser).comments.AddFromChildNode($$, $3)
}
$$ = stmt.NewTraitUse($2, adaptationList)
// save position // save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3.endToken)) yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $3))
// save comments // save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.UseToken) yylex.(*Parser).comments.AddFromToken($$, $1, comment.UseToken)
@ -1906,11 +1917,35 @@ name_list:
trait_adaptations: trait_adaptations:
';' ';'
{ $$ = &nodesWithEndToken{nil, $1} } {
$$ = stmt.NewNop()
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.SemiColonToken)
}
| '{' '}' | '{' '}'
{ $$ = &nodesWithEndToken{nil, $2} } {
$$ = stmt.NewTraitAdaptationList(nil)
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $2))
// save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.OpenCurlyBracesToken)
yylex.(*Parser).comments.AddFromToken($$, $2, comment.CloseCurlyBracesToken)
}
| '{' trait_adaptation_list '}' | '{' trait_adaptation_list '}'
{ $$ = &nodesWithEndToken{$2, $3} } {
$$ = stmt.NewTraitAdaptationList($2)
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
// save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.OpenCurlyBracesToken)
yylex.(*Parser).comments.AddFromToken($$, $3, comment.CloseCurlyBracesToken)
}
; ;
trait_adaptation_list: trait_adaptation_list:

View File

@ -1482,6 +1482,7 @@ func TestPhp7(t *testing.T) {
}, },
}, },
}, },
TraitAdaptationList: &stmt.TraitAdaptationList{},
}, },
}, },
}, },
@ -1502,12 +1503,14 @@ func TestPhp7(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUseAlias{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUseAlias{
Method: &node.Identifier{Value: "one"}, Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Alias: &node.Identifier{Value: "include"},
}, },
Alias: &node.Identifier{Value: "include"},
}, },
}, },
}, },
@ -1530,12 +1533,14 @@ func TestPhp7(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUseAlias{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUseAlias{
Method: &node.Identifier{Value: "one"}, Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
}, },
Modifier: &node.Identifier{Value: "public"},
}, },
}, },
}, },
@ -1558,13 +1563,15 @@ func TestPhp7(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUseAlias{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUseAlias{
Method: &node.Identifier{Value: "one"}, Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
},
Modifier: &node.Identifier{Value: "public"},
Alias: &node.Identifier{Value: "two"},
}, },
Modifier: &node.Identifier{Value: "public"},
Alias: &node.Identifier{Value: "two"},
}, },
}, },
}, },
@ -1587,39 +1594,41 @@ func TestPhp7(t *testing.T) {
}, },
}, },
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUsePrecedence{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUsePrecedence{
Trait: &name.Name{ Ref: &stmt.TraitMethodRef{
Parts: []node.Node{ Trait: &name.Name{
&name.NamePart{Value: "Bar"}, Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
}, },
Method: &node.Identifier{Value: "one"},
}, },
Method: &node.Identifier{Value: "one"}, Insteadof: []node.Node{
}, &name.Name{
Insteadof: []node.Node{ Parts: []node.Node{
&name.Name{ &name.NamePart{Value: "Baz"},
Parts: []node.Node{ },
&name.NamePart{Value: "Baz"},
}, },
}, &name.Name{
&name.Name{ Parts: []node.Node{
Parts: []node.Node{ &name.NamePart{Value: "Quux"},
&name.NamePart{Value: "Quux"}, },
}, },
}, },
}, },
}, &stmt.TraitUseAlias{
&stmt.TraitUseAlias{ Ref: &stmt.TraitMethodRef{
Ref: &stmt.TraitMethodRef{ Trait: &name.Name{
Trait: &name.Name{ Parts: []node.Node{
Parts: []node.Node{ &name.NamePart{Value: "Baz"},
&name.NamePart{Value: "Baz"}, },
}, },
Method: &node.Identifier{Value: "one"},
}, },
Method: &node.Identifier{Value: "one"}, Alias: &node.Identifier{Value: "two"},
}, },
Alias: &node.Identifier{Value: "two"},
}, },
}, },
}, },

View File

@ -2066,9 +2066,10 @@ func (p *Printer) printStmtTraitUse(n node.Node) {
io.WriteString(p.w, "use ") io.WriteString(p.w, "use ")
p.joinPrint(", ", nn.Traits) p.joinPrint(", ", nn.Traits)
if nn.Adaptations != nil { if nn.TraitAdaptationList != nil {
adaptations := nn.TraitAdaptationList.Adaptations
io.WriteString(p.w, " {\n") io.WriteString(p.w, " {\n")
p.printNodes(nn.Adaptations) p.printNodes(adaptations)
io.WriteString(p.w, "\n") io.WriteString(p.w, "\n")
p.printIndent() p.printIndent()
io.WriteString(p.w, "}") io.WriteString(p.w, "}")

View File

@ -3789,13 +3789,15 @@ func TestPrintStmtTraitAdaptations(t *testing.T) {
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}}, &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUseAlias{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUseAlias{
Trait: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "a"}, Trait: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
Method: &node.Identifier{Value: "a"},
},
Alias: &node.Identifier{Value: "b"},
}, },
Alias: &node.Identifier{Value: "b"},
}, },
}, },
}, },

View File

@ -152,7 +152,7 @@ func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool {
nsr.ResolveName(t, "") nsr.ResolveName(t, "")
} }
for _, a := range n.Adaptations { for _, a := range n.TraitAdaptationList.Adaptations {
switch aa := a.(type) { switch aa := a.(type) {
case *stmt.TraitUsePrecedence: case *stmt.TraitUsePrecedence:
refTrait := aa.Ref.(*stmt.TraitMethodRef).Trait refTrait := aa.Ref.(*stmt.TraitMethodRef).Trait

View File

@ -43,8 +43,8 @@ func TestResolveStaticCall(t *testing.T) {
}, },
}, },
&expr.StaticCall{ &expr.StaticCall{
Class: nameBC, Class: nameBC,
Call: &node.Identifier{Value: "foo"}, Call: &node.Identifier{Value: "foo"},
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
}, },
@ -134,7 +134,7 @@ func TestResolveNew(t *testing.T) {
}, },
}, },
&expr.New{ &expr.New{
Class: nameBC, Class: nameBC,
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
}, },
@ -242,7 +242,7 @@ func TestResolveFunctionCall(t *testing.T) {
}, },
}, },
&expr.FunctionCall{ &expr.FunctionCall{
Function: nameB, Function: nameB,
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
}, },
@ -323,11 +323,11 @@ func TestResolveGroupUse(t *testing.T) {
Constant: nameC, Constant: nameC,
}, },
&expr.FunctionCall{ &expr.FunctionCall{
Function: nameF, Function: nameF,
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
&expr.FunctionCall{ &expr.FunctionCall{
Function: nameE, Function: nameE,
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
}, },
@ -368,20 +368,22 @@ func TestResolveTraitUse(t *testing.T) {
nameB, nameB,
relativeNameB, relativeNameB,
}, },
Adaptations: []node.Node{ TraitAdaptationList: &stmt.TraitAdaptationList{
&stmt.TraitUsePrecedence{ Adaptations: []node.Node{
Ref: &stmt.TraitMethodRef{ &stmt.TraitUsePrecedence{
Trait: fullyQualifiedNameB, Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "foo"}, Trait: fullyQualifiedNameB,
Method: &node.Identifier{Value: "foo"},
},
Insteadof: []node.Node{fullyQualifiedNameBC},
}, },
Insteadof: []node.Node{fullyQualifiedNameBC}, &stmt.TraitUseAlias{
}, Ref: &stmt.TraitMethodRef{
&stmt.TraitUseAlias{ Trait: relativeNameBC,
Ref: &stmt.TraitMethodRef{ Method: &node.Identifier{Value: "foo"},
Trait: relativeNameBC, },
Method: &node.Identifier{Value: "foo"}, Alias: &node.Identifier{Value: "bar"},
}, },
Alias: &node.Identifier{Value: "bar"},
}, },
}, },
}, },
@ -658,8 +660,8 @@ func TestResolveNamespaces(t *testing.T) {
}, },
}, },
&expr.StaticCall{ &expr.StaticCall{
Class: nameFG, Class: nameFG,
Call: &node.Identifier{Value: "foo"}, Call: &node.Identifier{Value: "foo"},
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
&stmt.Namespace{ &stmt.Namespace{
@ -676,13 +678,13 @@ func TestResolveNamespaces(t *testing.T) {
}, },
}, },
&expr.StaticCall{ &expr.StaticCall{
Class: relativeNameCE, Class: relativeNameCE,
Call: &node.Identifier{Value: "foo"}, Call: &node.Identifier{Value: "foo"},
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
&expr.StaticCall{ &expr.StaticCall{
Class: nameCF, Class: nameCF,
Call: &node.Identifier{Value: "foo"}, Call: &node.Identifier{Value: "foo"},
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
}, },
@ -708,8 +710,8 @@ func TestResolveStaticCallDinamicClassName(t *testing.T) {
ast := &stmt.StmtList{ ast := &stmt.StmtList{
Stmts: []node.Node{ Stmts: []node.Node{
&expr.StaticCall{ &expr.StaticCall{
Class: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}, Class: &expr.Variable{VarName: &node.Identifier{Value: "foo"}},
Call: &node.Identifier{Value: "foo"}, Call: &node.Identifier{Value: "foo"},
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
}, },