AssetsGraph class

A graph of Dart assets and their dependencies.

The AssetsGraph tracks all Dart files in the project, their declarations, and the relationships between them (imports, exports, parts).

It provides methods to:

  • Query assets by package
  • Look up declarations
  • Trace dependencies between files
  • Track generated outputs
  • Determine which assets need processing

The graph can be persisted to disk to improve build performance across runs.

Constructors

AssetsGraph(String hash)
A graph of Dart assets and their dependencies.
AssetsGraph.fromCache(Map<String, dynamic> json, String hash)
Creates an AssetsGraph from cached JSON data.
factory
AssetsGraph.init(String hash)
Initialize an assets graph, loading from cache if possible.
factory

Properties

assets HashMap<String, List>
Represents the all the assets the scanner has seen. including the assets that are not processed yet (directives)
finalinherited
directives HashMap<String, List<List>>
Represents the directives that have been found in the scanned assets.
finalinherited
hash String
A hash of the build configuration
final
hashCode int
The hash code for this object.
no setterinherited
identifiers List<List>
Represents the identifiers that have been found in the scanned assets.
finalinherited
loadedFromCache bool
Whether the graph was loaded from cache
final
outputs HashMap<String, Set<String>>
the generated outputs sources of a file
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shouldInvalidate bool
Whether the cached graph should be invalidated
final

Methods

addAsset(Asset asset) String
Adds an asset to the asset graph.
inherited
addDeclaration(String identifier, Asset declaringFile, ReferenceType type) → void
Adds A declaration to the asset graph.
inherited
addDirective(Asset src, DirectiveStatement statement) → void
Adds a directive to the asset graph.
inherited
addLibraryPartOf(String stringUri, Asset asset) → void
Adds a library part-of directive to the asset graph.
inherited
addOutput(Asset asset, Asset output) → void
Registers a generated output as being produced by an asset.
clearAll() → void
Clears all data from the graph.
dependentsOf(String id) Map<String, List>
Returns all assets that depend on a specific asset.
exportedSymbolsOf(String id) List<ExportedSymbol>
Returns all symbols exported by a specific asset.
exportsOf(String fileId, {bool includeParts = true}) List<List>
Returns a list of all the exports and parts of a file.
inherited
getAssetsForPackages(Set<String> packages) List<ScannedAsset>
Returns all assets for a specific package.
getBuilderProcessableAssets(PackageFileResolver fileResolver) Set<ProcessableAsset>
Returns all assets that need to be processed by builders.
getDeclarationRef(String identifier, Asset importingSrc, {String? importPrefix}) → DeclarationRef?
Looks up a declaration reference for an identifier.
getExposedIdentifiersInside(String fileHash) Map<String, String>
Returns all identifiers exposed within a file through imports.
getGeneratorOfOutput(String id) String?
Returns the ID of the asset that generated a specific output.
getInputOf(String id) List?
Returns the data for the input asset that generated a specific output.
getParentSrc(String fileId) String
Returns the parent source of a file.
inherited
getProcessableAssets(PackageFileResolver fileResolver) Set<ProcessableAsset>
Returns all assets that need to be processed.
hasProcessableAssets() bool
Returns whether there are any assets that need to be processed.
identifiersForAsset(String src) Set<String>
Returns all identifiers declared in a specific asset.
importPrefixesOf(String id) Set<String>
Returns all the prefixes of the imports of a file.
inherited
importsOf(String fileId, {bool includeParts = true}) List<List>
Returns a list of all the imports and parts of a file.
inherited
invalidateDigest(String assetId) → void
Invalidates the digest of an asset, forcing it to be reprocessed.
invalidateProcessedAssetsOf(String package) → void
Marks all assets from a package as needing to be reprocessed.
isAGeneratedSource(String id) bool
Returns whether an asset is a generated output.
isBuilderConfigAsset(String id) bool
Returns whether an asset has builder annotations.
isVisited(String fileId) bool
Returns true if the file has been visited.
inherited
lookupIdentifier(String identifier, String src) List?
Looks up an identifier in the identifiers list.
inherited
lookupIdentifierByProvider(String name, String providerSrc) → DeclarationRef?
Looks up an identifier using its provider source.
merge(ScanResults results) → void
Merges the results of another scan into this one.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
partOfOf(String fileId) List?
Returns a the first part-of directive of a file.
inherited
partsOf(String fileId) List<List>
Returns a list of all the parts of a file.
inherited
removeAsset(String id) → void
Removes an asset from the asset graph
inherited
removeOutput(String output) → void
Removes an output asset from the graph.
save() Future<void>
Saves the graph to disk for future use.
toJson() Map<String, dynamic>
Converts the graph to a JSON-serializable map.
toString() String
A string representation of this object.
inherited
updateAssetInfo(Asset asset, {required Uint8List content, int tlmFlag = 0, String? libraryName}) → void
Updates the asset information in the asset graph.
inherited
updateAssetState(String id, AssetState state) → void
Updates the asset state in the asset graph.
inherited
uriForAsset(String id) Uri
Returns the URI of an asset by its ID.
inherited
uriForAssetOrNull(String id) Uri?
Returns the URI of an asset by its ID, or null if not found.
inherited

Operators

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

Static Properties

cacheFile File
File where the assets graph cache is stored
final

Static Methods

invalidateCache() → void
Invalidates the cached graph, forcing a rebuild

Constants

version → const String
Version of the graph format