Skip to content

Commit 917e065

Browse files
authored
Merge pull request microsoft#341 from TysonAndre/attributes-group
Add support for PHP 8.0 `#[` attribute groups
2 parents 52e792a + 673bacf commit 917e065

File tree

198 files changed

+2268
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+2268
-69
lines changed

src/FunctionLike.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66

77
namespace Microsoft\PhpParser;
88

9+
use Microsoft\PhpParser\Node\AttributeGroup;
10+
911
/**
1012
* Interface for recognizing functions easily.
1113
* Each Node that implements this interface can be considered a function.
14+
*
15+
* @property AttributeGroup[] $attributes
1216
*/
1317
interface FunctionLike {}

src/Node/Attribute.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*---------------------------------------------------------------------------------------------
3+
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
namespace Microsoft\PhpParser\Node;
8+
9+
use Microsoft\PhpParser\Node;
10+
use Microsoft\PhpParser\Token;
11+
12+
class Attribute extends Node {
13+
/** @var Token|Node */
14+
public $name;
15+
16+
/** @var Token|null */
17+
public $openParen;
18+
19+
/** @var DelimitedList\ArgumentExpressionList|null */
20+
public $argumentExpressionList;
21+
22+
/** @var Token|null */
23+
public $closeParen;
24+
25+
const CHILD_NAMES = [
26+
'name',
27+
'openParen',
28+
'argumentExpressionList',
29+
'closeParen'
30+
];
31+
}

src/Node/AttributeGroup.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/*---------------------------------------------------------------------------------------------
3+
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
namespace Microsoft\PhpParser\Node;
8+
9+
use Microsoft\PhpParser\Node\DelimitedList\AttributeElementList;
10+
use Microsoft\PhpParser\Node;
11+
use Microsoft\PhpParser\Token;
12+
13+
class AttributeGroup extends Node {
14+
/** @var Token */
15+
public $startToken;
16+
17+
/** @var AttributeElementList */
18+
public $attributes;
19+
20+
/** @var Token */
21+
public $endToken;
22+
23+
const CHILD_NAMES = [
24+
'startToken',
25+
'attributes',
26+
'endToken'
27+
];
28+
}

src/Node/ClassConstDeclaration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
class ClassConstDeclaration extends Node implements ModifiedTypeInterface {
1515
use ModifiedTypeTrait;
1616

17+
/** @var AttributeGroup[]|null */
18+
public $attributes;
19+
20+
/** @var Token[] */
21+
public $modifiers;
22+
1723
/** @var Token */
1824
public $constKeyword;
1925

@@ -24,6 +30,7 @@ class ClassConstDeclaration extends Node implements ModifiedTypeInterface {
2430
public $semicolon;
2531

2632
const CHILD_NAMES = [
33+
'attributes',
2734
'modifiers',
2835
'constKeyword',
2936
'constElements',
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/*---------------------------------------------------------------------------------------------
3+
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
namespace Microsoft\PhpParser\Node\DelimitedList;
8+
9+
use Microsoft\PhpParser\Node\DelimitedList;
10+
11+
class AttributeElementList extends DelimitedList {
12+
}

src/Node/Expression/AnonymousFunctionCreationExpression.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AnonymousFunctionCreationExpression extends Expression implements Function
2121
use FunctionHeader, FunctionUseClause, FunctionReturnType, FunctionBody;
2222

2323
const CHILD_NAMES = [
24+
'attributes',
2425
'staticModifier',
2526

2627
// FunctionHeader

src/Node/Expression/ArrowFunctionCreationExpression.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ArrowFunctionCreationExpression extends Expression implements FunctionLike
2626
public $resultExpression;
2727

2828
const CHILD_NAMES = [
29+
'attributes',
2930
'staticModifier',
3031

3132
// FunctionHeader

src/Node/FunctionHeader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Microsoft\PhpParser\Token;
1010

1111
trait FunctionHeader {
12+
/** @var AttributeGroup[]|null */
13+
public $attributes;
1214
/** @var Token */
1315
public $functionKeyword;
1416
/** @var Token */

src/Node/MethodDeclaration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class MethodDeclaration extends Node implements FunctionLike, ModifiedTypeInterf
2020
use FunctionHeader, FunctionReturnType, FunctionBody, ModifiedTypeTrait;
2121

2222
const CHILD_NAMES = [
23+
'attributes',
2324
'modifiers',
2425

2526
// FunctionHeader

src/Node/MissingDeclaration.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/*---------------------------------------------------------------------------------------------
3+
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
namespace Microsoft\PhpParser\Node;
8+
9+
use Microsoft\PhpParser\Node;
10+
use Microsoft\PhpParser\MissingToken;
11+
12+
class MissingDeclaration extends Node {
13+
/** @var AttributeGroup[] */
14+
public $attributes;
15+
16+
/** @var MissingToken needed for emitting diagnostics */
17+
public $declaration;
18+
19+
const CHILD_NAMES = [
20+
'attributes',
21+
'declaration',
22+
];
23+
}

0 commit comments

Comments
 (0)