SourceLoader class

Loads and resolves Dart source files for analysis.

Uses the Dart Analyzer package to parse and resolve source files, providing access to both syntax (AST) and semantics (resolved types).

Example:

final loader = SourceLoader('lib');

// Discover all Dart files
for (final file in loader.discoverDartFiles()) {
  // Get fully resolved AST with type information
  final result = await loader.resolveFile(file);
  if (result != null) {
    print('${file}: ${result.unit.declarations.length} declarations');
  }
}

// Always dispose when done
loader.dispose();

Note: Always call dispose when finished to release analyzer resources. For automatic cleanup, use Anteater.analyzeMetrics or Anteater.analyze.

Available extensions

Constructors

SourceLoader(String projectPath)

Properties

hashCode int
The hash code for this object.
no setterinherited
irGenerator IrGenerator

Available on SourceLoader, provided by the IrGeneratorExtension extension

Creates an IR generator for this loader.
no setter
projectPath String
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

discoverDartFiles() List<String>
Returns all Dart files in the project.
dispose() Future<void>
Disposes resources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseFile(String filePath) Future<CompilationUnit?>
Parses a file without resolution (faster, syntax only).
resolveFile(String filePath) Future<ResolvedUnitResult?>
Parses a file and returns the resolved AST.
toString() String
A string representation of this object.
inherited

Operators

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