DefaultClassPathResource class final

Default implementation of ClassPathResource that resolves and provides access to classes, methods, fields, and packages from the Dart runtime.

This class uses the Runtime utilities to inspect available declarations and the package URI to scope lookups to a specific package or library. It also supports reading source code as an InputStream.

Example

void main() {
  final resource = DefaultClassPathResource('package:my_app/src/user.dart');

  // Get package metadata
  final pkg = resource.getPackage();
  print('Package name: ${pkg.name}');

  // Get all classes
  final classes = resource.getClasses();
  for (final c in classes) {
    print('Class: ${c.getSimpleName()}');
  }

  // Lookup a specific class
  final userClass = resource.getClass('User');
  print('Found class: ${userClass.getSimpleName()}');

  // Access top-level methods
  final methods = resource.getMethods();
  for (final m in methods) {
    print('Method: ${m.getName()}');
  }

  // Stream source file as bytes
  final inputStream = resource.getInputStream();
  inputStream.stream.listen((chunk) {
    print('Read ${chunk.length} bytes');
  });
}
Inheritance

Constructors

DefaultClassPathResource(String packageUri)

Properties

hashCode int
The hash code for this object.
no setterinherited
packageUri String
The package URI associated with this resource.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getClass([Type? type]) Class
Retrieves a class by its name from the package.
override
getClasses() List<Class>
Returns all classes defined in the package.
override
getInputStream() InputStream
Returns a new InputStream to read the underlying content.
override
getMethod([String? methodName]) Method
Retrieves a top-level method by its name.
override
getMethods() List<Method>
Returns all top-level methods defined in the package.
override
getPackage() Package
Retrieves metadata about the package.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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