3.8 KiB
3.8 KiB
Reflection System Implementation Plan
Core Design
Following the Dart mirrors API design while maintaining cross-platform compatibility.
Mirror System
abstract class MirrorSystem {
Map<Uri, LibraryMirror> get libraries;
LibraryMirror findLibrary(Symbol libraryName);
IsolateMirror get isolate;
TypeMirror get dynamicType;
TypeMirror get voidType;
TypeMirror get neverType;
}
Core Mirrors
abstract class Mirror {}
abstract class DeclarationMirror implements Mirror {
Symbol get simpleName;
Symbol get qualifiedName;
DeclarationMirror? get owner;
bool get isPrivate;
bool get isTopLevel;
List<InstanceMirror> get metadata;
}
abstract class ObjectMirror implements Mirror {
InstanceMirror invoke(Symbol memberName, List positionalArgs, [Map<Symbol, dynamic> namedArgs]);
InstanceMirror getField(Symbol fieldName);
InstanceMirror setField(Symbol fieldName, Object? value);
}
Type System
abstract class TypeMirror implements DeclarationMirror {
bool get hasReflectedType;
Type get reflectedType;
List<TypeVariableMirror> get typeVariables;
List<TypeMirror> get typeArguments;
bool get isOriginalDeclaration;
TypeMirror get originalDeclaration;
bool isSubtypeOf(TypeMirror other);
bool isAssignableTo(TypeMirror other);
}
Implementation Phases
Phase 1: Core Mirror System
-
Basic Mirror interfaces
- Mirror base class
- DeclarationMirror
- ObjectMirror
- TypeMirror
-
Instance Reflection
- InstanceMirror implementation
- Method invocation
- Field access
- Constructor invocation
-
Type Reflection
- ClassMirror implementation
- Type information handling
- Member reflection
- Metadata support
Phase 2: Type System
-
Type Mirrors
- TypeMirror implementation
- TypeVariableMirror
- Generic type support
- Type relationships
-
Method Reflection
- MethodMirror implementation
- Parameter handling
- Return type resolution
- Invocation support
-
Field Reflection
- VariableMirror implementation
- Property access
- Field metadata
- Type checking
Phase 3: Advanced Features
-
Library Support
- LibraryMirror implementation
- Symbol resolution
- Privacy handling
- Library dependencies
-
Metadata System
- Annotation support
- Metadata reflection
- Declaration scanning
- Attribute handling
Phase 4: Platform Support
-
Web Platform
- Tree shaking support
- Minification handling
- Browser optimizations
- JS interop
-
Native Platforms
- AOT compilation support
- Native optimizations
- Memory management
- Performance tuning
Testing Strategy
Unit Tests
-
Core Functionality
- Mirror creation
- Type reflection
- Member access
- Method invocation
-
Type System
- Type relationships
- Generic handling
- Type variables
- Type metadata
Integration Tests
-
System Tests
- Full reflection scenarios
- Cross-platform behavior
- Edge cases
- Error handling
-
Performance Tests
- Memory usage
- Operation speed
- Resource management
- Platform behavior
Success Criteria
Functional
- Complete mirrors API implementation
- Cross-platform compatibility
- Full type system support
- Metadata handling
Technical
- Matches Dart mirrors behavior
- Efficient memory usage
- Fast reflection operations
- Platform optimizations
Timeline
- Phase 1: 3 weeks
- Phase 2: 3 weeks
- Phase 3: 2 weeks
- Phase 4: 2 weeks
- Total: 10 weeks
This plan focuses on implementing the core Dart mirrors API while ensuring cross-platform compatibility and performance. By following the established mirrors API, we ensure our reflection system will be familiar to Dart developers and capable of supporting any use case that the original mirrors system supports.