Declaration class abstract

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());
}

Example Usage

Declaration getDeclaration(dynamic element) {
  return ClassDeclaration(element.runtimeType, element.runtimeType.toString());
}

final classDecl = getDeclaration(MyClass());
print(classDecl.getName()); // "MyClass"
print(classDecl.getType()); // MyClass

{@endtemplate}

Implementers

Constructors

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.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getIsPublic() bool
Checks if this declaration is a public declaration.
getIsSynthetic() bool
Checks if a declaration is a synthetic declaration.
getName() String
Gets the name of the declared element.
getType() Type
Gets the runtime type of the declared element.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, Object>
Returns a JSON representation of this entity.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited