LibraryDeclaration class abstract

Represents a Dart library, providing access to its URI, the containing package, and all top-level declarations inside it.

Libraries in Dart map directly to .dart files and can expose multiple classes, functions, and constants.

Example

final library = reflector.getLibraries().firstWhere(
  (lib) => lib.getUri().contains('my_library.dart'),
);
print(library.getParentPackage().getName());
for (final decl in library.getDeclarations()) {
  print(decl.getName());
}
Inheritance

Constructors

LibraryDeclaration()
Represents a Dart library, providing access to its URI, the containing package, and all top-level declarations inside it.
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

getAnnotations() List<AnnotationDeclaration>
Returns all annotations applied to this declaration.
inherited
getClasses() List<ClassDeclaration>
Returns all ClassDeclaration instances declared directly in this library.
getDartType() → DartType?
The analyzer DartType of the entity for enhanced type operations.
inherited
getDebugIdentifier() String
The debug identifier for the entity.
inherited
getDeclarations() List<SourceDeclaration>
Returns all top-level SourceDeclarations in the library.
getElement() → Element?
The analyzer element associated with this declaration.
inherited
getEnums() List<EnumDeclaration>
Returns all EnumDeclaration instances declared directly in this library.
getExtensions() List<ExtensionDeclaration>
Returns all ExtensionDeclaration instances declared directly in this library.
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.
override
getPackage() Package
Returns the Package that this library is part of.
getParentLibrary() LibraryDeclaration
Returns the LibraryDeclaration in which this declaration is defined.
inherited
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.
inherited
getTopLevelFields() List<FieldDeclaration>
Returns all top-level FieldDeclaration instances declared directly in this library.
getTopLevelMethods() List<MethodDeclaration>
Returns all top-level MethodDeclaration instances declared directly in this library.
getTopLevelRecordFields() List<RecordFieldDeclaration>
Returns all top-level RecordFieldDeclaration instances declared directly in this library.
getTopLevelRecords() List<RecordDeclaration>
Returns all top-level RecordDeclaration instances declared directly in this library.
getType() Type
Gets the runtime type of the declared element.
inherited
getTypedefs() List<TypedefDeclaration>
Returns all TypedefDeclaration instances declared directly in this library.
getUri() String
Returns the URI of the library (e.g., 'package:my_app/main.dart').
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.
inherited
toString() String
A string representation of this object.
inherited

Operators

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