99use Roave \BetterReflection \NodeCompiler \CompiledValue ;
1010use Roave \BetterReflection \NodeCompiler \CompileNodeToValue ;
1111use Roave \BetterReflection \NodeCompiler \CompilerContext ;
12- use Roave \BetterReflection \Reflection \Annotation \AnnotationHelper ;
12+ use Roave \BetterReflection \Reflection \Attribute \ReflectionAttributeHelper ;
13+ use Roave \BetterReflection \Reflection \Deprecated \DeprecatedHelper ;
1314use Roave \BetterReflection \Reflection \Exception \InvalidConstantNode ;
1415use Roave \BetterReflection \Reflection \StringCast \ReflectionConstantStringCast ;
1516use Roave \BetterReflection \Reflector \Exception \IdentifierNotFound ;
@@ -58,6 +59,9 @@ class ReflectionConstant implements Reflection
5859 /** @var positive-int */
5960 private int $ endColumn ;
6061
62+ /** @var list<ReflectionAttribute> */
63+ private array $ attributes ;
64+
6165 /** @psalm-allow-private-mutation */
6266 private CompiledValue |null $ compiledValue = null ;
6367
@@ -82,6 +86,9 @@ private function __construct(
8286 }
8387
8488 $ this ->docComment = GetLastDocComment::forNode ($ node );
89+ $ this ->attributes = $ node instanceof Node \Stmt \Const_
90+ ? ReflectionAttributeHelper::createAttributes ($ reflector , $ this , $ node ->attrGroups )
91+ : [];
8592
8693 $ startLine = $ node ->getStartLine ();
8794 assert ($ startLine > 0 );
@@ -227,7 +234,7 @@ public function isUserDefined(): bool
227234
228235 public function isDeprecated (): bool
229236 {
230- return AnnotationHelper ::isDeprecated ($ this -> getDocComment () );
237+ return DeprecatedHelper ::isDeprecated ($ this );
231238 }
232239
233240 public function getValueExpression (): Node \Expr
@@ -305,6 +312,28 @@ public function __toString(): string
305312 return ReflectionConstantStringCast::toString ($ this );
306313 }
307314
315+ /** @return list<ReflectionAttribute> */
316+ public function getAttributes (): array
317+ {
318+ return $ this ->attributes ;
319+ }
320+
321+ /** @return list<ReflectionAttribute> */
322+ public function getAttributesByName (string $ name ): array
323+ {
324+ return ReflectionAttributeHelper::filterAttributesByName ($ this ->getAttributes (), $ name );
325+ }
326+
327+ /**
328+ * @param class-string $className
329+ *
330+ * @return list<ReflectionAttribute>
331+ */
332+ public function getAttributesByInstance (string $ className ): array
333+ {
334+ return ReflectionAttributeHelper::filterAttributesByInstance ($ this ->getAttributes (), $ className );
335+ }
336+
308337 private function setNamesFromNode (Node \Stmt \Const_ |Node \Expr \FuncCall $ node , int |null $ positionInNode ): void
309338 {
310339 if ($ node instanceof Node \Expr \FuncCall) {
0 commit comments