Declaration constructor

const Declaration()

Represents any top-level or member declaration in Dart code, such as a class, method, field, enum, typedef, etc., and exposes its metadata for reflection.

This interface provides access to:

  • The declaration's name
  • The library it belongs to
  • Attached annotations
  • Optional source location (e.g., filename or URI)

It forms the base interface for all reflectable declarations like ClassDeclaration, MethodDeclaration, and FieldDeclaration.

Example

final clazz = reflector.reflectType(MyClass).asClassType();
final methods = clazz?.getMethods();

for (final method in methods!) {
  print(method.getName());
  print(method.getSourceLocation());
}

Implementation

const Declaration();