StandardLibraryDeclaration class final

A standard implementation of LibraryDeclaration that provides access to all top-level declarations in a Dart library.

This class encapsulates information about a Dart library such as:

  • The URI of the library
  • The parent package
  • Its source location (if available)
  • Its annotations
  • All top-level declarations (e.g., classes, enums, typedefs, functions, fields, records)

You can use this class to inspect a library's structure reflectively, enabling dynamic introspection for frameworks, compilers, and development tools.

Example

final lib = StandardReflectedLibrary(
  uri: 'package:my_app/src/my_library.dart',
  parentPackage: myPackage,
  declarations: [
    myReflectedClass,
    myReflectedEnum,
    myTopLevelFunction,
  ],
);

print(lib.getUri()); // "package:my_app/src/my_library.dart"
print(lib.getClasses().length); // 1
print(lib.getTopLevelMethods().first.getName()); // e.g., "myTopLevelFunction"
Inheritance
Implemented types
Mixed-in types

Constructors

StandardLibraryDeclaration({required String uri, required Package parentPackage, required String name, required bool isPublic, required bool isSynthetic})
A standard implementation of LibraryDeclaration that provides access to all top-level declarations in a Dart library.
StandardLibraryDeclaration.empty()
Creates an empty library declaration for deserialization.
factory
StandardLibraryDeclaration.fromUri(String uri)
Creates a library declaration from a URI string for deserialization.
factory

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

equalizedProperties() → List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
override
getAnnotations() → List<AnnotationDeclaration>
Returns all annotations applied to this declaration in source code.
inherited
getDebugIdentifier() → String
Returns the stable debug identifier for this entity.
override
getIsPublic() → bool
Indicates whether this declaration is publicly visible.
inherited
getIsSynthetic() → bool
Indicates whether this declaration is synthetic.
inherited
getName() → String
Returns the simple (unqualified) name of this declaration.
inherited
getPackage() → Package
Returns the Package that contains this library.
override
getSourceLocation() → Uri?
Returns the URI pointing to the source location where this declaration is defined.
inherited
getType() → Type
Returns the Dart Type represented by this declaration.
override
getUri() → String
Returns the URI of the library.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
serialize(BinaryBuilder builder) → void
Serializes this declaration to binary format.
override
toJson() → Map<String, Object>
Serializes this declaration into a JSON-compatible map.
override
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

deserialize(BinaryReader reader) → StandardLibraryDeclaration
Deserializes a StandardLibraryDeclaration from binary format.
override