-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for PHP Attributes
- Show `<<attribute>>` stereotype for Attribute classes (Annotations)
- Loading branch information
1 parent
7158b92
commit df4c134
Showing
20 changed files
with
172 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* PHP version 8.1 | ||
* | ||
* This source file is subject to the license that is bundled with this package in the file LICENSE. | ||
*/ | ||
|
||
namespace PhUml\Parser\Code\Builders; | ||
|
||
use Attribute; | ||
use PhpParser\Node\Stmt\Class_; | ||
|
||
final class AttributeAnalyzer | ||
{ | ||
public function isAttribute(Class_ $class): bool | ||
{ | ||
return $class->attrGroups !== [] | ||
&& $class->attrGroups[0]->attrs !== [] | ||
&& (string) $class->attrGroups[0]->attrs[0]->name === Attribute::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
#[Attribute] | ||
class Listener { | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* PHP version 8.1 | ||
* | ||
* This source file is subject to the license that is bundled with this package in the file LICENSE. | ||
*/ | ||
|
||
namespace PhUml\Parser\Code\Builders; | ||
|
||
use PhpParser\Node\Attribute; | ||
use PhpParser\Node\AttributeGroup; | ||
use PhpParser\Node\Identifier; | ||
use PhpParser\Node\Name; | ||
use PhpParser\Node\Stmt\Class_; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AttributeAnalyzerTest extends TestCase | ||
{ | ||
/** @test */ | ||
function it_detects_attribute_classes() | ||
{ | ||
$attributeClass = new Class_(new Identifier('AnAttributeClass'), [ | ||
'attrGroups' => [ | ||
new AttributeGroup([ | ||
new Attribute(new Name('Attribute')), | ||
]), | ||
], | ||
]); | ||
$annotatedClass = new Class_(new Identifier('AnAnnotatedClass'), [ | ||
'attrGroups' => [ | ||
new AttributeGroup( | ||
[ | ||
new Attribute(new Name('Command')), | ||
] | ||
), | ||
], | ||
]); | ||
$regularClass = new Class_(new Identifier('ARegularClass')); | ||
$analyzer = new AttributeAnalyzer(); | ||
|
||
$isAttribute = $analyzer->isAttribute($attributeClass); | ||
$isNotAttribute = $analyzer->isAttribute($regularClass); | ||
$isAnnotatedBuNotAttribute = $analyzer->isAttribute($annotatedClass); | ||
|
||
$this->assertTrue($isAttribute, 'It should have detected this is an attribute class'); | ||
$this->assertFalse($isNotAttribute, 'It should have detected this is not an attribute class'); | ||
$this->assertFalse($isAnnotatedBuNotAttribute, 'It should have detected this is not an attribute class'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.