create TraitAdaptationList node
This commit is contained in:
parent
8fc4c60bfe
commit
f8d9d6d7c2
42
node/stmt/n_trait_adaptation_list.go
Normal file
42
node/stmt/n_trait_adaptation_list.go
Normal 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)
|
||||
}
|
@ -7,15 +7,15 @@ import (
|
||||
|
||||
// TraitUse node
|
||||
type TraitUse struct {
|
||||
Traits []node.Node
|
||||
Adaptations []node.Node
|
||||
Traits []node.Node
|
||||
TraitAdaptationList *TraitAdaptationList
|
||||
}
|
||||
|
||||
// NewTraitUse node constructor
|
||||
func NewTraitUse(Traits []node.Node, Adaptations []node.Node) *TraitUse {
|
||||
func NewTraitUse(Traits []node.Node, InnerAdaptationList *TraitAdaptationList) *TraitUse {
|
||||
return &TraitUse{
|
||||
Traits,
|
||||
Adaptations,
|
||||
InnerAdaptationList,
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,13 +40,9 @@ func (n *TraitUse) Walk(v walker.Visitor) {
|
||||
}
|
||||
}
|
||||
|
||||
if n.Adaptations != nil {
|
||||
vv := v.GetChildrenVisitor("Adaptations")
|
||||
for _, nn := range n.Adaptations {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
}
|
||||
}
|
||||
if n.TraitAdaptationList != nil {
|
||||
vv := v.GetChildrenVisitor("TraitAdaptationList")
|
||||
n.TraitAdaptationList.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -2,9 +2,10 @@ package stmt_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/z7zmey/php-parser/node/name"
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/name"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"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{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
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{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
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{
|
||||
&stmt.TraitUsePrecedence{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUsePrecedence{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
},
|
||||
Insteadof: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
Insteadof: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Quux"},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Quux"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
Alias: &node.Identifier{Value: "two"},
|
||||
},
|
||||
Alias: &node.Identifier{Value: "two"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -92,10 +92,10 @@ var nodesToTest = []struct {
|
||||
PhpDocComment: "/** */",
|
||||
ClassName: &node.Identifier{},
|
||||
Modifiers: []node.Node{&stmt.Expression{}},
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
Extends: &node.Identifier{},
|
||||
Implements: []node.Node{&stmt.Expression{}},
|
||||
Stmts: []node.Node{&stmt.Expression{}},
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
Extends: &node.Identifier{},
|
||||
Implements: []node.Node{&stmt.Expression{}},
|
||||
Stmts: []node.Node{&stmt.Expression{}},
|
||||
},
|
||||
[]string{"ClassName", "Modifiers", "ArgumentList", "Extends", "Implements", "Stmts"},
|
||||
map[string]interface{}{"PhpDocComment": "/** */"},
|
||||
@ -408,10 +408,10 @@ var nodesToTest = []struct {
|
||||
},
|
||||
{
|
||||
&stmt.TraitUse{
|
||||
Traits: []node.Node{&stmt.Expression{}},
|
||||
Adaptations: []node.Node{&stmt.Expression{}},
|
||||
Traits: []node.Node{&stmt.Expression{}},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{},
|
||||
},
|
||||
[]string{"Traits", "Adaptations"},
|
||||
[]string{"Traits", "TraitAdaptationList"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
@ -479,6 +479,13 @@ var nodesToTest = []struct {
|
||||
[]string{"Stmts"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{&stmt.TraitUsePrecedence{}},
|
||||
},
|
||||
[]string{"Adaptations"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
}
|
||||
|
||||
type visitorMock struct {
|
||||
|
1284
php5/php5.go
1284
php5/php5.go
File diff suppressed because it is too large
Load Diff
27
php5/php5.y
27
php5/php5.y
@ -243,6 +243,7 @@ import (
|
||||
%type <node> trait_method_reference_fully_qualified trait_method_reference trait_modifiers member_modifier method
|
||||
%type <node> static_scalar_value static_operation
|
||||
%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> 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 <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 <altSyntaxNode> while_statement for_statement foreach_statement
|
||||
|
||||
@ -1550,8 +1551,16 @@ class_statement:
|
||||
trait_use_statement:
|
||||
T_USE trait_list trait_adaptations
|
||||
{
|
||||
$$ = stmt.NewTraitUse($2, $3.nodes)
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3.endToken))
|
||||
var adaptationList *stmt.TraitAdaptationList
|
||||
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())
|
||||
}
|
||||
;
|
||||
@ -1565,9 +1574,17 @@ trait_list:
|
||||
|
||||
trait_adaptations:
|
||||
';'
|
||||
{ $$ = &nodesWithEndToken{nil, $1} }
|
||||
{
|
||||
$$ = stmt.NewNop()
|
||||
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenPosition($1))
|
||||
}
|
||||
| '{' trait_adaptation_list '}'
|
||||
{ $$ = &nodesWithEndToken{$2, $3} }
|
||||
{
|
||||
$$ = stmt.NewTraitAdaptationList($2)
|
||||
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
|
||||
}
|
||||
;
|
||||
|
||||
trait_adaptation_list:
|
||||
|
@ -1455,6 +1455,7 @@ func TestPhp5(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1475,12 +1476,14 @@ func TestPhp5(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
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{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
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{
|
||||
&stmt.TraitUsePrecedence{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUsePrecedence{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
},
|
||||
Insteadof: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
Insteadof: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Quux"},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Quux"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
Alias: &node.Identifier{Value: "two"},
|
||||
},
|
||||
Alias: &node.Identifier{Value: "two"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
1058
php7/php7.go
1058
php7/php7.go
File diff suppressed because it is too large
Load Diff
47
php7/php7.y
47
php7/php7.y
@ -264,12 +264,13 @@ import (
|
||||
%type <node> isset_variable type return_type type_expr
|
||||
%type <node> class_modifier
|
||||
%type <node> argument_list ctor_arguments
|
||||
%type <node> trait_adaptations
|
||||
|
||||
%type <node> member_modifier
|
||||
%type <node> use_type
|
||||
%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> 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
|
||||
{
|
||||
$$ = 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
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3.endToken))
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $3))
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken($$, $1, comment.UseToken)
|
||||
@ -1906,11 +1917,35 @@ name_list:
|
||||
|
||||
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 '}'
|
||||
{ $$ = &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:
|
||||
|
@ -1482,6 +1482,7 @@ func TestPhp7(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1502,12 +1503,14 @@ func TestPhp7(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
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{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
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{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
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{
|
||||
&stmt.TraitUsePrecedence{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUsePrecedence{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
},
|
||||
Insteadof: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
Insteadof: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Quux"},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Quux"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
},
|
||||
Method: &node.Identifier{Value: "one"},
|
||||
Alias: &node.Identifier{Value: "two"},
|
||||
},
|
||||
Alias: &node.Identifier{Value: "two"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -2066,9 +2066,10 @@ func (p *Printer) printStmtTraitUse(n node.Node) {
|
||||
io.WriteString(p.w, "use ")
|
||||
p.joinPrint(", ", nn.Traits)
|
||||
|
||||
if nn.Adaptations != nil {
|
||||
if nn.TraitAdaptationList != nil {
|
||||
adaptations := nn.TraitAdaptationList.Adaptations
|
||||
io.WriteString(p.w, " {\n")
|
||||
p.printNodes(nn.Adaptations)
|
||||
p.printNodes(adaptations)
|
||||
io.WriteString(p.w, "\n")
|
||||
p.printIndent()
|
||||
io.WriteString(p.w, "}")
|
||||
|
@ -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: "Bar"}}},
|
||||
},
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
||||
Method: &node.Identifier{Value: "a"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
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"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -152,7 +152,7 @@ func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool {
|
||||
nsr.ResolveName(t, "")
|
||||
}
|
||||
|
||||
for _, a := range n.Adaptations {
|
||||
for _, a := range n.TraitAdaptationList.Adaptations {
|
||||
switch aa := a.(type) {
|
||||
case *stmt.TraitUsePrecedence:
|
||||
refTrait := aa.Ref.(*stmt.TraitMethodRef).Trait
|
||||
|
@ -43,8 +43,8 @@ func TestResolveStaticCall(t *testing.T) {
|
||||
},
|
||||
},
|
||||
&expr.StaticCall{
|
||||
Class: nameBC,
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
Class: nameBC,
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
},
|
||||
},
|
||||
@ -134,7 +134,7 @@ func TestResolveNew(t *testing.T) {
|
||||
},
|
||||
},
|
||||
&expr.New{
|
||||
Class: nameBC,
|
||||
Class: nameBC,
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
},
|
||||
},
|
||||
@ -242,7 +242,7 @@ func TestResolveFunctionCall(t *testing.T) {
|
||||
},
|
||||
},
|
||||
&expr.FunctionCall{
|
||||
Function: nameB,
|
||||
Function: nameB,
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
},
|
||||
},
|
||||
@ -323,11 +323,11 @@ func TestResolveGroupUse(t *testing.T) {
|
||||
Constant: nameC,
|
||||
},
|
||||
&expr.FunctionCall{
|
||||
Function: nameF,
|
||||
Function: nameF,
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
},
|
||||
&expr.FunctionCall{
|
||||
Function: nameE,
|
||||
Function: nameE,
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
},
|
||||
},
|
||||
@ -368,20 +368,22 @@ func TestResolveTraitUse(t *testing.T) {
|
||||
nameB,
|
||||
relativeNameB,
|
||||
},
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUsePrecedence{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: fullyQualifiedNameB,
|
||||
Method: &node.Identifier{Value: "foo"},
|
||||
TraitAdaptationList: &stmt.TraitAdaptationList{
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUsePrecedence{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: fullyQualifiedNameB,
|
||||
Method: &node.Identifier{Value: "foo"},
|
||||
},
|
||||
Insteadof: []node.Node{fullyQualifiedNameBC},
|
||||
},
|
||||
Insteadof: []node.Node{fullyQualifiedNameBC},
|
||||
},
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: relativeNameBC,
|
||||
Method: &node.Identifier{Value: "foo"},
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
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{
|
||||
Class: nameFG,
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
Class: nameFG,
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
},
|
||||
&stmt.Namespace{
|
||||
@ -676,13 +678,13 @@ func TestResolveNamespaces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
&expr.StaticCall{
|
||||
Class: relativeNameCE,
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
Class: relativeNameCE,
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
},
|
||||
&expr.StaticCall{
|
||||
Class: nameCF,
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
Class: nameCF,
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
},
|
||||
},
|
||||
@ -708,8 +710,8 @@ func TestResolveStaticCallDinamicClassName(t *testing.T) {
|
||||
ast := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&expr.StaticCall{
|
||||
Class: &expr.Variable{VarName: &node.Identifier{Value: "foo"}},
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
Class: &expr.Variable{VarName: &node.Identifier{Value: "foo"}},
|
||||
Call: &node.Identifier{Value: "foo"},
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user