SourceDeclaration class abstract interface

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

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

getAnnotations() List<AnnotationDeclaration>
Returns all annotations applied to this declaration.
getDartType() → DartType?
The analyzer DartType of the entity for enhanced type operations.
inherited
getDebugIdentifier() String
The debug identifier for the entity.
override
getElement() → Element?
The analyzer element associated with this declaration.
inherited
getIsPublic() bool
Checks if this declaration is a public declaration.
inherited
getIsSynthetic() bool
Checks if a declaration is a synthetic declaration.
inherited
getName() String
Gets the name of the declared element.
inherited
getParentLibrary() LibraryDeclaration
Returns the LibraryDeclaration in which this declaration is defined.
getSourceLocation() Uri?
Returns the source code location (e.g., file path or URI) where this declaration is defined, or null if not available in the current reflection context.
getType() Type
Gets the runtime type of the declared element.
inherited
hasAnalyzerSupport() bool
Returns true if this declaration has analyzer information available.
inherited
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.
override
toString() String
A string representation of this object.
inherited

Operators

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