refactor: refactoring reflection system pass 43 fail 1
This commit is contained in:
parent
8bab6aa4b8
commit
14e1fc099d
63 changed files with 1621 additions and 666 deletions
|
@ -1,4 +1,4 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
// Custom annotation to demonstrate metadata
|
||||
class Validate {
|
||||
|
|
60
incubation/reflection/lib/mirrors.dart
Normal file
60
incubation/reflection/lib/mirrors.dart
Normal file
|
@ -0,0 +1,60 @@
|
|||
library mirrors;
|
||||
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
|
||||
import 'src/mirrors/mirror_system.dart';
|
||||
import 'src/mirrors/instance_mirror.dart';
|
||||
|
||||
/// Core
|
||||
export 'src/core/library_scanner.dart';
|
||||
export 'src/core/reflector.dart';
|
||||
export 'src/core/runtime_reflector.dart';
|
||||
export 'src/core/scanner.dart';
|
||||
|
||||
/// MirrorSystem
|
||||
export 'src/mirrors/mirror_system.dart';
|
||||
|
||||
/// Mirrors
|
||||
export 'src/mirrors/base_mirror.dart';
|
||||
export 'src/mirrors/class_mirror.dart';
|
||||
export 'src/mirrors/combinator_mirror.dart';
|
||||
export 'src/mirrors/instance_mirror.dart';
|
||||
export 'src/mirrors/isolate_mirror.dart';
|
||||
export 'src/mirrors/library_dependency_mirror.dart';
|
||||
export 'src/mirrors/library_mirror.dart';
|
||||
export 'src/mirrors/method_mirror.dart';
|
||||
export 'src/mirrors/parameter_mirror.dart';
|
||||
export 'src/mirrors/type_mirror.dart';
|
||||
export 'src/mirrors/type_variable_mirror.dart';
|
||||
export 'src/mirrors/variable_mirror.dart';
|
||||
|
||||
/// Types
|
||||
export 'src/mirrors/special_types.dart';
|
||||
|
||||
/// Metadata and Annotations
|
||||
export 'src/annotations.dart';
|
||||
export 'src/metadata.dart';
|
||||
|
||||
/// Exceptions
|
||||
export 'src/exceptions.dart';
|
||||
|
||||
/// Reflects an instance.
|
||||
InstanceMirrorContract reflect(dynamic reflectee) {
|
||||
return InstanceMirror(
|
||||
reflectee: reflectee,
|
||||
type: reflectClass(reflectee.runtimeType),
|
||||
);
|
||||
}
|
||||
|
||||
/// Reflects a class.
|
||||
ClassMirrorContract reflectClass(Type key) {
|
||||
return MirrorSystem.instance.reflectClass(key);
|
||||
}
|
||||
|
||||
/// Reflects a type.
|
||||
TypeMirrorContract reflectType(Type key) {
|
||||
return MirrorSystem.instance.reflectType(key);
|
||||
}
|
||||
|
||||
/// Returns the current mirror system.
|
||||
MirrorSystemContract currentMirrorSystem() => MirrorSystem.current();
|
|
@ -1,18 +0,0 @@
|
|||
/// A lightweight, cross-platform reflection system for Dart.
|
||||
library reflection;
|
||||
|
||||
// Core functionality
|
||||
export 'src/core/reflector.dart';
|
||||
export 'src/core/scanner.dart';
|
||||
export 'src/core/runtime_reflector.dart';
|
||||
|
||||
// Mirror API
|
||||
export 'src/mirrors.dart';
|
||||
export 'src/mirrors/isolate_mirror_impl.dart' show IsolateMirrorImpl;
|
||||
|
||||
// Metadata and annotations
|
||||
export 'src/metadata.dart';
|
||||
export 'src/annotations.dart' show reflectable;
|
||||
|
||||
// Exceptions
|
||||
export 'src/exceptions.dart';
|
|
@ -1,4 +1,4 @@
|
|||
import 'metadata.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Registry of reflectable types and their metadata.
|
||||
class ReflectionRegistry {
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import 'dart:core';
|
||||
import '../metadata.dart';
|
||||
import '../mirrors.dart';
|
||||
import '../mirrors/mirror_system_impl.dart';
|
||||
import '../mirrors/special_types.dart';
|
||||
import '../exceptions.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Runtime scanner that analyzes libraries and extracts their metadata.
|
||||
class LibraryScanner {
|
||||
|
@ -89,7 +86,7 @@ class LibraryAnalyzer {
|
|||
),
|
||||
],
|
||||
returnsVoid: false,
|
||||
returnType: InstanceMirror,
|
||||
returnType: InstanceMirrorContract,
|
||||
isPrivate: false,
|
||||
),
|
||||
FunctionInfo(
|
||||
|
@ -104,7 +101,7 @@ class LibraryAnalyzer {
|
|||
),
|
||||
],
|
||||
returnsVoid: false,
|
||||
returnType: ClassMirror,
|
||||
returnType: ClassMirrorContract,
|
||||
isPrivate: false,
|
||||
),
|
||||
]);
|
||||
|
@ -112,7 +109,7 @@ class LibraryAnalyzer {
|
|||
variables.addAll([
|
||||
VariableInfo(
|
||||
name: 'currentMirrorSystem',
|
||||
type: MirrorSystem,
|
||||
type: MirrorSystemContract,
|
||||
isFinal: true,
|
||||
isConst: false,
|
||||
isPrivate: false,
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import 'dart:collection';
|
||||
import '../metadata.dart';
|
||||
import '../mirrors.dart';
|
||||
import '../mirrors/mirrors.dart';
|
||||
import '../mirrors/special_types.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Static registry for reflection metadata.
|
||||
class Reflector {
|
||||
|
|
|
@ -1,22 +1,6 @@
|
|||
import 'package:meta/meta.dart';
|
||||
import 'dart:isolate' as isolate;
|
||||
import '../exceptions.dart';
|
||||
import '../metadata.dart';
|
||||
import '../mirrors.dart';
|
||||
import 'reflector.dart';
|
||||
import '../mirrors/base_mirror.dart';
|
||||
import '../mirrors/class_mirror_impl.dart';
|
||||
import '../mirrors/instance_mirror_impl.dart';
|
||||
import '../mirrors/method_mirror_impl.dart';
|
||||
import '../mirrors/parameter_mirror_impl.dart';
|
||||
import '../mirrors/type_mirror_impl.dart';
|
||||
import '../mirrors/type_variable_mirror_impl.dart';
|
||||
import '../mirrors/variable_mirror_impl.dart';
|
||||
import '../mirrors/library_mirror_impl.dart';
|
||||
import '../mirrors/library_dependency_mirror_impl.dart';
|
||||
import '../mirrors/isolate_mirror_impl.dart';
|
||||
import '../mirrors/mirror_system_impl.dart';
|
||||
import '../mirrors/special_types.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// A pure runtime reflection system that provides type introspection and manipulation.
|
||||
class RuntimeReflector {
|
||||
|
@ -24,26 +8,26 @@ class RuntimeReflector {
|
|||
static final instance = RuntimeReflector._();
|
||||
|
||||
/// The current mirror system.
|
||||
late final MirrorSystemImpl _mirrorSystem;
|
||||
late final MirrorSystem _mirrorSystem;
|
||||
|
||||
/// Cache of class mirrors to prevent infinite recursion
|
||||
final Map<Type, ClassMirror> _classMirrorCache = {};
|
||||
final Map<Type, ClassMirrorContract> _classMirrorCache = {};
|
||||
|
||||
RuntimeReflector._() {
|
||||
// Initialize mirror system
|
||||
_mirrorSystem = MirrorSystemImpl.current();
|
||||
_mirrorSystem = MirrorSystem.current();
|
||||
}
|
||||
|
||||
/// Resolves parameters for method or constructor invocation
|
||||
List<dynamic> resolveParameters(
|
||||
List<ParameterMirror> parameters,
|
||||
List<ParameterMirrorContract> parameters,
|
||||
List<dynamic> positionalArgs,
|
||||
Map<Symbol, dynamic>? namedArgs,
|
||||
) {
|
||||
final resolvedArgs = List<dynamic>.filled(parameters.length, null);
|
||||
var positionalIndex = 0;
|
||||
|
||||
ClassMirror? _getClassMirror(Type? type) {
|
||||
ClassMirrorContract? _getClassMirror(Type? type) {
|
||||
if (type == null) return null;
|
||||
try {
|
||||
return reflectClass(type);
|
||||
|
@ -52,7 +36,7 @@ class RuntimeReflector {
|
|||
}
|
||||
}
|
||||
|
||||
bool _isTypeCompatible(dynamic value, TypeMirror expectedType) {
|
||||
bool _isTypeCompatible(dynamic value, TypeMirrorContract expectedType) {
|
||||
// Handle null values
|
||||
if (value == null) {
|
||||
// For now, accept null for any type as we don't have nullability information
|
||||
|
@ -81,7 +65,7 @@ class RuntimeReflector {
|
|||
}
|
||||
|
||||
// Handle generic type parameters
|
||||
if (expectedType is TypeVariableMirrorImpl) {
|
||||
if (expectedType is TypeVariableMirror) {
|
||||
return _isTypeCompatible(value, expectedType.upperBound);
|
||||
}
|
||||
|
||||
|
@ -198,9 +182,9 @@ class RuntimeReflector {
|
|||
// Resolve parameters using constructor metadata
|
||||
final resolvedArgs = resolveParameters(
|
||||
constructor.parameters
|
||||
.map((param) => ParameterMirrorImpl(
|
||||
.map((param) => ParameterMirror(
|
||||
name: param.name,
|
||||
type: TypeMirrorImpl(
|
||||
type: TypeMirror(
|
||||
type: param.type,
|
||||
name: param.type.toString(),
|
||||
owner: mirror,
|
||||
|
@ -242,14 +226,15 @@ class RuntimeReflector {
|
|||
}
|
||||
|
||||
/// Creates a TypeMirror for a given type.
|
||||
TypeMirror _createTypeMirror(Type type, String name, [ClassMirror? owner]) {
|
||||
TypeMirrorContract _createTypeMirror(Type type, String name,
|
||||
[ClassMirrorContract? owner]) {
|
||||
if (type == voidType) {
|
||||
return TypeMirrorImpl.voidType(owner);
|
||||
return TypeMirror.voidType(owner);
|
||||
}
|
||||
if (type == dynamicType) {
|
||||
return TypeMirrorImpl.dynamicType(owner);
|
||||
return TypeMirror.dynamicType(owner);
|
||||
}
|
||||
return TypeMirrorImpl(
|
||||
return TypeMirror(
|
||||
type: type,
|
||||
name: name,
|
||||
owner: owner,
|
||||
|
@ -258,7 +243,7 @@ class RuntimeReflector {
|
|||
}
|
||||
|
||||
/// Reflects on a type, returning its class mirror.
|
||||
ClassMirror reflectClass(Type type) {
|
||||
ClassMirrorContract reflectClass(Type type) {
|
||||
// Check cache first
|
||||
if (_classMirrorCache.containsKey(type)) {
|
||||
return _classMirrorCache[type]!;
|
||||
|
@ -270,7 +255,7 @@ class RuntimeReflector {
|
|||
}
|
||||
|
||||
// Create empty mirror and add to cache to break recursion
|
||||
final emptyMirror = ClassMirrorImpl(
|
||||
final emptyMirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
|
@ -288,11 +273,11 @@ class RuntimeReflector {
|
|||
final typeMetadata = Reflector.getTypeMetadata(type);
|
||||
|
||||
// Create declarations map
|
||||
final declarations = <Symbol, DeclarationMirror>{};
|
||||
final declarations = <Symbol, DeclarationMirrorContract>{};
|
||||
|
||||
// Add properties as variable declarations
|
||||
properties.forEach((name, prop) {
|
||||
declarations[Symbol(name)] = VariableMirrorImpl(
|
||||
declarations[Symbol(name)] = VariableMirror(
|
||||
name: name,
|
||||
type: _createTypeMirror(prop.type, prop.type.toString(), emptyMirror),
|
||||
owner: emptyMirror,
|
||||
|
@ -305,15 +290,15 @@ class RuntimeReflector {
|
|||
|
||||
// Add methods as method declarations
|
||||
methods.forEach((name, method) {
|
||||
declarations[Symbol(name)] = MethodMirrorImpl(
|
||||
declarations[Symbol(name)] = MethodMirror(
|
||||
name: name,
|
||||
owner: emptyMirror,
|
||||
returnType: method.returnsVoid
|
||||
? TypeMirrorImpl.voidType(emptyMirror)
|
||||
? TypeMirror.voidType(emptyMirror)
|
||||
: _createTypeMirror(
|
||||
method.returnType, method.returnType.toString(), emptyMirror),
|
||||
parameters: method.parameters
|
||||
.map((param) => ParameterMirrorImpl(
|
||||
.map((param) => ParameterMirror(
|
||||
name: param.name,
|
||||
type: _createTypeMirror(
|
||||
param.type, param.type.toString(), emptyMirror),
|
||||
|
@ -334,12 +319,12 @@ class RuntimeReflector {
|
|||
|
||||
// Add constructors as method declarations
|
||||
for (final ctor in constructors) {
|
||||
declarations[Symbol(ctor.name)] = MethodMirrorImpl(
|
||||
declarations[Symbol(ctor.name)] = MethodMirror(
|
||||
name: ctor.name,
|
||||
owner: emptyMirror,
|
||||
returnType: emptyMirror,
|
||||
parameters: ctor.parameters
|
||||
.map((param) => ParameterMirrorImpl(
|
||||
.map((param) => ParameterMirror(
|
||||
name: param.name,
|
||||
type: _createTypeMirror(
|
||||
param.type, param.type.toString(), emptyMirror),
|
||||
|
@ -360,11 +345,11 @@ class RuntimeReflector {
|
|||
}
|
||||
|
||||
// Create instance and static member maps
|
||||
final instanceMembers = <Symbol, MethodMirror>{};
|
||||
final staticMembers = <Symbol, MethodMirror>{};
|
||||
final instanceMembers = <Symbol, MethodMirrorContract>{};
|
||||
final staticMembers = <Symbol, MethodMirrorContract>{};
|
||||
|
||||
methods.forEach((name, method) {
|
||||
final methodMirror = declarations[Symbol(name)] as MethodMirror;
|
||||
final methodMirror = declarations[Symbol(name)] as MethodMirrorContract;
|
||||
if (method.isStatic) {
|
||||
staticMembers[Symbol(name)] = methodMirror;
|
||||
} else {
|
||||
|
@ -373,7 +358,7 @@ class RuntimeReflector {
|
|||
});
|
||||
|
||||
// Create class mirror
|
||||
final mirror = ClassMirrorImpl(
|
||||
final mirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
|
@ -403,7 +388,7 @@ class RuntimeReflector {
|
|||
}
|
||||
|
||||
/// Reflects on a type, returning its type mirror.
|
||||
TypeMirror reflectType(Type type) {
|
||||
TypeMirrorContract reflectType(Type type) {
|
||||
// Check if type is reflectable
|
||||
if (!Reflector.isReflectable(type)) {
|
||||
throw NotReflectableException(type);
|
||||
|
@ -413,22 +398,22 @@ class RuntimeReflector {
|
|||
}
|
||||
|
||||
/// Creates a new instance reflector for the given object.
|
||||
InstanceMirror reflect(Object instance) {
|
||||
InstanceMirrorContract reflect(Object instance) {
|
||||
// Check if type is reflectable
|
||||
if (!Reflector.isReflectable(instance.runtimeType)) {
|
||||
throw NotReflectableException(instance.runtimeType);
|
||||
}
|
||||
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: instance,
|
||||
type: reflectClass(instance.runtimeType),
|
||||
);
|
||||
}
|
||||
|
||||
/// Reflects on a library, returning its library mirror.
|
||||
LibraryMirror reflectLibrary(Uri uri) {
|
||||
LibraryMirrorContract reflectLibrary(Uri uri) {
|
||||
// Create library mirror with declarations
|
||||
final library = LibraryMirrorImpl.withDeclarations(
|
||||
final library = LibraryMirror.withDeclarations(
|
||||
name: uri.toString(),
|
||||
uri: uri,
|
||||
owner: null,
|
||||
|
@ -443,30 +428,30 @@ class RuntimeReflector {
|
|||
}
|
||||
|
||||
/// Gets library dependencies for a given URI.
|
||||
List<LibraryDependencyMirror> _getLibraryDependencies(Uri uri) {
|
||||
List<LibraryDependencyMirrorContract> _getLibraryDependencies(Uri uri) {
|
||||
// Create source library
|
||||
final sourceLibrary = LibraryMirrorImpl.withDeclarations(
|
||||
final sourceLibrary = LibraryMirror.withDeclarations(
|
||||
name: uri.toString(),
|
||||
uri: uri,
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create core library as target
|
||||
final coreLibrary = LibraryMirrorImpl.withDeclarations(
|
||||
final coreLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart:core',
|
||||
uri: Uri.parse('dart:core'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create test library as target
|
||||
final testLibrary = LibraryMirrorImpl.withDeclarations(
|
||||
final testLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'package:test/test.dart',
|
||||
uri: Uri.parse('package:test/test.dart'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create reflection library as target
|
||||
final reflectionLibrary = LibraryMirrorImpl.withDeclarations(
|
||||
final reflectionLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'package:platform_reflection/reflection.dart',
|
||||
uri: Uri.parse('package:platform_reflection/reflection.dart'),
|
||||
owner: null,
|
||||
|
@ -474,7 +459,7 @@ class RuntimeReflector {
|
|||
|
||||
return [
|
||||
// Import dependencies
|
||||
LibraryDependencyMirrorImpl(
|
||||
LibraryDependencyMirror(
|
||||
isImport: true,
|
||||
isDeferred: false,
|
||||
sourceLibrary: sourceLibrary,
|
||||
|
@ -482,7 +467,7 @@ class RuntimeReflector {
|
|||
prefix: null,
|
||||
combinators: const [],
|
||||
),
|
||||
LibraryDependencyMirrorImpl(
|
||||
LibraryDependencyMirror(
|
||||
isImport: true,
|
||||
isDeferred: false,
|
||||
sourceLibrary: sourceLibrary,
|
||||
|
@ -490,7 +475,7 @@ class RuntimeReflector {
|
|||
prefix: null,
|
||||
combinators: const [],
|
||||
),
|
||||
LibraryDependencyMirrorImpl(
|
||||
LibraryDependencyMirror(
|
||||
isImport: true,
|
||||
isDeferred: false,
|
||||
sourceLibrary: sourceLibrary,
|
||||
|
@ -499,7 +484,7 @@ class RuntimeReflector {
|
|||
combinators: const [],
|
||||
),
|
||||
// Export dependencies
|
||||
LibraryDependencyMirrorImpl(
|
||||
LibraryDependencyMirror(
|
||||
isImport: false,
|
||||
isDeferred: false,
|
||||
sourceLibrary: sourceLibrary,
|
||||
|
@ -511,11 +496,12 @@ class RuntimeReflector {
|
|||
}
|
||||
|
||||
/// Returns a mirror on the current isolate.
|
||||
IsolateMirror get currentIsolate => _mirrorSystem.isolate;
|
||||
IsolateMirrorContract get currentIsolate => _mirrorSystem.isolate;
|
||||
|
||||
/// Creates a mirror for another isolate.
|
||||
IsolateMirror reflectIsolate(isolate.Isolate isolate, String debugName) {
|
||||
return IsolateMirrorImpl.other(
|
||||
IsolateMirrorContract reflectIsolate(
|
||||
isolate.Isolate isolate, String debugName) {
|
||||
return IsolateMirror.other(
|
||||
isolate,
|
||||
debugName,
|
||||
reflectLibrary(Uri.parse('dart:core')),
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
import 'dart:core';
|
||||
import '../metadata.dart';
|
||||
import 'reflector.dart';
|
||||
import '../mirrors.dart';
|
||||
import '../mirrors/mirror_system_impl.dart';
|
||||
import '../mirrors/special_types.dart';
|
||||
import '../exceptions.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Runtime scanner that analyzes types and extracts their metadata.
|
||||
class Scanner {
|
||||
|
@ -22,7 +17,7 @@ class Scanner {
|
|||
Reflector.register(type);
|
||||
|
||||
// Get mirror system and analyze type
|
||||
final mirrorSystem = MirrorSystemImpl.current();
|
||||
//final mirrorSystem = MirrorSystem.current();
|
||||
final typeInfo = TypeAnalyzer.analyze(type);
|
||||
|
||||
// Convert properties, methods, and constructors to metadata
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'exceptions.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Represents metadata about a type parameter.
|
||||
class TypeParameterMetadata {
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
import 'dart:core';
|
||||
import 'mirrors.dart';
|
||||
import 'mirrors/class_mirror_impl.dart';
|
||||
import 'mirrors/instance_mirror_impl.dart';
|
||||
import 'mirrors/library_mirror_impl.dart';
|
||||
import 'mirrors/type_mirror_impl.dart';
|
||||
import 'mirrors/isolate_mirror_impl.dart';
|
||||
import 'mirrors/special_types.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// The default implementation of [MirrorSystem].
|
||||
class RuntimeMirrorSystem implements MirrorSystem {
|
||||
/// The default implementation of [MirrorSystemContract].
|
||||
class RuntimeMirrorSystem implements MirrorSystemContract {
|
||||
/// The singleton instance of the mirror system.
|
||||
static final instance = RuntimeMirrorSystem._();
|
||||
|
||||
|
@ -16,16 +11,16 @@ class RuntimeMirrorSystem implements MirrorSystem {
|
|||
_initializeRootLibrary();
|
||||
}
|
||||
|
||||
final Map<Uri, LibraryMirror> _libraries = {};
|
||||
final Map<Type, ClassMirror> _classes = {};
|
||||
final Map<Type, TypeMirror> _types = {};
|
||||
late final LibraryMirror _rootLibrary;
|
||||
final Map<Uri, LibraryMirrorContract> _libraries = {};
|
||||
final Map<Type, ClassMirrorContract> _classes = {};
|
||||
final Map<Type, TypeMirrorContract> _types = {};
|
||||
late final LibraryMirrorContract _rootLibrary;
|
||||
|
||||
@override
|
||||
Map<Uri, LibraryMirror> get libraries => Map.unmodifiable(_libraries);
|
||||
Map<Uri, LibraryMirrorContract> get libraries => Map.unmodifiable(_libraries);
|
||||
|
||||
@override
|
||||
LibraryMirror findLibrary(Symbol libraryName) {
|
||||
LibraryMirrorContract findLibrary(Symbol libraryName) {
|
||||
final lib = _libraries.values.firstWhere(
|
||||
(lib) => lib.qualifiedName == libraryName,
|
||||
orElse: () => throw ArgumentError('Library not found: $libraryName'),
|
||||
|
@ -34,30 +29,31 @@ class RuntimeMirrorSystem implements MirrorSystem {
|
|||
}
|
||||
|
||||
@override
|
||||
IsolateMirror get isolate => IsolateMirrorImpl.current(_rootLibrary);
|
||||
IsolateMirrorContract get isolate => IsolateMirror.current(_rootLibrary);
|
||||
|
||||
@override
|
||||
TypeMirror get dynamicType => _getOrCreateTypeMirror(dynamic);
|
||||
TypeMirrorContract get dynamicType => _getOrCreateTypeMirror(dynamic);
|
||||
|
||||
@override
|
||||
TypeMirror get voidType => _getOrCreateTypeMirror(VoidType);
|
||||
TypeMirrorContract get voidType => _getOrCreateTypeMirror(VoidType);
|
||||
|
||||
@override
|
||||
TypeMirror get neverType => _getOrCreateTypeMirror(NeverType);
|
||||
TypeMirrorContract get neverType => _getOrCreateTypeMirror(NeverType);
|
||||
|
||||
/// Creates a mirror reflecting [reflectee].
|
||||
InstanceMirror reflect(Object reflectee) {
|
||||
return InstanceMirrorImpl(
|
||||
InstanceMirrorContract reflect(Object reflectee) {
|
||||
return InstanceMirror(
|
||||
reflectee: reflectee,
|
||||
type: reflectClass(reflectee.runtimeType),
|
||||
);
|
||||
}
|
||||
|
||||
/// Creates a mirror reflecting the class [key].
|
||||
ClassMirror reflectClass(Type key) {
|
||||
@override
|
||||
ClassMirrorContract reflectClass(Type key) {
|
||||
return _classes.putIfAbsent(
|
||||
key,
|
||||
() => ClassMirrorImpl(
|
||||
() => ClassMirror(
|
||||
type: key,
|
||||
name: key.toString(),
|
||||
owner: _rootLibrary,
|
||||
|
@ -70,14 +66,15 @@ class RuntimeMirrorSystem implements MirrorSystem {
|
|||
}
|
||||
|
||||
/// Creates a mirror reflecting the type [key].
|
||||
TypeMirror reflectType(Type key) {
|
||||
@override
|
||||
TypeMirrorContract reflectType(Type key) {
|
||||
return _getOrCreateTypeMirror(key);
|
||||
}
|
||||
|
||||
TypeMirror _getOrCreateTypeMirror(Type type) {
|
||||
TypeMirrorContract _getOrCreateTypeMirror(Type type) {
|
||||
return _types.putIfAbsent(
|
||||
type,
|
||||
() => TypeMirrorImpl(
|
||||
() => TypeMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: _rootLibrary,
|
||||
|
@ -87,7 +84,7 @@ class RuntimeMirrorSystem implements MirrorSystem {
|
|||
}
|
||||
|
||||
void _initializeRootLibrary() {
|
||||
_rootLibrary = LibraryMirrorImpl.withDeclarations(
|
||||
_rootLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart.core',
|
||||
uri: Uri.parse('dart:core'),
|
||||
);
|
||||
|
@ -96,16 +93,16 @@ class RuntimeMirrorSystem implements MirrorSystem {
|
|||
}
|
||||
|
||||
/// The current mirror system.
|
||||
MirrorSystem currentMirrorSystem() => RuntimeMirrorSystem.instance;
|
||||
MirrorSystemContract currentMirrorSystem() => RuntimeMirrorSystem.instance;
|
||||
|
||||
/// Reflects an instance.
|
||||
InstanceMirror reflect(Object reflectee) =>
|
||||
InstanceMirrorContract reflect(Object reflectee) =>
|
||||
RuntimeMirrorSystem.instance.reflect(reflectee);
|
||||
|
||||
/// Reflects a class.
|
||||
ClassMirror reflectClass(Type key) =>
|
||||
ClassMirrorContract reflectClass(Type key) =>
|
||||
RuntimeMirrorSystem.instance.reflectClass(key);
|
||||
|
||||
/// Reflects a type.
|
||||
TypeMirror reflectType(Type key) =>
|
||||
TypeMirrorContract reflectType(Type key) =>
|
||||
RuntimeMirrorSystem.instance.reflectType(key);
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
/// Basic reflection in Dart, with support for introspection and dynamic invocation.
|
||||
library mirrors;
|
||||
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
|
||||
export 'package:platform_contracts/contracts.dart'
|
||||
show
|
||||
Mirror,
|
||||
DeclarationMirror,
|
||||
ObjectMirror,
|
||||
InstanceMirror,
|
||||
TypeMirror,
|
||||
ClassMirror,
|
||||
LibraryMirror,
|
||||
MethodMirror,
|
||||
VariableMirror,
|
||||
ParameterMirror,
|
||||
TypeVariableMirror,
|
||||
LibraryDependencyMirror,
|
||||
CombinatorMirror;
|
||||
|
||||
export 'mirrors/mirrors.dart';
|
||||
|
||||
/// An [IsolateMirror] reflects an isolate.
|
||||
abstract class IsolateMirror implements Mirror {
|
||||
/// A unique name used to refer to the isolate in debugging messages.
|
||||
String get debugName;
|
||||
|
||||
/// Whether this mirror reflects the currently running isolate.
|
||||
bool get isCurrent;
|
||||
|
||||
/// The root library for the reflected isolate.
|
||||
LibraryMirror get rootLibrary;
|
||||
}
|
||||
|
||||
/// A [MirrorSystem] is the main interface used to reflect on a set of libraries.
|
||||
abstract class MirrorSystem {
|
||||
/// All libraries known to the mirror system.
|
||||
Map<Uri, LibraryMirror> get libraries;
|
||||
|
||||
/// Returns the unique library with the specified name.
|
||||
LibraryMirror findLibrary(Symbol libraryName);
|
||||
|
||||
/// Returns a mirror for the specified class.
|
||||
ClassMirror reflectClass(Type type);
|
||||
|
||||
/// Returns a mirror for the specified type.
|
||||
TypeMirror reflectType(Type type);
|
||||
|
||||
/// A mirror on the isolate associated with this mirror system.
|
||||
IsolateMirror get isolate;
|
||||
|
||||
/// A mirror on the dynamic type.
|
||||
TypeMirror get dynamicType;
|
||||
|
||||
/// A mirror on the void type.
|
||||
TypeMirror get voidType;
|
||||
|
||||
/// A mirror on the Never type.
|
||||
TypeMirror get neverType;
|
||||
}
|
|
@ -1,31 +1,31 @@
|
|||
import 'package:meta/meta.dart';
|
||||
import '../mirrors.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
|
||||
/// Base class for mirrors that have an owner.
|
||||
abstract class MutableOwnerMirror implements DeclarationMirror {
|
||||
DeclarationMirror? _owner;
|
||||
abstract class MutableOwnerMirror implements DeclarationMirrorContract {
|
||||
DeclarationMirrorContract? _owner;
|
||||
|
||||
/// Sets the owner of this mirror.
|
||||
@protected
|
||||
void setOwner(DeclarationMirror? owner) {
|
||||
void setOwner(DeclarationMirrorContract? owner) {
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
@override
|
||||
DeclarationMirror? get owner => _owner;
|
||||
DeclarationMirrorContract? get owner => _owner;
|
||||
}
|
||||
|
||||
/// Base class for mirrors that have a type.
|
||||
abstract class TypedMirror extends MutableOwnerMirror {
|
||||
final Type _type;
|
||||
final String _name;
|
||||
final List<InstanceMirror> _metadata;
|
||||
final List<InstanceMirrorContract> _metadata;
|
||||
|
||||
TypedMirror({
|
||||
required Type type,
|
||||
required String name,
|
||||
DeclarationMirror? owner,
|
||||
List<InstanceMirror> metadata = const [],
|
||||
DeclarationMirrorContract? owner,
|
||||
List<InstanceMirrorContract> metadata = const [],
|
||||
}) : _type = type,
|
||||
_name = name,
|
||||
_metadata = metadata {
|
||||
|
@ -54,5 +54,5 @@ abstract class TypedMirror extends MutableOwnerMirror {
|
|||
bool get isTopLevel => owner == null;
|
||||
|
||||
@override
|
||||
List<InstanceMirror> get metadata => List.unmodifiable(_metadata);
|
||||
List<InstanceMirrorContract> get metadata => List.unmodifiable(_metadata);
|
||||
}
|
||||
|
|
|
@ -1,23 +1,16 @@
|
|||
import '../metadata.dart';
|
||||
import '../mirrors.dart';
|
||||
import '../exceptions.dart';
|
||||
import '../core/reflector.dart';
|
||||
import 'base_mirror.dart';
|
||||
import 'instance_mirror_impl.dart';
|
||||
import 'method_mirror_impl.dart';
|
||||
import 'mirror_system_impl.dart';
|
||||
import 'type_mirror_impl.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [ClassMirror].
|
||||
class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
||||
/// Implementation of [ClassMirrorContract].
|
||||
class ClassMirror extends TypeMirror implements ClassMirrorContract {
|
||||
@override
|
||||
final Map<Symbol, DeclarationMirror> declarations;
|
||||
final Map<Symbol, DeclarationMirrorContract> declarations;
|
||||
|
||||
@override
|
||||
final Map<Symbol, MethodMirror> instanceMembers;
|
||||
final Map<Symbol, MethodMirrorContract> instanceMembers;
|
||||
|
||||
@override
|
||||
final Map<Symbol, MethodMirror> staticMembers;
|
||||
final Map<Symbol, MethodMirrorContract> staticMembers;
|
||||
|
||||
@override
|
||||
final bool isAbstract;
|
||||
|
@ -26,19 +19,19 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
final bool isEnum;
|
||||
|
||||
@override
|
||||
final ClassMirror? superclass;
|
||||
final ClassMirrorContract? superclass;
|
||||
|
||||
@override
|
||||
final List<ClassMirror> superinterfaces;
|
||||
final List<ClassMirrorContract> superinterfaces;
|
||||
|
||||
ClassMirrorImpl({
|
||||
ClassMirror({
|
||||
required Type type,
|
||||
required String name,
|
||||
required DeclarationMirror? owner,
|
||||
required DeclarationMirrorContract? owner,
|
||||
required this.declarations,
|
||||
required this.instanceMembers,
|
||||
required this.staticMembers,
|
||||
required List<InstanceMirror> metadata,
|
||||
required List<InstanceMirrorContract> metadata,
|
||||
this.isAbstract = false,
|
||||
this.isEnum = false,
|
||||
this.superclass,
|
||||
|
@ -57,19 +50,19 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
}
|
||||
|
||||
@override
|
||||
bool isSubclassOf(ClassMirror other) {
|
||||
bool isSubclassOf(ClassMirrorContract other) {
|
||||
var current = this;
|
||||
while (current.superclass != null) {
|
||||
if (current.superclass == other) {
|
||||
return true;
|
||||
}
|
||||
current = current.superclass as ClassMirrorImpl;
|
||||
current = current.superclass as ClassMirror;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
InstanceMirror newInstance(
|
||||
InstanceMirrorContract newInstance(
|
||||
Symbol constructorName,
|
||||
List<dynamic> positionalArguments, [
|
||||
Map<Symbol, dynamic>? namedArguments,
|
||||
|
@ -126,7 +119,7 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
'Failed to create instance: creator returned null');
|
||||
}
|
||||
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: instance,
|
||||
type: this,
|
||||
);
|
||||
|
@ -136,7 +129,8 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
}
|
||||
|
||||
@override
|
||||
InstanceMirror invoke(Symbol memberName, List<dynamic> positionalArguments,
|
||||
InstanceMirrorContract invoke(
|
||||
Symbol memberName, List<dynamic> positionalArguments,
|
||||
[Map<Symbol, dynamic>? namedArguments]) {
|
||||
try {
|
||||
// Get method metadata
|
||||
|
@ -174,7 +168,7 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
namedArguments,
|
||||
);
|
||||
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: result,
|
||||
type: this,
|
||||
);
|
||||
|
@ -184,7 +178,7 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
}
|
||||
|
||||
@override
|
||||
InstanceMirror getField(Symbol fieldName) {
|
||||
InstanceMirrorContract getField(Symbol fieldName) {
|
||||
final declaration = declarations[fieldName];
|
||||
if (declaration == null) {
|
||||
throw NoSuchMethodError.withInvocation(
|
||||
|
@ -195,7 +189,7 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
|
||||
try {
|
||||
final value = (type as dynamic)[_symbolToString(fieldName)];
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: value,
|
||||
type: this,
|
||||
);
|
||||
|
@ -205,7 +199,7 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
}
|
||||
|
||||
@override
|
||||
InstanceMirror setField(Symbol fieldName, dynamic value) {
|
||||
InstanceMirrorContract setField(Symbol fieldName, dynamic value) {
|
||||
final declaration = declarations[fieldName];
|
||||
if (declaration == null) {
|
||||
throw NoSuchMethodError.withInvocation(
|
||||
|
@ -216,7 +210,7 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
|
||||
try {
|
||||
(type as dynamic)[_symbolToString(fieldName)] = value;
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: value,
|
||||
type: this,
|
||||
);
|
||||
|
@ -228,7 +222,7 @@ class ClassMirrorImpl extends TypeMirrorImpl implements ClassMirror {
|
|||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ClassMirrorImpl &&
|
||||
other is ClassMirror &&
|
||||
runtimeType == other.runtimeType &&
|
||||
type == other.type;
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
import '../mirrors.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
|
||||
/// Implementation of [CombinatorMirror] that provides reflection on show/hide combinators.
|
||||
class CombinatorMirrorImpl implements CombinatorMirror {
|
||||
/// Implementation of [CombinatorMirrorContract] that provides reflection on show/hide combinators.
|
||||
class CombinatorMirror implements CombinatorMirrorContract {
|
||||
final List<Symbol> _identifiers;
|
||||
final bool _isShow;
|
||||
|
||||
CombinatorMirrorImpl({
|
||||
CombinatorMirror({
|
||||
required List<Symbol> identifiers,
|
||||
required bool isShow,
|
||||
}) : _identifiers = identifiers,
|
||||
|
@ -23,7 +23,7 @@ class CombinatorMirrorImpl implements CombinatorMirror {
|
|||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! CombinatorMirrorImpl) return false;
|
||||
if (other is! CombinatorMirror) return false;
|
||||
|
||||
return _identifiers == other._identifiers && _isShow == other._isShow;
|
||||
}
|
|
@ -1,21 +1,20 @@
|
|||
import 'dart:core';
|
||||
import '../mirrors.dart';
|
||||
import '../exceptions.dart';
|
||||
import '../core/reflector.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [InstanceMirror] that provides reflection on instances.
|
||||
class InstanceMirrorImpl implements InstanceMirror {
|
||||
/// Implementation of [InstanceMirrorContract] that provides reflection on instances.
|
||||
class InstanceMirror implements InstanceMirrorContract {
|
||||
final Object _reflectee;
|
||||
final ClassMirror _type;
|
||||
final ClassMirrorContract _type;
|
||||
|
||||
InstanceMirrorImpl({
|
||||
InstanceMirror({
|
||||
required Object reflectee,
|
||||
required ClassMirror type,
|
||||
required ClassMirrorContract type,
|
||||
}) : _reflectee = reflectee,
|
||||
_type = type;
|
||||
|
||||
@override
|
||||
ClassMirror get type => _type;
|
||||
ClassMirrorContract get type => _type;
|
||||
|
||||
@override
|
||||
bool get hasReflectee => true;
|
||||
|
@ -24,7 +23,7 @@ class InstanceMirrorImpl implements InstanceMirror {
|
|||
dynamic get reflectee => _reflectee;
|
||||
|
||||
@override
|
||||
InstanceMirror invoke(Symbol memberName, List positionalArguments,
|
||||
InstanceMirrorContract invoke(Symbol memberName, List positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments = const {}]) {
|
||||
// Get method metadata
|
||||
final methods = Reflector.getMethodMetadata(_reflectee.runtimeType);
|
||||
|
@ -79,7 +78,7 @@ class InstanceMirrorImpl implements InstanceMirror {
|
|||
default:
|
||||
throw ReflectionException('Method $methodName not implemented');
|
||||
}
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: result ?? '',
|
||||
type: _type,
|
||||
);
|
||||
|
@ -89,7 +88,7 @@ class InstanceMirrorImpl implements InstanceMirror {
|
|||
}
|
||||
|
||||
@override
|
||||
InstanceMirror getField(Symbol fieldName) {
|
||||
InstanceMirrorContract getField(Symbol fieldName) {
|
||||
// Get property metadata
|
||||
final properties = Reflector.getPropertyMetadata(_reflectee.runtimeType);
|
||||
if (properties == null) {
|
||||
|
@ -135,7 +134,7 @@ class InstanceMirrorImpl implements InstanceMirror {
|
|||
default:
|
||||
throw ReflectionException('Property $propertyName not implemented');
|
||||
}
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: value ?? '',
|
||||
type: _type,
|
||||
);
|
||||
|
@ -145,7 +144,7 @@ class InstanceMirrorImpl implements InstanceMirror {
|
|||
}
|
||||
|
||||
@override
|
||||
InstanceMirror setField(Symbol fieldName, dynamic value) {
|
||||
InstanceMirrorContract setField(Symbol fieldName, dynamic value) {
|
||||
// Get property metadata
|
||||
final properties = Reflector.getPropertyMetadata(_reflectee.runtimeType);
|
||||
if (properties == null) {
|
||||
|
@ -194,7 +193,7 @@ class InstanceMirrorImpl implements InstanceMirror {
|
|||
default:
|
||||
throw ReflectionException('Property $propertyName not implemented');
|
||||
}
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: value,
|
||||
type: _type,
|
||||
);
|
||||
|
@ -206,7 +205,7 @@ class InstanceMirrorImpl implements InstanceMirror {
|
|||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! InstanceMirrorImpl) return false;
|
||||
if (other is! InstanceMirror) return false;
|
||||
|
||||
return identical(_reflectee, other._reflectee) && _type == other._type;
|
||||
}
|
||||
|
@ -224,22 +223,22 @@ class InstanceMirrorImpl implements InstanceMirror {
|
|||
}
|
||||
}
|
||||
|
||||
/// Implementation of [InstanceMirror] for closures.
|
||||
class ClosureMirrorImpl extends InstanceMirrorImpl {
|
||||
final MethodMirror _function;
|
||||
/// Implementation of [InstanceMirrorContract] for closures.
|
||||
class ClosureMirrorImpl extends InstanceMirror {
|
||||
final MethodMirrorContract _function;
|
||||
|
||||
ClosureMirrorImpl({
|
||||
required Object reflectee,
|
||||
required ClassMirror type,
|
||||
required MethodMirror function,
|
||||
required ClassMirrorContract type,
|
||||
required MethodMirrorContract function,
|
||||
}) : _function = function,
|
||||
super(reflectee: reflectee, type: type);
|
||||
|
||||
/// The function this closure represents.
|
||||
MethodMirror get function => _function;
|
||||
MethodMirrorContract get function => _function;
|
||||
|
||||
/// Applies this closure with the given arguments.
|
||||
InstanceMirror apply(List positionalArguments,
|
||||
InstanceMirrorContract apply(List positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments = const {}]) {
|
||||
final closure = reflectee as Function;
|
||||
final result = Function.apply(
|
||||
|
@ -247,7 +246,7 @@ class ClosureMirrorImpl extends InstanceMirrorImpl {
|
|||
positionalArguments,
|
||||
namedArguments,
|
||||
);
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: result ?? '',
|
||||
type: type,
|
||||
);
|
||||
|
@ -269,11 +268,11 @@ class ClosureMirrorImpl extends InstanceMirrorImpl {
|
|||
String toString() => 'ClosureMirror on ${_reflectee.runtimeType}';
|
||||
}
|
||||
|
||||
/// Implementation of [InstanceMirror] for simple values.
|
||||
class ValueMirrorImpl extends InstanceMirrorImpl {
|
||||
/// Implementation of [InstanceMirrorContract] for simple values.
|
||||
class ValueMirrorImpl extends InstanceMirror {
|
||||
ValueMirrorImpl({
|
||||
required Object reflectee,
|
||||
required ClassMirror type,
|
||||
required ClassMirrorContract type,
|
||||
}) : super(reflectee: reflectee, type: type);
|
||||
|
||||
@override
|
|
@ -1,19 +1,18 @@
|
|||
import 'dart:core';
|
||||
import 'dart:isolate' as isolate;
|
||||
import '../mirrors.dart';
|
||||
import 'library_mirror_impl.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
|
||||
/// Implementation of [IsolateMirror] that provides reflection on isolates.
|
||||
class IsolateMirrorImpl implements IsolateMirror {
|
||||
/// Implementation of [IsolateMirrorContract] that provides reflection on isolates.
|
||||
class IsolateMirror implements IsolateMirrorContract {
|
||||
final String _debugName;
|
||||
final bool _isCurrent;
|
||||
final LibraryMirror _rootLibrary;
|
||||
final LibraryMirrorContract _rootLibrary;
|
||||
final isolate.Isolate? _underlyingIsolate;
|
||||
|
||||
IsolateMirrorImpl({
|
||||
IsolateMirror({
|
||||
required String debugName,
|
||||
required bool isCurrent,
|
||||
required LibraryMirror rootLibrary,
|
||||
required LibraryMirrorContract rootLibrary,
|
||||
isolate.Isolate? underlyingIsolate,
|
||||
}) : _debugName = debugName,
|
||||
_isCurrent = isCurrent,
|
||||
|
@ -21,8 +20,8 @@ class IsolateMirrorImpl implements IsolateMirror {
|
|||
_underlyingIsolate = underlyingIsolate;
|
||||
|
||||
/// Creates a mirror for the current isolate.
|
||||
factory IsolateMirrorImpl.current(LibraryMirror rootLibrary) {
|
||||
return IsolateMirrorImpl(
|
||||
factory IsolateMirror.current(LibraryMirrorContract rootLibrary) {
|
||||
return IsolateMirror(
|
||||
debugName: 'main',
|
||||
isCurrent: true,
|
||||
rootLibrary: rootLibrary,
|
||||
|
@ -31,12 +30,12 @@ class IsolateMirrorImpl implements IsolateMirror {
|
|||
}
|
||||
|
||||
/// Creates a mirror for another isolate.
|
||||
factory IsolateMirrorImpl.other(
|
||||
factory IsolateMirror.other(
|
||||
isolate.Isolate underlyingIsolate,
|
||||
String debugName,
|
||||
LibraryMirror rootLibrary,
|
||||
LibraryMirrorContract rootLibrary,
|
||||
) {
|
||||
return IsolateMirrorImpl(
|
||||
return IsolateMirror(
|
||||
debugName: debugName,
|
||||
isCurrent: false,
|
||||
rootLibrary: rootLibrary,
|
||||
|
@ -51,7 +50,7 @@ class IsolateMirrorImpl implements IsolateMirror {
|
|||
bool get isCurrent => _isCurrent;
|
||||
|
||||
@override
|
||||
LibraryMirror get rootLibrary => _rootLibrary;
|
||||
LibraryMirrorContract get rootLibrary => _rootLibrary;
|
||||
|
||||
/// The underlying isolate, if this mirror reflects a non-current isolate.
|
||||
isolate.Isolate? get underlyingIsolate => _underlyingIsolate;
|
||||
|
@ -59,7 +58,7 @@ class IsolateMirrorImpl implements IsolateMirror {
|
|||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! IsolateMirrorImpl) return false;
|
||||
if (other is! IsolateMirror) return false;
|
||||
|
||||
// Only compare debug name and isCurrent flag
|
||||
// Two mirrors pointing to the same isolate should be equal
|
|
@ -1,21 +1,21 @@
|
|||
import '../mirrors.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
|
||||
/// Implementation of [LibraryDependencyMirror] that provides reflection on library dependencies.
|
||||
class LibraryDependencyMirrorImpl implements LibraryDependencyMirror {
|
||||
/// Implementation of [LibraryDependencyMirrorContract] that provides reflection on library dependencies.
|
||||
class LibraryDependencyMirror implements LibraryDependencyMirrorContract {
|
||||
final bool _isImport;
|
||||
final bool _isDeferred;
|
||||
final LibraryMirror _sourceLibrary;
|
||||
final LibraryMirror? _targetLibrary;
|
||||
final LibraryMirrorContract _sourceLibrary;
|
||||
final LibraryMirrorContract? _targetLibrary;
|
||||
final Symbol? _prefix;
|
||||
final List<CombinatorMirror> _combinators;
|
||||
final List<CombinatorMirrorContract> _combinators;
|
||||
|
||||
LibraryDependencyMirrorImpl({
|
||||
LibraryDependencyMirror({
|
||||
required bool isImport,
|
||||
required bool isDeferred,
|
||||
required LibraryMirror sourceLibrary,
|
||||
LibraryMirror? targetLibrary,
|
||||
required LibraryMirrorContract sourceLibrary,
|
||||
LibraryMirrorContract? targetLibrary,
|
||||
Symbol? prefix,
|
||||
List<CombinatorMirror> combinators = const [],
|
||||
List<CombinatorMirrorContract> combinators = const [],
|
||||
}) : _isImport = isImport,
|
||||
_isDeferred = isDeferred,
|
||||
_sourceLibrary = sourceLibrary,
|
||||
|
@ -33,21 +33,22 @@ class LibraryDependencyMirrorImpl implements LibraryDependencyMirror {
|
|||
bool get isDeferred => _isDeferred;
|
||||
|
||||
@override
|
||||
LibraryMirror get sourceLibrary => _sourceLibrary;
|
||||
LibraryMirrorContract get sourceLibrary => _sourceLibrary;
|
||||
|
||||
@override
|
||||
LibraryMirror? get targetLibrary => _targetLibrary;
|
||||
LibraryMirrorContract? get targetLibrary => _targetLibrary;
|
||||
|
||||
@override
|
||||
Symbol? get prefix => _prefix;
|
||||
|
||||
@override
|
||||
List<CombinatorMirror> get combinators => List.unmodifiable(_combinators);
|
||||
List<CombinatorMirrorContract> get combinators =>
|
||||
List.unmodifiable(_combinators);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! LibraryDependencyMirrorImpl) return false;
|
||||
if (other is! LibraryDependencyMirror) return false;
|
||||
|
||||
return _isImport == other._isImport &&
|
||||
_isDeferred == other._isDeferred &&
|
|
@ -1,31 +1,21 @@
|
|||
import 'dart:core';
|
||||
import '../mirrors.dart';
|
||||
import '../core/library_scanner.dart';
|
||||
import 'base_mirror.dart';
|
||||
import 'library_dependency_mirror_impl.dart';
|
||||
import 'method_mirror_impl.dart';
|
||||
import 'variable_mirror_impl.dart';
|
||||
import 'type_mirror_impl.dart';
|
||||
import 'parameter_mirror_impl.dart';
|
||||
import 'instance_mirror_impl.dart';
|
||||
import 'class_mirror_impl.dart';
|
||||
import '../core/reflector.dart';
|
||||
import '../core/runtime_reflector.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [LibraryMirror] that provides reflection on libraries.
|
||||
class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
||||
/// Implementation of [LibraryMirrorContract] that provides reflection on libraries.
|
||||
class LibraryMirror extends TypedMirror implements LibraryMirrorContract {
|
||||
final Uri _uri;
|
||||
final Map<Symbol, DeclarationMirror> _declarations;
|
||||
final List<LibraryDependencyMirror> _libraryDependencies;
|
||||
final Map<Symbol, DeclarationMirrorContract> _declarations;
|
||||
final List<LibraryDependencyMirrorContract> _libraryDependencies;
|
||||
final Map<Symbol, dynamic> _topLevelValues;
|
||||
|
||||
LibraryMirrorImpl({
|
||||
LibraryMirror({
|
||||
required String name,
|
||||
required Uri uri,
|
||||
DeclarationMirror? owner,
|
||||
Map<Symbol, DeclarationMirror>? declarations,
|
||||
List<LibraryDependencyMirror> libraryDependencies = const [],
|
||||
List<InstanceMirror> metadata = const [],
|
||||
DeclarationMirrorContract? owner,
|
||||
Map<Symbol, DeclarationMirrorContract>? declarations,
|
||||
List<LibraryDependencyMirrorContract> libraryDependencies = const [],
|
||||
List<InstanceMirrorContract> metadata = const [],
|
||||
Map<Symbol, dynamic>? topLevelValues,
|
||||
}) : _uri = uri,
|
||||
_declarations = declarations ?? {},
|
||||
|
@ -39,20 +29,20 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
);
|
||||
|
||||
/// Factory constructor that creates a library mirror with declarations from scanning
|
||||
factory LibraryMirrorImpl.withDeclarations({
|
||||
factory LibraryMirror.withDeclarations({
|
||||
required String name,
|
||||
required Uri uri,
|
||||
DeclarationMirror? owner,
|
||||
List<LibraryDependencyMirror> libraryDependencies = const [],
|
||||
List<InstanceMirror> metadata = const [],
|
||||
DeclarationMirrorContract? owner,
|
||||
List<LibraryDependencyMirrorContract> libraryDependencies = const [],
|
||||
List<InstanceMirrorContract> metadata = const [],
|
||||
}) {
|
||||
// Scan library to get declarations
|
||||
final libraryInfo = LibraryScanner.scanLibrary(uri);
|
||||
final declarations = <Symbol, DeclarationMirror>{};
|
||||
final declarations = <Symbol, DeclarationMirrorContract>{};
|
||||
final topLevelValues = <Symbol, dynamic>{};
|
||||
|
||||
// Create temporary library for owner references
|
||||
final tempLibrary = LibraryMirrorImpl(
|
||||
final tempLibrary = LibraryMirror(
|
||||
name: name,
|
||||
uri: uri,
|
||||
owner: owner,
|
||||
|
@ -63,19 +53,19 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
// Add top-level function declarations
|
||||
for (final function in libraryInfo.topLevelFunctions) {
|
||||
if (!function.isPrivate || uri == tempLibrary.uri) {
|
||||
declarations[Symbol(function.name)] = MethodMirrorImpl(
|
||||
declarations[Symbol(function.name)] = MethodMirror(
|
||||
name: function.name,
|
||||
owner: tempLibrary,
|
||||
returnType: TypeMirrorImpl(
|
||||
returnType: TypeMirror(
|
||||
type: function.returnType,
|
||||
name: function.returnType.toString(),
|
||||
owner: tempLibrary,
|
||||
metadata: const [],
|
||||
),
|
||||
parameters: function.parameters
|
||||
.map((param) => ParameterMirrorImpl(
|
||||
.map((param) => ParameterMirror(
|
||||
name: param.name,
|
||||
type: TypeMirrorImpl(
|
||||
type: TypeMirror(
|
||||
type: param.type,
|
||||
name: param.type.toString(),
|
||||
owner: tempLibrary,
|
||||
|
@ -96,9 +86,9 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
// Add top-level variable declarations
|
||||
for (final variable in libraryInfo.topLevelVariables) {
|
||||
if (!variable.isPrivate || uri == tempLibrary.uri) {
|
||||
declarations[Symbol(variable.name)] = VariableMirrorImpl(
|
||||
declarations[Symbol(variable.name)] = VariableMirror(
|
||||
name: variable.name,
|
||||
type: TypeMirrorImpl(
|
||||
type: TypeMirror(
|
||||
type: variable.type,
|
||||
name: variable.type.toString(),
|
||||
owner: tempLibrary,
|
||||
|
@ -124,15 +114,15 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
}
|
||||
|
||||
// Create library dependencies
|
||||
final dependencies = <LibraryDependencyMirror>[];
|
||||
final dependencies = <LibraryDependencyMirrorContract>[];
|
||||
|
||||
// Add imports
|
||||
for (final dep in libraryInfo.dependencies) {
|
||||
dependencies.add(LibraryDependencyMirrorImpl(
|
||||
dependencies.add(LibraryDependencyMirror(
|
||||
isImport: true,
|
||||
isDeferred: dep.isDeferred,
|
||||
sourceLibrary: tempLibrary,
|
||||
targetLibrary: LibraryMirrorImpl.withDeclarations(
|
||||
targetLibrary: LibraryMirror.withDeclarations(
|
||||
name: dep.uri.toString(),
|
||||
uri: dep.uri,
|
||||
owner: tempLibrary,
|
||||
|
@ -144,11 +134,11 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
|
||||
// Add exports
|
||||
for (final dep in libraryInfo.exports) {
|
||||
dependencies.add(LibraryDependencyMirrorImpl(
|
||||
dependencies.add(LibraryDependencyMirror(
|
||||
isImport: false,
|
||||
isDeferred: false,
|
||||
sourceLibrary: tempLibrary,
|
||||
targetLibrary: LibraryMirrorImpl.withDeclarations(
|
||||
targetLibrary: LibraryMirror.withDeclarations(
|
||||
name: dep.uri.toString(),
|
||||
uri: dep.uri,
|
||||
owner: tempLibrary,
|
||||
|
@ -158,7 +148,7 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
));
|
||||
}
|
||||
|
||||
return LibraryMirrorImpl(
|
||||
return LibraryMirror(
|
||||
name: name,
|
||||
uri: uri,
|
||||
owner: owner,
|
||||
|
@ -194,15 +184,15 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
Uri get uri => _uri;
|
||||
|
||||
@override
|
||||
Map<Symbol, DeclarationMirror> get declarations =>
|
||||
Map<Symbol, DeclarationMirrorContract> get declarations =>
|
||||
Map.unmodifiable(_declarations);
|
||||
|
||||
@override
|
||||
List<LibraryDependencyMirror> get libraryDependencies =>
|
||||
List<LibraryDependencyMirrorContract> get libraryDependencies =>
|
||||
List.unmodifiable(_libraryDependencies);
|
||||
|
||||
@override
|
||||
InstanceMirror invoke(Symbol memberName, List positionalArguments,
|
||||
InstanceMirrorContract invoke(Symbol memberName, List positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments = const {}]) {
|
||||
final member = declarations[memberName];
|
||||
if (member == null) {
|
||||
|
@ -212,7 +202,7 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
);
|
||||
}
|
||||
|
||||
if (member is! MethodMirror) {
|
||||
if (member is! MethodMirrorContract) {
|
||||
throw NoSuchMethodError.withInvocation(
|
||||
this,
|
||||
Invocation.method(memberName, positionalArguments, namedArguments),
|
||||
|
@ -223,7 +213,7 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
if (memberName == const Symbol('add')) {
|
||||
final a = positionalArguments[0] as int;
|
||||
final b = positionalArguments[1] as int;
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: a + b,
|
||||
type: _createPrimitiveClassMirror(int, 'int'),
|
||||
);
|
||||
|
@ -234,7 +224,7 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
}
|
||||
|
||||
@override
|
||||
InstanceMirror getField(Symbol fieldName) {
|
||||
InstanceMirrorContract getField(Symbol fieldName) {
|
||||
final member = declarations[fieldName];
|
||||
if (member == null) {
|
||||
throw NoSuchMethodError.withInvocation(
|
||||
|
@ -243,7 +233,7 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
);
|
||||
}
|
||||
|
||||
if (member is! VariableMirror) {
|
||||
if (member is! VariableMirrorContract) {
|
||||
throw NoSuchMethodError.withInvocation(
|
||||
this,
|
||||
Invocation.getter(fieldName),
|
||||
|
@ -257,14 +247,14 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
'Top-level variable $fieldName has not been initialized');
|
||||
}
|
||||
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: value,
|
||||
type: _createPrimitiveClassMirror(member.type.reflectedType, member.name),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
InstanceMirror setField(Symbol fieldName, dynamic value) {
|
||||
InstanceMirrorContract setField(Symbol fieldName, dynamic value) {
|
||||
final member = declarations[fieldName];
|
||||
if (member == null) {
|
||||
throw NoSuchMethodError.withInvocation(
|
||||
|
@ -273,7 +263,7 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
);
|
||||
}
|
||||
|
||||
if (member is! VariableMirror) {
|
||||
if (member is! VariableMirrorContract) {
|
||||
throw NoSuchMethodError.withInvocation(
|
||||
this,
|
||||
Invocation.setter(fieldName, [value]),
|
||||
|
@ -296,15 +286,16 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
|
||||
// Update value in top-level values map
|
||||
_topLevelValues[fieldName] = value;
|
||||
return InstanceMirrorImpl(
|
||||
return InstanceMirror(
|
||||
reflectee: value,
|
||||
type: _createPrimitiveClassMirror(member.type.reflectedType, member.name),
|
||||
);
|
||||
}
|
||||
|
||||
/// Creates a ClassMirror for a primitive type.
|
||||
static ClassMirror _createPrimitiveClassMirror(Type type, String name) {
|
||||
return ClassMirrorImpl(
|
||||
static ClassMirrorContract _createPrimitiveClassMirror(
|
||||
Type type, String name) {
|
||||
return ClassMirror(
|
||||
type: type,
|
||||
name: name,
|
||||
owner: null,
|
||||
|
@ -318,7 +309,7 @@ class LibraryMirrorImpl extends TypedMirror implements LibraryMirror {
|
|||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! LibraryMirrorImpl) return false;
|
||||
if (other is! LibraryMirror) return false;
|
||||
|
||||
return _uri == other._uri &&
|
||||
name == other.name &&
|
|
@ -1,10 +1,10 @@
|
|||
import '../mirrors.dart';
|
||||
import 'base_mirror.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [MethodMirror] that provides reflection on methods.
|
||||
class MethodMirrorImpl extends TypedMirror implements MethodMirror {
|
||||
final TypeMirror _returnType;
|
||||
final List<ParameterMirror> _parameters;
|
||||
/// Implementation of [MethodMirrorContract] that provides reflection on methods.
|
||||
class MethodMirror extends TypedMirror implements MethodMirrorContract {
|
||||
final TypeMirrorContract _returnType;
|
||||
final List<ParameterMirrorContract> _parameters;
|
||||
final bool _isStatic;
|
||||
final bool _isAbstract;
|
||||
final bool _isSynthetic;
|
||||
|
@ -16,11 +16,11 @@ class MethodMirrorImpl extends TypedMirror implements MethodMirror {
|
|||
final bool _isFactoryConstructor;
|
||||
final String? _source;
|
||||
|
||||
MethodMirrorImpl({
|
||||
MethodMirror({
|
||||
required String name,
|
||||
required DeclarationMirror? owner,
|
||||
required TypeMirror returnType,
|
||||
required List<ParameterMirror> parameters,
|
||||
required DeclarationMirrorContract? owner,
|
||||
required TypeMirrorContract returnType,
|
||||
required List<ParameterMirrorContract> parameters,
|
||||
bool isStatic = false,
|
||||
bool isAbstract = false,
|
||||
bool isSynthetic = false,
|
||||
|
@ -31,7 +31,7 @@ class MethodMirrorImpl extends TypedMirror implements MethodMirror {
|
|||
bool isRedirectingConstructor = false,
|
||||
bool isFactoryConstructor = false,
|
||||
String? source,
|
||||
List<InstanceMirror> metadata = const [],
|
||||
List<InstanceMirrorContract> metadata = const [],
|
||||
}) : _returnType = returnType,
|
||||
_parameters = parameters,
|
||||
_isStatic = isStatic,
|
||||
|
@ -52,10 +52,11 @@ class MethodMirrorImpl extends TypedMirror implements MethodMirror {
|
|||
);
|
||||
|
||||
@override
|
||||
TypeMirror get returnType => _returnType;
|
||||
TypeMirrorContract get returnType => _returnType;
|
||||
|
||||
@override
|
||||
List<ParameterMirror> get parameters => List.unmodifiable(_parameters);
|
||||
List<ParameterMirrorContract> get parameters =>
|
||||
List.unmodifiable(_parameters);
|
||||
|
||||
@override
|
||||
bool get isStatic => _isStatic;
|
||||
|
@ -103,7 +104,7 @@ class MethodMirrorImpl extends TypedMirror implements MethodMirror {
|
|||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! MethodMirrorImpl) return false;
|
||||
if (other is! MethodMirror) return false;
|
||||
|
||||
return name == other.name &&
|
||||
owner == other.owner &&
|
323
incubation/reflection/lib/src/mirrors/mirror_system.dart
Normal file
323
incubation/reflection/lib/src/mirrors/mirror_system.dart
Normal file
|
@ -0,0 +1,323 @@
|
|||
import 'dart:core';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [MirrorSystemContract] that provides reflection on a set of libraries.
|
||||
class MirrorSystem implements MirrorSystemContract {
|
||||
static MirrorSystem? _instance;
|
||||
|
||||
static MirrorSystem get instance {
|
||||
return _instance ??= MirrorSystem._();
|
||||
}
|
||||
|
||||
// Add this method back
|
||||
static MirrorSystem current() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
final Map<Uri, LibraryMirrorContract> _libraries = {};
|
||||
final Map<Type, ClassMirrorContract> _classes = {};
|
||||
final Map<Type, TypeMirrorContract> _types = {};
|
||||
late final LibraryMirrorContract _rootLibrary;
|
||||
late final IsolateMirrorContract _isolate;
|
||||
late final TypeMirrorContract _dynamicType;
|
||||
late final TypeMirrorContract _voidType;
|
||||
late final TypeMirrorContract _neverType;
|
||||
|
||||
// Private constructor
|
||||
MirrorSystem._() {
|
||||
_initializeSystem();
|
||||
}
|
||||
|
||||
void _initializeSystem() {
|
||||
_initializeRootLibrary();
|
||||
_initializeCoreDependencies();
|
||||
_initializeSpecialTypes();
|
||||
_initializeIsolate();
|
||||
}
|
||||
|
||||
void _initializeRootLibrary() {
|
||||
_rootLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart.core',
|
||||
uri: Uri.parse('dart:core'),
|
||||
);
|
||||
_libraries[_rootLibrary.uri] = _rootLibrary;
|
||||
}
|
||||
|
||||
void _initializeCoreDependencies() {
|
||||
// Create core library mirror
|
||||
final coreLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart:core',
|
||||
uri: _createDartUri('core'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create async library mirror
|
||||
final asyncLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart:async',
|
||||
uri: _createDartUri('async'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create test library mirror
|
||||
final testLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'package:test/test.dart',
|
||||
uri: Uri.parse('package:test/test.dart'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Add dependencies to core library
|
||||
final coreDependencies = [
|
||||
LibraryDependencyMirror(
|
||||
isImport: true,
|
||||
isDeferred: false,
|
||||
sourceLibrary: coreLibrary,
|
||||
targetLibrary: asyncLibrary,
|
||||
prefix: null,
|
||||
combinators: const [],
|
||||
),
|
||||
LibraryDependencyMirror(
|
||||
isImport: false,
|
||||
isDeferred: false,
|
||||
sourceLibrary: coreLibrary,
|
||||
targetLibrary: asyncLibrary,
|
||||
prefix: null,
|
||||
combinators: const [],
|
||||
),
|
||||
];
|
||||
|
||||
// Update core library with dependencies
|
||||
_libraries[coreLibrary.uri] = LibraryMirror(
|
||||
name: 'dart:core',
|
||||
uri: _createDartUri('core'),
|
||||
owner: null,
|
||||
declarations: const {},
|
||||
libraryDependencies: coreDependencies,
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
// Add libraries to the map
|
||||
_libraries[asyncLibrary.uri] = asyncLibrary;
|
||||
_libraries[testLibrary.uri] = testLibrary;
|
||||
}
|
||||
|
||||
void _initializeSpecialTypes() {
|
||||
_dynamicType = TypeMirror.dynamicType();
|
||||
_voidType = TypeMirror.voidType();
|
||||
_neverType = TypeMirror(
|
||||
type: Never,
|
||||
name: 'Never',
|
||||
owner: null,
|
||||
metadata: [],
|
||||
);
|
||||
}
|
||||
|
||||
void _initializeIsolate() {
|
||||
_isolate = IsolateMirror.current(_rootLibrary);
|
||||
}
|
||||
|
||||
/// Creates a URI for a dart: library.
|
||||
static Uri _createDartUri(String library) {
|
||||
return Uri(scheme: 'dart', path: library);
|
||||
}
|
||||
|
||||
/// Parses a library name into a URI.
|
||||
static Uri _parseLibraryName(String name) {
|
||||
if (name.startsWith('"') && name.endsWith('"')) {
|
||||
name = name.substring(1, name.length - 1);
|
||||
}
|
||||
|
||||
if (name.startsWith('dart:')) {
|
||||
final library = name.substring(5);
|
||||
return _createDartUri(library);
|
||||
}
|
||||
|
||||
return Uri.parse(name);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<Uri, LibraryMirrorContract> get libraries => Map.unmodifiable(_libraries);
|
||||
|
||||
@override
|
||||
LibraryMirrorContract findLibrary(Symbol libraryName) {
|
||||
final name = libraryName.toString();
|
||||
// Remove leading 'Symbol(' and trailing ')'
|
||||
final normalizedName = name.substring(7, name.length - 1);
|
||||
|
||||
final uri = _parseLibraryName(normalizedName);
|
||||
final library = _libraries[uri];
|
||||
if (library == null) {
|
||||
throw ArgumentError('Library not found: $normalizedName');
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
||||
@override
|
||||
ClassMirrorContract reflectClass(Type type) {
|
||||
return _classes.putIfAbsent(
|
||||
type,
|
||||
() => _createClassMirror(type),
|
||||
);
|
||||
}
|
||||
|
||||
ClassMirrorContract _createClassMirror(Type type) {
|
||||
// Check if type is reflectable
|
||||
if (!Reflector.isReflectable(type)) {
|
||||
throw ArgumentError('Type is not reflectable: $type');
|
||||
}
|
||||
|
||||
// Create temporary class mirror to serve as owner
|
||||
final tempMirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
declarations: const {},
|
||||
instanceMembers: const {},
|
||||
staticMembers: const {},
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
// Get metadata from registry
|
||||
final properties = Reflector.getPropertyMetadata(type) ?? {};
|
||||
final methods = Reflector.getMethodMetadata(type) ?? {};
|
||||
|
||||
// Create declarations map
|
||||
final declarations = <Symbol, DeclarationMirrorContract>{};
|
||||
final instanceMembers = <Symbol, MethodMirrorContract>{};
|
||||
final staticMembers = <Symbol, MethodMirrorContract>{};
|
||||
|
||||
// Add properties and methods to declarations
|
||||
properties.forEach((name, prop) {
|
||||
declarations[Symbol(name)] = VariableMirror(
|
||||
name: name,
|
||||
type: TypeMirror(
|
||||
type: prop.type,
|
||||
name: prop.type.toString(),
|
||||
owner: tempMirror,
|
||||
metadata: [],
|
||||
),
|
||||
owner: tempMirror,
|
||||
isStatic: false,
|
||||
isFinal: !prop.isWritable,
|
||||
isConst: false,
|
||||
metadata: [],
|
||||
);
|
||||
});
|
||||
|
||||
methods.forEach((name, method) {
|
||||
final methodMirror = MethodMirror(
|
||||
name: name,
|
||||
owner: tempMirror,
|
||||
returnType: method.returnsVoid
|
||||
? TypeMirror.voidType(tempMirror)
|
||||
: TypeMirror.dynamicType(tempMirror),
|
||||
parameters: method.parameters
|
||||
.map((param) => ParameterMirror(
|
||||
name: param.name,
|
||||
type: TypeMirror(
|
||||
type: param.type,
|
||||
name: param.type.toString(),
|
||||
owner: tempMirror,
|
||||
metadata: [],
|
||||
),
|
||||
owner: tempMirror,
|
||||
isOptional: !param.isRequired,
|
||||
isNamed: param.isNamed,
|
||||
metadata: [],
|
||||
))
|
||||
.toList(),
|
||||
isStatic: method.isStatic,
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
declarations[Symbol(name)] = methodMirror;
|
||||
if (method.isStatic) {
|
||||
staticMembers[Symbol(name)] = methodMirror;
|
||||
} else {
|
||||
instanceMembers[Symbol(name)] = methodMirror;
|
||||
}
|
||||
});
|
||||
|
||||
// Create class mirror
|
||||
final mirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
declarations: declarations,
|
||||
instanceMembers: instanceMembers,
|
||||
staticMembers: staticMembers,
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
// Update owners to point to the real class mirror
|
||||
declarations.forEach((_, decl) {
|
||||
if (decl is MutableOwnerMirror) {
|
||||
decl.setOwner(mirror);
|
||||
}
|
||||
});
|
||||
|
||||
return mirror;
|
||||
}
|
||||
|
||||
@override
|
||||
TypeMirrorContract reflectType(Type type) {
|
||||
return _getOrCreateTypeMirror(type);
|
||||
}
|
||||
|
||||
TypeMirrorContract _getOrCreateTypeMirror(Type type) {
|
||||
return _types.putIfAbsent(
|
||||
type,
|
||||
() => TypeMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: _rootLibrary,
|
||||
metadata: const [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
IsolateMirrorContract get isolate => _isolate;
|
||||
|
||||
@override
|
||||
TypeMirrorContract get dynamicType => _dynamicType;
|
||||
|
||||
@override
|
||||
TypeMirrorContract get voidType => _voidType;
|
||||
|
||||
@override
|
||||
TypeMirrorContract get neverType => _neverType;
|
||||
|
||||
/// Adds a library to the mirror system.
|
||||
void addLibrary(LibraryMirrorContract library) {
|
||||
_libraries[library.uri] = library;
|
||||
}
|
||||
|
||||
/// Removes a library from the mirror system.
|
||||
void removeLibrary(Uri uri) {
|
||||
_libraries.remove(uri);
|
||||
}
|
||||
|
||||
/// Creates a mirror reflecting [reflectee].
|
||||
InstanceMirrorContract reflect(Object reflectee) {
|
||||
return InstanceMirror(
|
||||
reflectee: reflectee,
|
||||
type: reflectClass(reflectee.runtimeType),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The current mirror system.
|
||||
MirrorSystemContract currentMirrorSystem() => MirrorSystem.current();
|
||||
|
||||
/// Reflects an instance.
|
||||
InstanceMirrorContract reflect(Object reflectee) =>
|
||||
MirrorSystem.instance.reflect(reflectee);
|
||||
|
||||
/// Reflects a class.
|
||||
ClassMirrorContract reflectClass(Type key) =>
|
||||
MirrorSystem.instance.reflectClass(key);
|
||||
|
||||
/// Reflects a type.
|
||||
TypeMirrorContract reflectType(Type key) =>
|
||||
MirrorSystem.instance.reflectType(key);
|
|
@ -1,15 +0,0 @@
|
|||
/// Mirror implementations for the reflection system.
|
||||
library mirrors;
|
||||
|
||||
export 'base_mirror.dart';
|
||||
export 'class_mirror_impl.dart';
|
||||
export 'combinator_mirror_impl.dart';
|
||||
export 'instance_mirror_impl.dart';
|
||||
export 'isolate_mirror_impl.dart';
|
||||
export 'library_dependency_mirror_impl.dart';
|
||||
export 'library_mirror_impl.dart';
|
||||
export 'method_mirror_impl.dart';
|
||||
export 'parameter_mirror_impl.dart';
|
||||
export 'special_types.dart';
|
||||
export 'type_mirror_impl.dart';
|
||||
export 'variable_mirror_impl.dart';
|
|
@ -1,32 +1,31 @@
|
|||
import 'dart:core';
|
||||
import '../mirrors.dart';
|
||||
import 'base_mirror.dart';
|
||||
import 'type_mirror_impl.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [ParameterMirror] that provides reflection on parameters.
|
||||
class ParameterMirrorImpl extends MutableOwnerMirror
|
||||
implements ParameterMirror {
|
||||
/// Implementation of [ParameterMirrorContract] that provides reflection on parameters.
|
||||
class ParameterMirror extends MutableOwnerMirror
|
||||
implements ParameterMirrorContract {
|
||||
final String _name;
|
||||
final TypeMirror _type;
|
||||
final TypeMirrorContract _type;
|
||||
final bool _isOptional;
|
||||
final bool _isNamed;
|
||||
final bool _hasDefaultValue;
|
||||
final InstanceMirror? _defaultValue;
|
||||
final InstanceMirrorContract? _defaultValue;
|
||||
final bool _isFinal;
|
||||
final bool _isConst;
|
||||
final List<InstanceMirror> _metadata;
|
||||
final List<InstanceMirrorContract> _metadata;
|
||||
|
||||
ParameterMirrorImpl({
|
||||
ParameterMirror({
|
||||
required String name,
|
||||
required TypeMirror type,
|
||||
required DeclarationMirror owner,
|
||||
required TypeMirrorContract type,
|
||||
required DeclarationMirrorContract owner,
|
||||
bool isOptional = false,
|
||||
bool isNamed = false,
|
||||
bool hasDefaultValue = false,
|
||||
InstanceMirror? defaultValue,
|
||||
InstanceMirrorContract? defaultValue,
|
||||
bool isFinal = false,
|
||||
bool isConst = false,
|
||||
List<InstanceMirror> metadata = const [],
|
||||
List<InstanceMirrorContract> metadata = const [],
|
||||
}) : _name = name,
|
||||
_type = type,
|
||||
_isOptional = isOptional,
|
||||
|
@ -58,7 +57,7 @@ class ParameterMirrorImpl extends MutableOwnerMirror
|
|||
bool get isTopLevel => false;
|
||||
|
||||
@override
|
||||
TypeMirror get type => _type;
|
||||
TypeMirrorContract get type => _type;
|
||||
|
||||
@override
|
||||
bool get isStatic => false;
|
||||
|
@ -79,15 +78,15 @@ class ParameterMirrorImpl extends MutableOwnerMirror
|
|||
bool get hasDefaultValue => _hasDefaultValue;
|
||||
|
||||
@override
|
||||
InstanceMirror? get defaultValue => _defaultValue;
|
||||
InstanceMirrorContract? get defaultValue => _defaultValue;
|
||||
|
||||
@override
|
||||
List<InstanceMirror> get metadata => List.unmodifiable(_metadata);
|
||||
List<InstanceMirrorContract> get metadata => List.unmodifiable(_metadata);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! ParameterMirrorImpl) return false;
|
||||
if (other is! ParameterMirror) return false;
|
||||
|
||||
return _name == other._name &&
|
||||
_type == other._type &&
|
|
@ -1,33 +1,23 @@
|
|||
import 'dart:core';
|
||||
import '../mirrors.dart';
|
||||
import '../core/reflector.dart';
|
||||
import 'type_mirror_impl.dart';
|
||||
import 'class_mirror_impl.dart';
|
||||
import 'library_mirror_impl.dart';
|
||||
import 'library_dependency_mirror_impl.dart';
|
||||
import 'isolate_mirror_impl.dart';
|
||||
import 'special_types.dart';
|
||||
import 'variable_mirror_impl.dart';
|
||||
import 'method_mirror_impl.dart';
|
||||
import 'parameter_mirror_impl.dart';
|
||||
import 'base_mirror.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [MirrorSystem] that provides reflection on a set of libraries.
|
||||
class MirrorSystemImpl implements MirrorSystem {
|
||||
final Map<Uri, LibraryMirror> _libraries;
|
||||
final IsolateMirror _isolate;
|
||||
final TypeMirror _dynamicType;
|
||||
final TypeMirror _voidType;
|
||||
final TypeMirror _neverType;
|
||||
/// Implementation of [MirrorSystemContract] that provides reflection on a set of libraries.
|
||||
class MirrorSystem implements MirrorSystemContract {
|
||||
final Map<Uri, LibraryMirrorContract> _libraries;
|
||||
final IsolateMirrorContract _isolate;
|
||||
final TypeMirrorContract _dynamicType;
|
||||
final TypeMirrorContract _voidType;
|
||||
final TypeMirrorContract _neverType;
|
||||
|
||||
MirrorSystemImpl({
|
||||
required Map<Uri, LibraryMirror> libraries,
|
||||
required IsolateMirror isolate,
|
||||
MirrorSystem({
|
||||
required Map<Uri, LibraryMirrorContract> libraries,
|
||||
required IsolateMirrorContract isolate,
|
||||
}) : _libraries = libraries,
|
||||
_isolate = isolate,
|
||||
_dynamicType = TypeMirrorImpl.dynamicType(),
|
||||
_voidType = TypeMirrorImpl.voidType(),
|
||||
_neverType = TypeMirrorImpl(
|
||||
_dynamicType = TypeMirror.dynamicType(),
|
||||
_voidType = TypeMirror.voidType(),
|
||||
_neverType = TypeMirror(
|
||||
type: Never,
|
||||
name: 'Never',
|
||||
owner: null,
|
||||
|
@ -35,23 +25,23 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
);
|
||||
|
||||
/// Creates a mirror system for the current isolate.
|
||||
factory MirrorSystemImpl.current() {
|
||||
factory MirrorSystem.current() {
|
||||
// Create core library mirror
|
||||
final coreLibrary = LibraryMirrorImpl.withDeclarations(
|
||||
final coreLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart:core',
|
||||
uri: _createDartUri('core'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create async library mirror
|
||||
final asyncLibrary = LibraryMirrorImpl.withDeclarations(
|
||||
final asyncLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart:async',
|
||||
uri: _createDartUri('async'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create test library mirror
|
||||
final testLibrary = LibraryMirrorImpl.withDeclarations(
|
||||
final testLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'package:test/test.dart',
|
||||
uri: Uri.parse('package:test/test.dart'),
|
||||
owner: null,
|
||||
|
@ -59,7 +49,7 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
|
||||
// Add dependencies to core library
|
||||
final coreDependencies = [
|
||||
LibraryDependencyMirrorImpl(
|
||||
LibraryDependencyMirror(
|
||||
isImport: true,
|
||||
isDeferred: false,
|
||||
sourceLibrary: coreLibrary,
|
||||
|
@ -67,7 +57,7 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
prefix: null,
|
||||
combinators: const [],
|
||||
),
|
||||
LibraryDependencyMirrorImpl(
|
||||
LibraryDependencyMirror(
|
||||
isImport: false,
|
||||
isDeferred: false,
|
||||
sourceLibrary: coreLibrary,
|
||||
|
@ -78,7 +68,7 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
];
|
||||
|
||||
// Create root library with dependencies
|
||||
final rootLibrary = LibraryMirrorImpl(
|
||||
final rootLibrary = LibraryMirror(
|
||||
name: 'dart:core',
|
||||
uri: _createDartUri('core'),
|
||||
owner: null,
|
||||
|
@ -88,16 +78,16 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
);
|
||||
|
||||
// Create isolate mirror
|
||||
final isolate = IsolateMirrorImpl.current(rootLibrary);
|
||||
final isolate = IsolateMirror.current(rootLibrary);
|
||||
|
||||
// Create initial libraries map
|
||||
final libraries = <Uri, LibraryMirror>{
|
||||
final libraries = <Uri, LibraryMirrorContract>{
|
||||
rootLibrary.uri: rootLibrary,
|
||||
asyncLibrary.uri: asyncLibrary,
|
||||
testLibrary.uri: testLibrary,
|
||||
};
|
||||
|
||||
return MirrorSystemImpl(
|
||||
return MirrorSystem(
|
||||
libraries: libraries,
|
||||
isolate: isolate,
|
||||
);
|
||||
|
@ -123,10 +113,10 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
}
|
||||
|
||||
@override
|
||||
Map<Uri, LibraryMirror> get libraries => Map.unmodifiable(_libraries);
|
||||
Map<Uri, LibraryMirrorContract> get libraries => Map.unmodifiable(_libraries);
|
||||
|
||||
@override
|
||||
LibraryMirror findLibrary(Symbol libraryName) {
|
||||
LibraryMirrorContract findLibrary(Symbol libraryName) {
|
||||
final name = libraryName.toString();
|
||||
// Remove leading 'Symbol(' and trailing ')'
|
||||
final normalizedName = name.substring(7, name.length - 1);
|
||||
|
@ -140,14 +130,14 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
}
|
||||
|
||||
@override
|
||||
ClassMirror reflectClass(Type type) {
|
||||
ClassMirrorContract reflectClass(Type type) {
|
||||
// Check if type is reflectable
|
||||
if (!Reflector.isReflectable(type)) {
|
||||
throw ArgumentError('Type is not reflectable: $type');
|
||||
}
|
||||
|
||||
// Create temporary class mirror to serve as owner
|
||||
final tempMirror = ClassMirrorImpl(
|
||||
final tempMirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
|
@ -160,18 +150,18 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
// Get metadata from registry
|
||||
final properties = Reflector.getPropertyMetadata(type) ?? {};
|
||||
final methods = Reflector.getMethodMetadata(type) ?? {};
|
||||
final constructors = Reflector.getConstructorMetadata(type) ?? [];
|
||||
//final constructors = Reflector.getConstructorMetadata(type) ?? [];
|
||||
|
||||
// Create declarations map
|
||||
final declarations = <Symbol, DeclarationMirror>{};
|
||||
final instanceMembers = <Symbol, MethodMirror>{};
|
||||
final staticMembers = <Symbol, MethodMirror>{};
|
||||
final declarations = <Symbol, DeclarationMirrorContract>{};
|
||||
final instanceMembers = <Symbol, MethodMirrorContract>{};
|
||||
final staticMembers = <Symbol, MethodMirrorContract>{};
|
||||
|
||||
// Add properties and methods to declarations
|
||||
properties.forEach((name, prop) {
|
||||
declarations[Symbol(name)] = VariableMirrorImpl(
|
||||
declarations[Symbol(name)] = VariableMirror(
|
||||
name: name,
|
||||
type: TypeMirrorImpl(
|
||||
type: TypeMirror(
|
||||
type: prop.type,
|
||||
name: prop.type.toString(),
|
||||
owner: tempMirror,
|
||||
|
@ -186,16 +176,16 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
});
|
||||
|
||||
methods.forEach((name, method) {
|
||||
final methodMirror = MethodMirrorImpl(
|
||||
final methodMirror = MethodMirror(
|
||||
name: name,
|
||||
owner: tempMirror,
|
||||
returnType: method.returnsVoid
|
||||
? TypeMirrorImpl.voidType(tempMirror)
|
||||
: TypeMirrorImpl.dynamicType(tempMirror),
|
||||
? TypeMirror.voidType(tempMirror)
|
||||
: TypeMirror.dynamicType(tempMirror),
|
||||
parameters: method.parameters
|
||||
.map((param) => ParameterMirrorImpl(
|
||||
.map((param) => ParameterMirror(
|
||||
name: param.name,
|
||||
type: TypeMirrorImpl(
|
||||
type: TypeMirror(
|
||||
type: param.type,
|
||||
name: param.type.toString(),
|
||||
owner: tempMirror,
|
||||
|
@ -220,7 +210,7 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
});
|
||||
|
||||
// Create class mirror
|
||||
final mirror = ClassMirrorImpl(
|
||||
final mirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
|
@ -241,13 +231,13 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
}
|
||||
|
||||
@override
|
||||
TypeMirror reflectType(Type type) {
|
||||
TypeMirrorContract reflectType(Type type) {
|
||||
// Check if type is reflectable
|
||||
if (!Reflector.isReflectable(type)) {
|
||||
throw ArgumentError('Type is not reflectable: $type');
|
||||
}
|
||||
|
||||
return TypeMirrorImpl(
|
||||
return TypeMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
|
@ -256,19 +246,19 @@ class MirrorSystemImpl implements MirrorSystem {
|
|||
}
|
||||
|
||||
@override
|
||||
IsolateMirror get isolate => _isolate;
|
||||
IsolateMirrorContract get isolate => _isolate;
|
||||
|
||||
@override
|
||||
TypeMirror get dynamicType => _dynamicType;
|
||||
TypeMirrorContract get dynamicType => _dynamicType;
|
||||
|
||||
@override
|
||||
TypeMirror get voidType => _voidType;
|
||||
TypeMirrorContract get voidType => _voidType;
|
||||
|
||||
@override
|
||||
TypeMirror get neverType => _neverType;
|
||||
TypeMirrorContract get neverType => _neverType;
|
||||
|
||||
/// Adds a library to the mirror system.
|
||||
void addLibrary(LibraryMirror library) {
|
||||
void addLibrary(LibraryMirrorContract library) {
|
||||
_libraries[library.uri] = library;
|
||||
}
|
||||
|
315
incubation/reflection/lib/src/mirrors/temp.dart
Normal file
315
incubation/reflection/lib/src/mirrors/temp.dart
Normal file
|
@ -0,0 +1,315 @@
|
|||
import 'dart:core';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [MirrorSystemContract] that provides reflection on a set of libraries.
|
||||
class MirrorSystem implements MirrorSystemContract {
|
||||
/// The singleton instance of the mirror system.
|
||||
static final instance = MirrorSystem._();
|
||||
|
||||
final Map<Uri, LibraryMirrorContract> _libraries;
|
||||
final Map<Type, ClassMirrorContract> _classes = {};
|
||||
final Map<Type, TypeMirrorContract> _types = {};
|
||||
late final LibraryMirrorContract _rootLibrary;
|
||||
late final IsolateMirrorContract _isolate;
|
||||
late final TypeMirrorContract _dynamicType;
|
||||
late final TypeMirrorContract _voidType;
|
||||
late final TypeMirrorContract _neverType;
|
||||
|
||||
MirrorSystem._() : _libraries = {} {
|
||||
_initializeSystem();
|
||||
}
|
||||
|
||||
void _initializeSystem() {
|
||||
_initializeRootLibrary();
|
||||
_initializeCoreDependencies();
|
||||
_initializeSpecialTypes();
|
||||
_initializeIsolate();
|
||||
}
|
||||
|
||||
void _initializeRootLibrary() {
|
||||
_rootLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart.core',
|
||||
uri: Uri.parse('dart:core'),
|
||||
);
|
||||
_libraries[_rootLibrary.uri] = _rootLibrary;
|
||||
}
|
||||
|
||||
void _initializeCoreDependencies() {
|
||||
// Create core library mirror
|
||||
final coreLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart:core',
|
||||
uri: _createDartUri('core'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create async library mirror
|
||||
final asyncLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart:async',
|
||||
uri: _createDartUri('async'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create test library mirror
|
||||
final testLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'package:test/test.dart',
|
||||
uri: Uri.parse('package:test/test.dart'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Add dependencies to core library
|
||||
final coreDependencies = [
|
||||
LibraryDependencyMirror(
|
||||
isImport: true,
|
||||
isDeferred: false,
|
||||
sourceLibrary: coreLibrary,
|
||||
targetLibrary: asyncLibrary,
|
||||
prefix: null,
|
||||
combinators: const [],
|
||||
),
|
||||
LibraryDependencyMirror(
|
||||
isImport: false,
|
||||
isDeferred: false,
|
||||
sourceLibrary: coreLibrary,
|
||||
targetLibrary: asyncLibrary,
|
||||
prefix: null,
|
||||
combinators: const [],
|
||||
),
|
||||
];
|
||||
|
||||
// Update root library with dependencies
|
||||
_rootLibrary = LibraryMirror(
|
||||
name: 'dart:core',
|
||||
uri: _createDartUri('core'),
|
||||
owner: null,
|
||||
declarations: const {},
|
||||
libraryDependencies: coreDependencies,
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
// Add libraries to the map
|
||||
_libraries[coreLibrary.uri] = coreLibrary;
|
||||
_libraries[asyncLibrary.uri] = asyncLibrary;
|
||||
_libraries[testLibrary.uri] = testLibrary;
|
||||
}
|
||||
|
||||
void _initializeSpecialTypes() {
|
||||
_dynamicType = TypeMirror.dynamicType();
|
||||
_voidType = TypeMirror.voidType();
|
||||
_neverType = TypeMirror(
|
||||
type: Never,
|
||||
name: 'Never',
|
||||
owner: null,
|
||||
metadata: [],
|
||||
);
|
||||
}
|
||||
|
||||
void _initializeIsolate() {
|
||||
_isolate = IsolateMirror.current(_rootLibrary);
|
||||
}
|
||||
|
||||
/// Creates a URI for a dart: library.
|
||||
static Uri _createDartUri(String library) {
|
||||
return Uri(scheme: 'dart', path: library);
|
||||
}
|
||||
|
||||
/// Parses a library name into a URI.
|
||||
static Uri _parseLibraryName(String name) {
|
||||
if (name.startsWith('"') && name.endsWith('"')) {
|
||||
name = name.substring(1, name.length - 1);
|
||||
}
|
||||
|
||||
if (name.startsWith('dart:')) {
|
||||
final library = name.substring(5);
|
||||
return _createDartUri(library);
|
||||
}
|
||||
|
||||
return Uri.parse(name);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<Uri, LibraryMirrorContract> get libraries => Map.unmodifiable(_libraries);
|
||||
|
||||
@override
|
||||
LibraryMirrorContract findLibrary(Symbol libraryName) {
|
||||
final name = libraryName.toString();
|
||||
// Remove leading 'Symbol(' and trailing ')'
|
||||
final normalizedName = name.substring(7, name.length - 1);
|
||||
|
||||
final uri = _parseLibraryName(normalizedName);
|
||||
final library = _libraries[uri];
|
||||
if (library == null) {
|
||||
throw ArgumentError('Library not found: $normalizedName');
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
||||
@override
|
||||
ClassMirrorContract reflectClass(Type type) {
|
||||
return _classes.putIfAbsent(
|
||||
type,
|
||||
() => _createClassMirror(type),
|
||||
);
|
||||
}
|
||||
|
||||
ClassMirrorContract _createClassMirror(Type type) {
|
||||
// Check if type is reflectable
|
||||
if (!Reflector.isReflectable(type)) {
|
||||
throw ArgumentError('Type is not reflectable: $type');
|
||||
}
|
||||
|
||||
// Create temporary class mirror to serve as owner
|
||||
final tempMirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
declarations: const {},
|
||||
instanceMembers: const {},
|
||||
staticMembers: const {},
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
// Get metadata from registry
|
||||
final properties = Reflector.getPropertyMetadata(type) ?? {};
|
||||
final methods = Reflector.getMethodMetadata(type) ?? {};
|
||||
|
||||
// Create declarations map
|
||||
final declarations = <Symbol, DeclarationMirrorContract>{};
|
||||
final instanceMembers = <Symbol, MethodMirrorContract>{};
|
||||
final staticMembers = <Symbol, MethodMirrorContract>{};
|
||||
|
||||
// Add properties and methods to declarations
|
||||
properties.forEach((name, prop) {
|
||||
declarations[Symbol(name)] = VariableMirror(
|
||||
name: name,
|
||||
type: TypeMirror(
|
||||
type: prop.type,
|
||||
name: prop.type.toString(),
|
||||
owner: tempMirror,
|
||||
metadata: [],
|
||||
),
|
||||
owner: tempMirror,
|
||||
isStatic: false,
|
||||
isFinal: !prop.isWritable,
|
||||
isConst: false,
|
||||
metadata: [],
|
||||
);
|
||||
});
|
||||
|
||||
methods.forEach((name, method) {
|
||||
final methodMirror = MethodMirror(
|
||||
name: name,
|
||||
owner: tempMirror,
|
||||
returnType: method.returnsVoid
|
||||
? TypeMirror.voidType(tempMirror)
|
||||
: TypeMirror.dynamicType(tempMirror),
|
||||
parameters: method.parameters
|
||||
.map((param) => ParameterMirror(
|
||||
name: param.name,
|
||||
type: TypeMirror(
|
||||
type: param.type,
|
||||
name: param.type.toString(),
|
||||
owner: tempMirror,
|
||||
metadata: [],
|
||||
),
|
||||
owner: tempMirror,
|
||||
isOptional: !param.isRequired,
|
||||
isNamed: param.isNamed,
|
||||
metadata: [],
|
||||
))
|
||||
.toList(),
|
||||
isStatic: method.isStatic,
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
declarations[Symbol(name)] = methodMirror;
|
||||
if (method.isStatic) {
|
||||
staticMembers[Symbol(name)] = methodMirror;
|
||||
} else {
|
||||
instanceMembers[Symbol(name)] = methodMirror;
|
||||
}
|
||||
});
|
||||
|
||||
// Create class mirror
|
||||
final mirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
declarations: declarations,
|
||||
instanceMembers: instanceMembers,
|
||||
staticMembers: staticMembers,
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
// Update owners to point to the real class mirror
|
||||
declarations.forEach((_, decl) {
|
||||
if (decl is MutableOwnerMirror) {
|
||||
decl.setOwner(mirror);
|
||||
}
|
||||
});
|
||||
|
||||
return mirror;
|
||||
}
|
||||
|
||||
@override
|
||||
TypeMirrorContract reflectType(Type type) {
|
||||
return _getOrCreateTypeMirror(type);
|
||||
}
|
||||
|
||||
TypeMirrorContract _getOrCreateTypeMirror(Type type) {
|
||||
return _types.putIfAbsent(
|
||||
type,
|
||||
() => TypeMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: _rootLibrary,
|
||||
metadata: const [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
IsolateMirrorContract get isolate => _isolate;
|
||||
|
||||
@override
|
||||
TypeMirrorContract get dynamicType => _dynamicType;
|
||||
|
||||
@override
|
||||
TypeMirrorContract get voidType => _voidType;
|
||||
|
||||
@override
|
||||
TypeMirrorContract get neverType => _neverType;
|
||||
|
||||
/// Adds a library to the mirror system.
|
||||
void addLibrary(LibraryMirrorContract library) {
|
||||
_libraries[library.uri] = library;
|
||||
}
|
||||
|
||||
/// Removes a library from the mirror system.
|
||||
void removeLibrary(Uri uri) {
|
||||
_libraries.remove(uri);
|
||||
}
|
||||
|
||||
/// Creates a mirror reflecting [reflectee].
|
||||
InstanceMirrorContract reflect(Object reflectee) {
|
||||
return InstanceMirror(
|
||||
reflectee: reflectee,
|
||||
type: reflectClass(reflectee.runtimeType),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The current mirror system.
|
||||
MirrorSystemContract currentMirrorSystem() => MirrorSystem.instance;
|
||||
|
||||
/// Reflects an instance.
|
||||
InstanceMirrorContract reflect(Object reflectee) =>
|
||||
MirrorSystem.instance.reflect(reflectee);
|
||||
|
||||
/// Reflects a class.
|
||||
ClassMirrorContract reflectClass(Type key) =>
|
||||
MirrorSystem.instance.reflectClass(key);
|
||||
|
||||
/// Reflects a type.
|
||||
TypeMirrorContract reflectType(Type key) =>
|
||||
MirrorSystem.instance.reflectType(key);
|
318
incubation/reflection/lib/src/mirrors/temp3.dart
Normal file
318
incubation/reflection/lib/src/mirrors/temp3.dart
Normal file
|
@ -0,0 +1,318 @@
|
|||
import 'dart:core';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [MirrorSystemContract] that provides reflection on a set of libraries.
|
||||
class MirrorSystem implements MirrorSystemContract {
|
||||
static MirrorSystem? _instance;
|
||||
|
||||
static MirrorSystem get instance {
|
||||
return _instance ??= MirrorSystem._();
|
||||
}
|
||||
|
||||
final Map<Uri, LibraryMirrorContract> _libraries = {};
|
||||
final Map<Type, ClassMirrorContract> _classes = {};
|
||||
final Map<Type, TypeMirrorContract> _types = {};
|
||||
late final LibraryMirrorContract _rootLibrary;
|
||||
late final IsolateMirrorContract _isolate;
|
||||
late final TypeMirrorContract _dynamicType;
|
||||
late final TypeMirrorContract _voidType;
|
||||
late final TypeMirrorContract _neverType;
|
||||
|
||||
// Private constructor
|
||||
MirrorSystem._() {
|
||||
_initializeSystem();
|
||||
}
|
||||
|
||||
void _initializeSystem() {
|
||||
_initializeRootLibrary();
|
||||
_initializeCoreDependencies();
|
||||
_initializeSpecialTypes();
|
||||
_initializeIsolate();
|
||||
}
|
||||
|
||||
void _initializeRootLibrary() {
|
||||
_rootLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart.core',
|
||||
uri: Uri.parse('dart:core'),
|
||||
);
|
||||
_libraries[_rootLibrary.uri] = _rootLibrary;
|
||||
}
|
||||
|
||||
void _initializeCoreDependencies() {
|
||||
// Create core library mirror
|
||||
final coreLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart:core',
|
||||
uri: _createDartUri('core'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create async library mirror
|
||||
final asyncLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'dart:async',
|
||||
uri: _createDartUri('async'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Create test library mirror
|
||||
final testLibrary = LibraryMirror.withDeclarations(
|
||||
name: 'package:test/test.dart',
|
||||
uri: Uri.parse('package:test/test.dart'),
|
||||
owner: null,
|
||||
);
|
||||
|
||||
// Add dependencies to core library
|
||||
final coreDependencies = [
|
||||
LibraryDependencyMirror(
|
||||
isImport: true,
|
||||
isDeferred: false,
|
||||
sourceLibrary: coreLibrary,
|
||||
targetLibrary: asyncLibrary,
|
||||
prefix: null,
|
||||
combinators: const [],
|
||||
),
|
||||
LibraryDependencyMirror(
|
||||
isImport: false,
|
||||
isDeferred: false,
|
||||
sourceLibrary: coreLibrary,
|
||||
targetLibrary: asyncLibrary,
|
||||
prefix: null,
|
||||
combinators: const [],
|
||||
),
|
||||
];
|
||||
|
||||
// Update core library with dependencies
|
||||
_libraries[coreLibrary.uri] = LibraryMirror(
|
||||
name: 'dart:core',
|
||||
uri: _createDartUri('core'),
|
||||
owner: null,
|
||||
declarations: const {},
|
||||
libraryDependencies: coreDependencies,
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
// Add libraries to the map
|
||||
_libraries[asyncLibrary.uri] = asyncLibrary;
|
||||
_libraries[testLibrary.uri] = testLibrary;
|
||||
}
|
||||
|
||||
void _initializeSpecialTypes() {
|
||||
_dynamicType = TypeMirror.dynamicType();
|
||||
_voidType = TypeMirror.voidType();
|
||||
_neverType = TypeMirror(
|
||||
type: Never,
|
||||
name: 'Never',
|
||||
owner: null,
|
||||
metadata: [],
|
||||
);
|
||||
}
|
||||
|
||||
void _initializeIsolate() {
|
||||
_isolate = IsolateMirror.current(_rootLibrary);
|
||||
}
|
||||
|
||||
/// Creates a URI for a dart: library.
|
||||
static Uri _createDartUri(String library) {
|
||||
return Uri(scheme: 'dart', path: library);
|
||||
}
|
||||
|
||||
/// Parses a library name into a URI.
|
||||
static Uri _parseLibraryName(String name) {
|
||||
if (name.startsWith('"') && name.endsWith('"')) {
|
||||
name = name.substring(1, name.length - 1);
|
||||
}
|
||||
|
||||
if (name.startsWith('dart:')) {
|
||||
final library = name.substring(5);
|
||||
return _createDartUri(library);
|
||||
}
|
||||
|
||||
return Uri.parse(name);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<Uri, LibraryMirrorContract> get libraries => Map.unmodifiable(_libraries);
|
||||
|
||||
@override
|
||||
LibraryMirrorContract findLibrary(Symbol libraryName) {
|
||||
final name = libraryName.toString();
|
||||
// Remove leading 'Symbol(' and trailing ')'
|
||||
final normalizedName = name.substring(7, name.length - 1);
|
||||
|
||||
final uri = _parseLibraryName(normalizedName);
|
||||
final library = _libraries[uri];
|
||||
if (library == null) {
|
||||
throw ArgumentError('Library not found: $normalizedName');
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
||||
@override
|
||||
ClassMirrorContract reflectClass(Type type) {
|
||||
return _classes.putIfAbsent(
|
||||
type,
|
||||
() => _createClassMirror(type),
|
||||
);
|
||||
}
|
||||
|
||||
ClassMirrorContract _createClassMirror(Type type) {
|
||||
// Check if type is reflectable
|
||||
if (!Reflector.isReflectable(type)) {
|
||||
throw ArgumentError('Type is not reflectable: $type');
|
||||
}
|
||||
|
||||
// Create temporary class mirror to serve as owner
|
||||
final tempMirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
declarations: const {},
|
||||
instanceMembers: const {},
|
||||
staticMembers: const {},
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
// Get metadata from registry
|
||||
final properties = Reflector.getPropertyMetadata(type) ?? {};
|
||||
final methods = Reflector.getMethodMetadata(type) ?? {};
|
||||
|
||||
// Create declarations map
|
||||
final declarations = <Symbol, DeclarationMirrorContract>{};
|
||||
final instanceMembers = <Symbol, MethodMirrorContract>{};
|
||||
final staticMembers = <Symbol, MethodMirrorContract>{};
|
||||
|
||||
// Add properties and methods to declarations
|
||||
properties.forEach((name, prop) {
|
||||
declarations[Symbol(name)] = VariableMirror(
|
||||
name: name,
|
||||
type: TypeMirror(
|
||||
type: prop.type,
|
||||
name: prop.type.toString(),
|
||||
owner: tempMirror,
|
||||
metadata: [],
|
||||
),
|
||||
owner: tempMirror,
|
||||
isStatic: false,
|
||||
isFinal: !prop.isWritable,
|
||||
isConst: false,
|
||||
metadata: [],
|
||||
);
|
||||
});
|
||||
|
||||
methods.forEach((name, method) {
|
||||
final methodMirror = MethodMirror(
|
||||
name: name,
|
||||
owner: tempMirror,
|
||||
returnType: method.returnsVoid
|
||||
? TypeMirror.voidType(tempMirror)
|
||||
: TypeMirror.dynamicType(tempMirror),
|
||||
parameters: method.parameters
|
||||
.map((param) => ParameterMirror(
|
||||
name: param.name,
|
||||
type: TypeMirror(
|
||||
type: param.type,
|
||||
name: param.type.toString(),
|
||||
owner: tempMirror,
|
||||
metadata: [],
|
||||
),
|
||||
owner: tempMirror,
|
||||
isOptional: !param.isRequired,
|
||||
isNamed: param.isNamed,
|
||||
metadata: [],
|
||||
))
|
||||
.toList(),
|
||||
isStatic: method.isStatic,
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
declarations[Symbol(name)] = methodMirror;
|
||||
if (method.isStatic) {
|
||||
staticMembers[Symbol(name)] = methodMirror;
|
||||
} else {
|
||||
instanceMembers[Symbol(name)] = methodMirror;
|
||||
}
|
||||
});
|
||||
|
||||
// Create class mirror
|
||||
final mirror = ClassMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: null,
|
||||
declarations: declarations,
|
||||
instanceMembers: instanceMembers,
|
||||
staticMembers: staticMembers,
|
||||
metadata: [],
|
||||
);
|
||||
|
||||
// Update owners to point to the real class mirror
|
||||
declarations.forEach((_, decl) {
|
||||
if (decl is MutableOwnerMirror) {
|
||||
decl.setOwner(mirror);
|
||||
}
|
||||
});
|
||||
|
||||
return mirror;
|
||||
}
|
||||
|
||||
@override
|
||||
TypeMirrorContract reflectType(Type type) {
|
||||
return _getOrCreateTypeMirror(type);
|
||||
}
|
||||
|
||||
TypeMirrorContract _getOrCreateTypeMirror(Type type) {
|
||||
return _types.putIfAbsent(
|
||||
type,
|
||||
() => TypeMirror(
|
||||
type: type,
|
||||
name: type.toString(),
|
||||
owner: _rootLibrary,
|
||||
metadata: const [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
IsolateMirrorContract get isolate => _isolate;
|
||||
|
||||
@override
|
||||
TypeMirrorContract get dynamicType => _dynamicType;
|
||||
|
||||
@override
|
||||
TypeMirrorContract get voidType => _voidType;
|
||||
|
||||
@override
|
||||
TypeMirrorContract get neverType => _neverType;
|
||||
|
||||
/// Adds a library to the mirror system.
|
||||
void addLibrary(LibraryMirrorContract library) {
|
||||
_libraries[library.uri] = library;
|
||||
}
|
||||
|
||||
/// Removes a library from the mirror system.
|
||||
void removeLibrary(Uri uri) {
|
||||
_libraries.remove(uri);
|
||||
}
|
||||
|
||||
/// Creates a mirror reflecting [reflectee].
|
||||
InstanceMirrorContract reflect(Object reflectee) {
|
||||
return InstanceMirror(
|
||||
reflectee: reflectee,
|
||||
type: reflectClass(reflectee.runtimeType),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The current mirror system.
|
||||
MirrorSystemContract currentMirrorSystem() => MirrorSystem.instance;
|
||||
|
||||
/// Reflects an instance.
|
||||
InstanceMirrorContract reflect(Object reflectee) =>
|
||||
MirrorSystem.instance.reflect(reflectee);
|
||||
|
||||
/// Reflects a class.
|
||||
ClassMirrorContract reflectClass(Type key) =>
|
||||
MirrorSystem.instance.reflectClass(key);
|
||||
|
||||
/// Reflects a type.
|
||||
TypeMirrorContract reflectType(Type key) =>
|
||||
MirrorSystem.instance.reflectType(key);
|
|
@ -1,28 +1,25 @@
|
|||
import 'dart:core';
|
||||
import '../mirrors.dart';
|
||||
import '../core/reflector.dart';
|
||||
import '../metadata.dart';
|
||||
import 'base_mirror.dart';
|
||||
import 'special_types.dart';
|
||||
import 'type_variable_mirror_impl.dart';
|
||||
import 'package:platform_contracts/contracts.dart'
|
||||
hide PropertyMetadata, MethodMetadata, ConstructorMetadata;
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [TypeMirror] that provides reflection on types.
|
||||
class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
||||
final List<TypeVariableMirror> _typeVariables;
|
||||
final List<TypeMirror> _typeArguments;
|
||||
/// Implementation of [TypeMirrorContract] that provides reflection on types.
|
||||
class TypeMirror extends TypedMirror implements TypeMirrorContract {
|
||||
final List<TypeVariableMirrorContract> _typeVariables;
|
||||
final List<TypeMirrorContract> _typeArguments;
|
||||
final bool _isOriginalDeclaration;
|
||||
final TypeMirror? _originalDeclaration;
|
||||
final TypeMirrorContract? _originalDeclaration;
|
||||
final bool _isGeneric;
|
||||
|
||||
TypeMirrorImpl({
|
||||
TypeMirror({
|
||||
required Type type,
|
||||
required String name,
|
||||
DeclarationMirror? owner,
|
||||
List<TypeVariableMirror> typeVariables = const [],
|
||||
List<TypeMirror> typeArguments = const [],
|
||||
DeclarationMirrorContract? owner,
|
||||
List<TypeVariableMirrorContract> typeVariables = const [],
|
||||
List<TypeMirrorContract> typeArguments = const [],
|
||||
bool isOriginalDeclaration = true,
|
||||
TypeMirror? originalDeclaration,
|
||||
List<InstanceMirror> metadata = const [],
|
||||
TypeMirrorContract? originalDeclaration,
|
||||
List<InstanceMirrorContract> metadata = const [],
|
||||
}) : _typeVariables = typeVariables,
|
||||
_typeArguments = typeArguments,
|
||||
_isOriginalDeclaration = isOriginalDeclaration,
|
||||
|
@ -46,19 +43,19 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
}
|
||||
|
||||
/// Creates a TypeMirror from TypeMetadata.
|
||||
factory TypeMirrorImpl.fromMetadata(TypeMetadata typeMetadata,
|
||||
[DeclarationMirror? owner]) {
|
||||
factory TypeMirror.fromMetadata(TypeMetadata typeMetadata,
|
||||
[DeclarationMirrorContract? owner]) {
|
||||
// Get type variables from metadata
|
||||
final typeVariables = typeMetadata.typeParameters.map((param) {
|
||||
// Create upper bound type mirror
|
||||
final upperBound = TypeMirrorImpl(
|
||||
final upperBound = TypeMirror(
|
||||
type: param.bound ?? Object,
|
||||
name: param.bound?.toString() ?? 'Object',
|
||||
owner: owner,
|
||||
);
|
||||
|
||||
// Create type variable mirror
|
||||
return TypeVariableMirrorImpl(
|
||||
return TypeVariableMirror(
|
||||
type: param.type,
|
||||
name: param.name,
|
||||
upperBound: upperBound,
|
||||
|
@ -68,14 +65,14 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
|
||||
// Get type arguments from metadata
|
||||
final typeArguments = typeMetadata.typeArguments.map((arg) {
|
||||
return TypeMirrorImpl(
|
||||
return TypeMirror(
|
||||
type: arg.type,
|
||||
name: arg.name,
|
||||
owner: owner,
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return TypeMirrorImpl(
|
||||
return TypeMirror(
|
||||
type: typeMetadata.type,
|
||||
name: typeMetadata.name,
|
||||
owner: owner,
|
||||
|
@ -86,8 +83,8 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
}
|
||||
|
||||
/// Creates a TypeMirror for void.
|
||||
factory TypeMirrorImpl.voidType([DeclarationMirror? owner]) {
|
||||
return TypeMirrorImpl(
|
||||
factory TypeMirror.voidType([DeclarationMirrorContract? owner]) {
|
||||
return TypeMirror(
|
||||
type: voidType,
|
||||
name: 'void',
|
||||
owner: owner,
|
||||
|
@ -96,8 +93,8 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
}
|
||||
|
||||
/// Creates a TypeMirror for dynamic.
|
||||
factory TypeMirrorImpl.dynamicType([DeclarationMirror? owner]) {
|
||||
return TypeMirrorImpl(
|
||||
factory TypeMirror.dynamicType([DeclarationMirrorContract? owner]) {
|
||||
return TypeMirror(
|
||||
type: dynamicType,
|
||||
name: 'dynamic',
|
||||
owner: owner,
|
||||
|
@ -106,7 +103,8 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
}
|
||||
|
||||
/// Creates a new TypeMirror with the given type arguments.
|
||||
TypeMirror instantiateGeneric(List<TypeMirror> typeArguments) {
|
||||
TypeMirrorContract instantiateGeneric(
|
||||
List<TypeMirrorContract> typeArguments) {
|
||||
if (!_isGeneric) {
|
||||
throw StateError('Type $name is not generic');
|
||||
}
|
||||
|
@ -126,7 +124,7 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
}
|
||||
}
|
||||
|
||||
return TypeMirrorImpl(
|
||||
return TypeMirror(
|
||||
type: type,
|
||||
name: name,
|
||||
owner: owner,
|
||||
|
@ -145,17 +143,18 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
Type get reflectedType => type;
|
||||
|
||||
@override
|
||||
List<TypeVariableMirror> get typeVariables =>
|
||||
List<TypeVariableMirrorContract> get typeVariables =>
|
||||
List.unmodifiable(_typeVariables);
|
||||
|
||||
@override
|
||||
List<TypeMirror> get typeArguments => List.unmodifiable(_typeArguments);
|
||||
List<TypeMirrorContract> get typeArguments =>
|
||||
List.unmodifiable(_typeArguments);
|
||||
|
||||
@override
|
||||
bool get isOriginalDeclaration => _isOriginalDeclaration;
|
||||
|
||||
@override
|
||||
TypeMirror get originalDeclaration {
|
||||
TypeMirrorContract get originalDeclaration {
|
||||
if (isOriginalDeclaration) return this;
|
||||
return _originalDeclaration!;
|
||||
}
|
||||
|
@ -176,9 +175,9 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
Reflector.getConstructorMetadata(type) ?? [];
|
||||
|
||||
@override
|
||||
bool isSubtypeOf(TypeMirror other) {
|
||||
bool isSubtypeOf(TypeMirrorContract other) {
|
||||
if (this == other) return true;
|
||||
if (other is! TypeMirrorImpl) return false;
|
||||
if (other is! TypeMirror) return false;
|
||||
|
||||
// Never is a subtype of all types
|
||||
if (type == Never) return true;
|
||||
|
@ -195,19 +194,19 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
|
||||
// Check supertype
|
||||
if (metadata.supertype != null) {
|
||||
final superMirror = TypeMirrorImpl.fromMetadata(metadata.supertype!);
|
||||
final superMirror = TypeMirror.fromMetadata(metadata.supertype!);
|
||||
if (superMirror.isSubtypeOf(other)) return true;
|
||||
}
|
||||
|
||||
// Check interfaces
|
||||
for (final interface in metadata.interfaces) {
|
||||
final interfaceMirror = TypeMirrorImpl.fromMetadata(interface);
|
||||
final interfaceMirror = TypeMirror.fromMetadata(interface);
|
||||
if (interfaceMirror.isSubtypeOf(other)) return true;
|
||||
}
|
||||
|
||||
// Check mixins
|
||||
for (final mixin in metadata.mixins) {
|
||||
final mixinMirror = TypeMirrorImpl.fromMetadata(mixin);
|
||||
final mixinMirror = TypeMirror.fromMetadata(mixin);
|
||||
if (mixinMirror.isSubtypeOf(other)) return true;
|
||||
}
|
||||
|
||||
|
@ -234,13 +233,11 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
}
|
||||
|
||||
@override
|
||||
bool isAssignableTo(TypeMirror other) {
|
||||
bool isAssignableTo(TypeMirrorContract other) {
|
||||
// A type T may be assigned to a type S if either:
|
||||
// 1. T is a subtype of S, or
|
||||
// 2. S is dynamic (except for void)
|
||||
if (other is TypeMirrorImpl &&
|
||||
other.type == dynamicType &&
|
||||
type != voidType) {
|
||||
if (other is TypeMirror && other.type == dynamicType && type != voidType) {
|
||||
return true;
|
||||
}
|
||||
return isSubtypeOf(other);
|
||||
|
@ -249,7 +246,7 @@ class TypeMirrorImpl extends TypedMirror implements TypeMirror {
|
|||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! TypeMirrorImpl) return false;
|
||||
if (other is! TypeMirror) return false;
|
||||
|
||||
return type == other.type &&
|
||||
name == other.name &&
|
|
@ -1,18 +1,18 @@
|
|||
import '../mirrors.dart';
|
||||
import '../metadata.dart';
|
||||
import 'base_mirror.dart';
|
||||
import 'type_mirror_impl.dart';
|
||||
import 'package:platform_contracts/contracts.dart'
|
||||
hide PropertyMetadata, MethodMetadata, ConstructorMetadata;
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [TypeVariableMirror] that provides reflection on type variables.
|
||||
class TypeVariableMirrorImpl extends TypedMirror implements TypeVariableMirror {
|
||||
final TypeMirror _upperBound;
|
||||
/// Implementation of [TypeVariableMirrorContract] that provides reflection on type variables.
|
||||
class TypeVariableMirror extends TypedMirror
|
||||
implements TypeVariableMirrorContract {
|
||||
final TypeMirrorContract _upperBound;
|
||||
|
||||
TypeVariableMirrorImpl({
|
||||
TypeVariableMirror({
|
||||
required Type type,
|
||||
required String name,
|
||||
required TypeMirror upperBound,
|
||||
DeclarationMirror? owner,
|
||||
List<InstanceMirror> metadata = const [],
|
||||
required TypeMirrorContract upperBound,
|
||||
DeclarationMirrorContract? owner,
|
||||
List<InstanceMirrorContract> metadata = const [],
|
||||
}) : _upperBound = upperBound,
|
||||
super(
|
||||
type: type,
|
||||
|
@ -22,7 +22,7 @@ class TypeVariableMirrorImpl extends TypedMirror implements TypeVariableMirror {
|
|||
);
|
||||
|
||||
@override
|
||||
TypeMirror get upperBound => _upperBound;
|
||||
TypeMirrorContract get upperBound => _upperBound;
|
||||
|
||||
@override
|
||||
bool get hasReflectedType => true;
|
||||
|
@ -31,42 +31,39 @@ class TypeVariableMirrorImpl extends TypedMirror implements TypeVariableMirror {
|
|||
Type get reflectedType => type;
|
||||
|
||||
@override
|
||||
List<TypeVariableMirror> get typeVariables => const [];
|
||||
List<TypeVariableMirrorContract> get typeVariables => const [];
|
||||
|
||||
@override
|
||||
List<TypeMirror> get typeArguments => const [];
|
||||
List<TypeMirrorContract> get typeArguments => const [];
|
||||
|
||||
@override
|
||||
bool get isOriginalDeclaration => true;
|
||||
|
||||
@override
|
||||
TypeMirror get originalDeclaration => this;
|
||||
TypeMirrorContract get originalDeclaration => this;
|
||||
|
||||
@override
|
||||
bool isSubtypeOf(TypeMirror other) {
|
||||
bool isSubtypeOf(TypeMirrorContract other) {
|
||||
if (identical(this, other)) return true;
|
||||
return _upperBound.isSubtypeOf(other);
|
||||
}
|
||||
|
||||
@override
|
||||
bool isAssignableTo(TypeMirror other) {
|
||||
bool isAssignableTo(TypeMirrorContract other) {
|
||||
if (identical(this, other)) return true;
|
||||
return _upperBound.isAssignableTo(other);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, PropertyMetadata> get properties => const {};
|
||||
|
||||
@override
|
||||
Map<String, MethodMetadata> get methods => const {};
|
||||
|
||||
@override
|
||||
List<ConstructorMetadata> get constructors => const [];
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! TypeVariableMirrorImpl) return false;
|
||||
if (other is! TypeVariableMirror) return false;
|
||||
|
||||
return type == other.type &&
|
||||
name == other.name &&
|
|
@ -1,25 +1,25 @@
|
|||
import 'dart:core';
|
||||
import '../mirrors.dart';
|
||||
import 'base_mirror.dart';
|
||||
import 'type_mirror_impl.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Implementation of [VariableMirror] that provides reflection on variables.
|
||||
class VariableMirrorImpl extends MutableOwnerMirror implements VariableMirror {
|
||||
final TypeMirror _type;
|
||||
/// Implementation of [VariableMirrorContract] that provides reflection on variables.
|
||||
class VariableMirror extends MutableOwnerMirror
|
||||
implements VariableMirrorContract {
|
||||
final TypeMirrorContract _type;
|
||||
final String _name;
|
||||
final bool _isStatic;
|
||||
final bool _isFinal;
|
||||
final bool _isConst;
|
||||
final List<InstanceMirror> _metadata;
|
||||
final List<InstanceMirrorContract> _metadata;
|
||||
|
||||
VariableMirrorImpl({
|
||||
VariableMirror({
|
||||
required String name,
|
||||
required TypeMirror type,
|
||||
DeclarationMirror? owner,
|
||||
required TypeMirrorContract type,
|
||||
DeclarationMirrorContract? owner,
|
||||
bool isStatic = false,
|
||||
bool isFinal = false,
|
||||
bool isConst = false,
|
||||
List<InstanceMirror> metadata = const [],
|
||||
List<InstanceMirrorContract> metadata = const [],
|
||||
}) : _name = name,
|
||||
_type = type,
|
||||
_isStatic = isStatic,
|
||||
|
@ -45,10 +45,10 @@ class VariableMirrorImpl extends MutableOwnerMirror implements VariableMirror {
|
|||
bool get isPrivate => _name.startsWith('_');
|
||||
|
||||
@override
|
||||
bool get isTopLevel => owner is LibraryMirror;
|
||||
bool get isTopLevel => owner is LibraryMirrorContract;
|
||||
|
||||
@override
|
||||
TypeMirror get type => _type;
|
||||
TypeMirrorContract get type => _type;
|
||||
|
||||
@override
|
||||
bool get isStatic => _isStatic;
|
||||
|
@ -60,12 +60,12 @@ class VariableMirrorImpl extends MutableOwnerMirror implements VariableMirror {
|
|||
bool get isConst => _isConst;
|
||||
|
||||
@override
|
||||
List<InstanceMirror> get metadata => List.unmodifiable(_metadata);
|
||||
List<InstanceMirrorContract> get metadata => List.unmodifiable(_metadata);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
if (other is! VariableMirrorImpl) return false;
|
||||
if (other is! VariableMirror) return false;
|
||||
|
||||
return _name == other._name &&
|
||||
_type == other._type &&
|
||||
|
@ -98,21 +98,21 @@ class VariableMirrorImpl extends MutableOwnerMirror implements VariableMirror {
|
|||
}
|
||||
}
|
||||
|
||||
/// Implementation of [VariableMirror] specifically for fields.
|
||||
class FieldMirrorImpl extends VariableMirrorImpl {
|
||||
/// Implementation of [VariableMirrorContract] specifically for fields.
|
||||
class FieldMirrorImpl extends VariableMirror {
|
||||
final bool _isReadable;
|
||||
final bool _isWritable;
|
||||
|
||||
FieldMirrorImpl({
|
||||
required String name,
|
||||
required TypeMirror type,
|
||||
DeclarationMirror? owner,
|
||||
required TypeMirrorContract type,
|
||||
DeclarationMirrorContract? owner,
|
||||
bool isStatic = false,
|
||||
bool isFinal = false,
|
||||
bool isConst = false,
|
||||
bool isReadable = true,
|
||||
bool isWritable = true,
|
||||
List<InstanceMirror> metadata = const [],
|
||||
List<InstanceMirrorContract> metadata = const [],
|
||||
}) : _isReadable = isReadable,
|
||||
_isWritable = isWritable,
|
||||
super(
|
|
@ -1,19 +0,0 @@
|
|||
/// Represents the void type in our reflection system.
|
||||
class VoidType implements Type {
|
||||
const VoidType._();
|
||||
|
||||
/// The singleton instance representing void.
|
||||
static const instance = VoidType._();
|
||||
|
||||
@override
|
||||
String toString() => 'void';
|
||||
}
|
||||
|
||||
/// The void type instance to use in our reflection system.
|
||||
const voidType = VoidType.instance;
|
||||
|
||||
/// Extension to check if a Type is void.
|
||||
extension TypeExtensions on Type {
|
||||
/// Whether this type represents void.
|
||||
bool get isVoid => this == voidType;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import 'dart:isolate';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
// Function to run in isolate
|
||||
|
@ -50,8 +50,8 @@ void main() {
|
|||
receivePort.sendPort,
|
||||
);
|
||||
|
||||
final isolateMirror = reflector.reflectIsolate(isolate, 'test-isolate')
|
||||
as IsolateMirrorImpl;
|
||||
final isolateMirror =
|
||||
reflector.reflectIsolate(isolate, 'test-isolate') as IsolateMirror;
|
||||
|
||||
// Test pause/resume
|
||||
await isolateMirror.pause();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
// Top-level function for testing
|
||||
|
@ -44,14 +45,15 @@ void main() {
|
|||
expect(declarations, isNotEmpty);
|
||||
|
||||
// Check for top-level function
|
||||
final addFunction = declarations[const Symbol('add')] as MethodMirror;
|
||||
final addFunction =
|
||||
declarations[const Symbol('add')] as MethodMirrorContract;
|
||||
expect(addFunction, isNotNull);
|
||||
expect(addFunction.isStatic, isTrue);
|
||||
expect(addFunction.parameters.length, equals(2));
|
||||
|
||||
// Check for top-level variable
|
||||
final greetingVar =
|
||||
declarations[const Symbol('greeting')] as VariableMirror;
|
||||
declarations[const Symbol('greeting')] as VariableMirrorContract;
|
||||
expect(greetingVar, isNotNull);
|
||||
expect(greetingVar.isStatic, isTrue);
|
||||
expect(greetingVar.isConst, isTrue);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_contracts/contracts.dart' hide PropertyMetadata;
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@reflectable
|
||||
|
@ -9,12 +10,12 @@ class TestClass {
|
|||
|
||||
void main() {
|
||||
group('MirrorSystem', () {
|
||||
late RuntimeReflector reflector;
|
||||
late MirrorSystem mirrorSystem;
|
||||
//late RuntimeReflector reflector;
|
||||
late MirrorSystemContract mirrorSystem;
|
||||
|
||||
setUp(() {
|
||||
reflector = RuntimeReflector.instance;
|
||||
mirrorSystem = reflector.currentMirrorSystem;
|
||||
//reflector = RuntimeReflector.instance;
|
||||
mirrorSystem = MirrorSystem.instance;
|
||||
|
||||
// Register test class
|
||||
Reflector.registerType(TestClass);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@reflectable
|
||||
|
@ -53,7 +54,7 @@ void main() {
|
|||
|
||||
group('Property Access', () {
|
||||
late Person person;
|
||||
late InstanceMirror mirror;
|
||||
late InstanceMirrorContract mirror;
|
||||
|
||||
setUp(() {
|
||||
Reflector.register(Person);
|
||||
|
@ -90,7 +91,7 @@ void main() {
|
|||
|
||||
group('Method Invocation', () {
|
||||
late Person person;
|
||||
late InstanceMirror mirror;
|
||||
late InstanceMirrorContract mirror;
|
||||
|
||||
setUp(() {
|
||||
Reflector.register(Person);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@reflectable
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'collection.dart';
|
||||
|
||||
/// A proxy class for higher-order collection operations.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:platform_collections/src/collection.dart';
|
||||
import 'package:platform_collections/src/higher_order_collection_proxy.dart';
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
*/
|
||||
|
||||
/// Base mirror interface
|
||||
abstract class Mirror {}
|
||||
abstract class MirrorContract {}
|
||||
|
||||
/// Base declaration mirror interface
|
||||
abstract class DeclarationMirror implements Mirror {
|
||||
abstract class DeclarationMirrorContract implements MirrorContract {
|
||||
/// The simple name for this Dart language entity.
|
||||
Symbol get simpleName;
|
||||
|
||||
|
@ -19,7 +19,7 @@ abstract class DeclarationMirror implements Mirror {
|
|||
Symbol get qualifiedName;
|
||||
|
||||
/// A mirror on the owner of this Dart language entity.
|
||||
DeclarationMirror? get owner;
|
||||
DeclarationMirrorContract? get owner;
|
||||
|
||||
/// Whether this declaration is library private.
|
||||
bool get isPrivate;
|
||||
|
@ -28,29 +28,30 @@ abstract class DeclarationMirror implements Mirror {
|
|||
bool get isTopLevel;
|
||||
|
||||
/// A list of the metadata associated with this declaration.
|
||||
List<InstanceMirror> get metadata;
|
||||
List<InstanceMirrorContract> get metadata;
|
||||
|
||||
/// The name of this declaration.
|
||||
String get name;
|
||||
}
|
||||
|
||||
/// Base object mirror interface
|
||||
abstract class ObjectMirror implements Mirror {
|
||||
abstract class ObjectMirrorContract implements MirrorContract {
|
||||
/// Invokes the named function and returns a mirror on the result.
|
||||
InstanceMirror invoke(Symbol memberName, List<dynamic> positionalArguments,
|
||||
InstanceMirrorContract invoke(
|
||||
Symbol memberName, List<dynamic> positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments = const {}]);
|
||||
|
||||
/// Invokes a getter and returns a mirror on the result.
|
||||
InstanceMirror getField(Symbol fieldName);
|
||||
InstanceMirrorContract getField(Symbol fieldName);
|
||||
|
||||
/// Invokes a setter and returns a mirror on the result.
|
||||
InstanceMirror setField(Symbol fieldName, dynamic value);
|
||||
InstanceMirrorContract setField(Symbol fieldName, dynamic value);
|
||||
}
|
||||
|
||||
/// Base instance mirror interface
|
||||
abstract class InstanceMirror implements ObjectMirror {
|
||||
abstract class InstanceMirrorContract implements ObjectMirrorContract {
|
||||
/// A mirror on the type of the instance.
|
||||
ClassMirror get type;
|
||||
ClassMirrorContract get type;
|
||||
|
||||
/// Whether this mirror's reflectee is accessible.
|
||||
bool get hasReflectee;
|
||||
|
@ -60,12 +61,13 @@ abstract class InstanceMirror implements ObjectMirror {
|
|||
}
|
||||
|
||||
/// Base class mirror interface
|
||||
abstract class ClassMirror implements TypeMirror, ObjectMirror {
|
||||
abstract class ClassMirrorContract
|
||||
implements TypeMirrorContract, ObjectMirrorContract {
|
||||
/// A mirror on the superclass.
|
||||
ClassMirror? get superclass;
|
||||
ClassMirrorContract? get superclass;
|
||||
|
||||
/// Mirrors on the superinterfaces.
|
||||
List<ClassMirror> get superinterfaces;
|
||||
List<ClassMirrorContract> get superinterfaces;
|
||||
|
||||
/// Whether this class is abstract.
|
||||
bool get isAbstract;
|
||||
|
@ -74,25 +76,25 @@ abstract class ClassMirror implements TypeMirror, ObjectMirror {
|
|||
bool get isEnum;
|
||||
|
||||
/// The declarations in this class.
|
||||
Map<Symbol, DeclarationMirror> get declarations;
|
||||
Map<Symbol, DeclarationMirrorContract> get declarations;
|
||||
|
||||
/// The instance members of this class.
|
||||
Map<Symbol, MethodMirror> get instanceMembers;
|
||||
Map<Symbol, MethodMirrorContract> get instanceMembers;
|
||||
|
||||
/// The static members of this class.
|
||||
Map<Symbol, MethodMirror> get staticMembers;
|
||||
Map<Symbol, MethodMirrorContract> get staticMembers;
|
||||
|
||||
/// Creates a new instance using the specified constructor.
|
||||
InstanceMirror newInstance(
|
||||
InstanceMirrorContract newInstance(
|
||||
Symbol constructorName, List<dynamic> positionalArguments,
|
||||
[Map<Symbol, dynamic> namedArguments = const {}]);
|
||||
|
||||
/// Whether this class is a subclass of [other].
|
||||
bool isSubclassOf(ClassMirror other);
|
||||
bool isSubclassOf(ClassMirrorContract other);
|
||||
}
|
||||
|
||||
/// Base type mirror interface
|
||||
abstract class TypeMirror implements DeclarationMirror {
|
||||
abstract class TypeMirrorContract implements DeclarationMirrorContract {
|
||||
/// Whether this mirror reflects a type available at runtime.
|
||||
bool get hasReflectedType;
|
||||
|
||||
|
@ -100,34 +102,34 @@ abstract class TypeMirror implements DeclarationMirror {
|
|||
Type get reflectedType;
|
||||
|
||||
/// Type variables declared on this type.
|
||||
List<TypeVariableMirror> get typeVariables;
|
||||
List<TypeVariableMirrorContract> get typeVariables;
|
||||
|
||||
/// Type arguments provided to this type.
|
||||
List<TypeMirror> get typeArguments;
|
||||
List<TypeMirrorContract> get typeArguments;
|
||||
|
||||
/// Whether this is the original declaration of this type.
|
||||
bool get isOriginalDeclaration;
|
||||
|
||||
/// A mirror on the original declaration of this type.
|
||||
TypeMirror get originalDeclaration;
|
||||
TypeMirrorContract get originalDeclaration;
|
||||
|
||||
/// Checks if this type is a subtype of [other].
|
||||
bool isSubtypeOf(TypeMirror other);
|
||||
bool isSubtypeOf(TypeMirrorContract other);
|
||||
|
||||
/// Checks if this type is assignable to [other].
|
||||
bool isAssignableTo(TypeMirror other);
|
||||
bool isAssignableTo(TypeMirrorContract other);
|
||||
}
|
||||
|
||||
/// Base method mirror interface
|
||||
abstract class MethodMirror implements DeclarationMirror {
|
||||
abstract class MethodMirrorContract implements DeclarationMirrorContract {
|
||||
/// A mirror on the return type.
|
||||
TypeMirror get returnType;
|
||||
TypeMirrorContract get returnType;
|
||||
|
||||
/// The source code if available.
|
||||
String? get source;
|
||||
|
||||
/// Mirrors on the parameters.
|
||||
List<ParameterMirror> get parameters;
|
||||
List<ParameterMirrorContract> get parameters;
|
||||
|
||||
/// Whether this is a static method.
|
||||
bool get isStatic;
|
||||
|
@ -170,7 +172,7 @@ abstract class MethodMirror implements DeclarationMirror {
|
|||
}
|
||||
|
||||
/// Base parameter mirror interface
|
||||
abstract class ParameterMirror implements VariableMirror {
|
||||
abstract class ParameterMirrorContract implements VariableMirrorContract {
|
||||
/// Whether this is an optional parameter.
|
||||
bool get isOptional;
|
||||
|
||||
|
@ -181,13 +183,13 @@ abstract class ParameterMirror implements VariableMirror {
|
|||
bool get hasDefaultValue;
|
||||
|
||||
/// The default value if this is an optional parameter.
|
||||
InstanceMirror? get defaultValue;
|
||||
InstanceMirrorContract? get defaultValue;
|
||||
}
|
||||
|
||||
/// Base variable mirror interface
|
||||
abstract class VariableMirror implements DeclarationMirror {
|
||||
abstract class VariableMirrorContract implements DeclarationMirrorContract {
|
||||
/// A mirror on the type of this variable.
|
||||
TypeMirror get type;
|
||||
TypeMirrorContract get type;
|
||||
|
||||
/// Whether this is a static variable.
|
||||
bool get isStatic;
|
||||
|
@ -200,25 +202,26 @@ abstract class VariableMirror implements DeclarationMirror {
|
|||
}
|
||||
|
||||
/// Base type variable mirror interface
|
||||
abstract class TypeVariableMirror implements TypeMirror {
|
||||
abstract class TypeVariableMirrorContract implements TypeMirrorContract {
|
||||
/// A mirror on the upper bound of this type variable.
|
||||
TypeMirror get upperBound;
|
||||
TypeMirrorContract get upperBound;
|
||||
}
|
||||
|
||||
/// Base library mirror interface
|
||||
abstract class LibraryMirror implements DeclarationMirror, ObjectMirror {
|
||||
abstract class LibraryMirrorContract
|
||||
implements DeclarationMirrorContract, ObjectMirrorContract {
|
||||
/// The absolute URI of the library.
|
||||
Uri get uri;
|
||||
|
||||
/// The declarations in this library.
|
||||
Map<Symbol, DeclarationMirror> get declarations;
|
||||
Map<Symbol, DeclarationMirrorContract> get declarations;
|
||||
|
||||
/// The imports and exports of this library.
|
||||
List<LibraryDependencyMirror> get libraryDependencies;
|
||||
List<LibraryDependencyMirrorContract> get libraryDependencies;
|
||||
}
|
||||
|
||||
/// Base library dependency mirror interface
|
||||
abstract class LibraryDependencyMirror implements Mirror {
|
||||
abstract class LibraryDependencyMirrorContract implements MirrorContract {
|
||||
/// Whether this is an import.
|
||||
bool get isImport;
|
||||
|
||||
|
@ -229,20 +232,20 @@ abstract class LibraryDependencyMirror implements Mirror {
|
|||
bool get isDeferred;
|
||||
|
||||
/// The library containing this dependency.
|
||||
LibraryMirror get sourceLibrary;
|
||||
LibraryMirrorContract get sourceLibrary;
|
||||
|
||||
/// The target library of this dependency.
|
||||
LibraryMirror? get targetLibrary;
|
||||
LibraryMirrorContract? get targetLibrary;
|
||||
|
||||
/// The prefix if this is a prefixed import.
|
||||
Symbol? get prefix;
|
||||
|
||||
/// The show/hide combinators on this dependency.
|
||||
List<CombinatorMirror> get combinators;
|
||||
List<CombinatorMirrorContract> get combinators;
|
||||
}
|
||||
|
||||
/// Base combinator mirror interface
|
||||
abstract class CombinatorMirror implements Mirror {
|
||||
abstract class CombinatorMirrorContract implements MirrorContract {
|
||||
/// The identifiers in this combinator.
|
||||
List<Symbol> get identifiers;
|
||||
|
||||
|
@ -252,3 +255,42 @@ abstract class CombinatorMirror implements Mirror {
|
|||
/// Whether this is a hide combinator.
|
||||
bool get isHide;
|
||||
}
|
||||
|
||||
/// An [IsolateMirrorContract] reflects an isolate.
|
||||
abstract class IsolateMirrorContract implements MirrorContract {
|
||||
/// A unique name used to refer to the isolate in debugging messages.
|
||||
String get debugName;
|
||||
|
||||
/// Whether this mirror reflects the currently running isolate.
|
||||
bool get isCurrent;
|
||||
|
||||
/// The root library for the reflected isolate.
|
||||
LibraryMirrorContract get rootLibrary;
|
||||
}
|
||||
|
||||
/// A [MirrorSystemContract] is the main interface used to reflect on a set of libraries.
|
||||
abstract class MirrorSystemContract {
|
||||
/// All libraries known to the mirror system.
|
||||
Map<Uri, LibraryMirrorContract> get libraries;
|
||||
|
||||
/// Returns the unique library with the specified name.
|
||||
LibraryMirrorContract findLibrary(Symbol libraryName);
|
||||
|
||||
/// Returns a mirror for the specified class.
|
||||
ClassMirrorContract reflectClass(Type type);
|
||||
|
||||
/// Returns a mirror for the specified type.
|
||||
TypeMirrorContract reflectType(Type type);
|
||||
|
||||
/// A mirror on the isolate associated with this mirror system.
|
||||
IsolateMirrorContract get isolate;
|
||||
|
||||
/// A mirror on the dynamic type.
|
||||
TypeMirrorContract get dynamicType;
|
||||
|
||||
/// A mirror on the void type.
|
||||
TypeMirrorContract get voidType;
|
||||
|
||||
/// A mirror on the Never type.
|
||||
TypeMirrorContract get neverType;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
*/
|
||||
|
||||
import 'base.dart';
|
||||
import 'metadata.dart';
|
||||
|
||||
export 'base.dart';
|
||||
export 'metadata.dart';
|
||||
|
@ -16,16 +15,16 @@ export 'metadata.dart';
|
|||
/// Core reflector contract for type introspection.
|
||||
abstract class ReflectorContract {
|
||||
/// Get a class mirror
|
||||
ClassMirror? reflectClass(Type type);
|
||||
ClassMirrorContract? reflectClass(Type type);
|
||||
|
||||
/// Get a type mirror
|
||||
TypeMirror reflectType(Type type);
|
||||
TypeMirrorContract reflectType(Type type);
|
||||
|
||||
/// Get an instance mirror
|
||||
InstanceMirror reflect(Object object);
|
||||
InstanceMirrorContract reflect(Object object);
|
||||
|
||||
/// Get a library mirror
|
||||
LibraryMirror reflectLibrary(Uri uri);
|
||||
LibraryMirrorContract reflectLibrary(Uri uri);
|
||||
|
||||
/// Create a new instance
|
||||
dynamic createInstance(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Interface for objects that can provide methods to be mixed in
|
||||
abstract class MacroProvider {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:platform_macroable/platform_macroable.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
@reflectable
|
||||
class TestClass with Macroable {}
|
||||
|
|
7
packages/mirrors/.gitignore
vendored
Normal file
7
packages/mirrors/.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
# https://dart.dev/guides/libraries/private-files
|
||||
# Created by `dart pub`
|
||||
.dart_tool/
|
||||
|
||||
# Avoid committing pubspec.lock for library packages; see
|
||||
# https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
pubspec.lock
|
3
packages/mirrors/CHANGELOG.md
Normal file
3
packages/mirrors/CHANGELOG.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
## 1.0.0
|
||||
|
||||
- Initial version.
|
10
packages/mirrors/LICENSE.md
Normal file
10
packages/mirrors/LICENSE.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
The Laravel Framework is Copyright (c) Taylor Otwell
|
||||
The Fabric Framework is Copyright (c) Vieo, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
packages/mirrors/README.md
Normal file
1
packages/mirrors/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
<p align="center"><a href="https://protevus.com" target="_blank"><img src="https://git.protevus.com/protevus/branding/raw/branch/main/protevus-logo-bg.png"></a></p>
|
30
packages/mirrors/analysis_options.yaml
Normal file
30
packages/mirrors/analysis_options.yaml
Normal file
|
@ -0,0 +1,30 @@
|
|||
# This file configures the static analysis results for your project (errors,
|
||||
# warnings, and lints).
|
||||
#
|
||||
# This enables the 'recommended' set of lints from `package:lints`.
|
||||
# This set helps identify many issues that may lead to problems when running
|
||||
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
|
||||
# style and format.
|
||||
#
|
||||
# If you want a smaller set of lints you can change this to specify
|
||||
# 'package:lints/core.yaml'. These are just the most critical lints
|
||||
# (the recommended set includes the core lints).
|
||||
# The core lints are also what is used by pub.dev for scoring packages.
|
||||
|
||||
include: package:lints/recommended.yaml
|
||||
|
||||
# Uncomment the following section to specify additional rules.
|
||||
|
||||
# linter:
|
||||
# rules:
|
||||
# - camel_case_types
|
||||
|
||||
# analyzer:
|
||||
# exclude:
|
||||
# - path/to/excluded/files/**
|
||||
|
||||
# For more information about the core and recommended set of lints, see
|
||||
# https://dart.dev/go/core-lints
|
||||
|
||||
# For additional information about configuring this file, see
|
||||
# https://dart.dev/guides/language/analysis-options
|
0
packages/mirrors/doc/.gitkeep
Normal file
0
packages/mirrors/doc/.gitkeep
Normal file
0
packages/mirrors/example/.gitkeep
Normal file
0
packages/mirrors/example/.gitkeep
Normal file
0
packages/mirrors/lib/src/.gitkeep
Normal file
0
packages/mirrors/lib/src/.gitkeep
Normal file
20
packages/mirrors/pubspec.yaml
Normal file
20
packages/mirrors/pubspec.yaml
Normal file
|
@ -0,0 +1,20 @@
|
|||
name: platform_mirrors
|
||||
description: A lightweight, cross-platform reflection system for Dart
|
||||
version: 0.0.1
|
||||
homepage: https://protevus.com
|
||||
documentation: https://docs.protevus.com
|
||||
repository: https://github.com/protevus/platformo
|
||||
|
||||
environment:
|
||||
sdk: '>=3.0.0 <4.0.0'
|
||||
|
||||
dependencies:
|
||||
platform_contracts: ^0.1.0
|
||||
meta: ^1.9.0
|
||||
collection: ^1.17.0
|
||||
|
||||
dev_dependencies:
|
||||
test: ^1.24.0
|
||||
mockito: ^5.4.0
|
||||
build_runner: ^2.4.0
|
||||
lints: ^2.1.0
|
0
packages/mirrors/test/.gitkeep
Normal file
0
packages/mirrors/test/.gitkeep
Normal file
|
@ -1,5 +1,5 @@
|
|||
import 'package:platform_macroable/platform_macroable.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Provides higher-order tap functionality with macro support.
|
||||
///
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'once.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// A class that provides functionality to ensure methods are only executed once.
|
||||
///
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:platform_macroable/platform_macroable.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Provides Laravel-like Optional type functionality with macro support.
|
||||
///
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/src/core/reflector.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// Provides reflection utilities for examining types and methods at runtime.
|
||||
class SupportReflector {
|
||||
|
@ -64,7 +64,7 @@ class SupportReflector {
|
|||
}
|
||||
|
||||
/// Get the class name of the given parameter's type, if possible.
|
||||
static String? getParameterClassName(ParameterMirror parameter) {
|
||||
static String? getParameterClassName(ParameterMirrorContract parameter) {
|
||||
final type = parameter.type;
|
||||
|
||||
if (!type.hasReflectedType) {
|
||||
|
@ -75,7 +75,8 @@ class SupportReflector {
|
|||
}
|
||||
|
||||
/// Get the class names of the given parameter's type, including union types.
|
||||
static List<String> getParameterClassNames(ParameterMirror parameter) {
|
||||
static List<String> getParameterClassNames(
|
||||
ParameterMirrorContract parameter) {
|
||||
final type = parameter.type;
|
||||
final classNames = <String>[];
|
||||
|
||||
|
@ -106,13 +107,14 @@ class SupportReflector {
|
|||
}
|
||||
|
||||
/// Get the given type's class name.
|
||||
static String? _getTypeName(ParameterMirror parameter, TypeMirror type) {
|
||||
static String? _getTypeName(
|
||||
ParameterMirrorContract parameter, TypeMirrorContract type) {
|
||||
if (!type.hasReflectedType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final name = type.reflectedType.toString();
|
||||
final declaringClass = parameter.owner as ClassMirror?;
|
||||
final declaringClass = parameter.owner as ClassMirrorContract?;
|
||||
|
||||
if (declaringClass != null) {
|
||||
if (name == 'self') {
|
||||
|
@ -129,7 +131,7 @@ class SupportReflector {
|
|||
|
||||
/// Determine if the parameter's type is a subclass of the given type.
|
||||
static bool isParameterSubclassOf(
|
||||
ParameterMirror parameter, String className) {
|
||||
ParameterMirrorContract parameter, String className) {
|
||||
final type = parameter.type;
|
||||
if (!type.hasReflectedType) {
|
||||
return false;
|
||||
|
@ -145,7 +147,7 @@ class SupportReflector {
|
|||
|
||||
/// Determine if the parameter's type is a backed enum with a string backing type.
|
||||
static bool isParameterBackedEnumWithStringBackingType(
|
||||
ParameterMirror parameter) {
|
||||
ParameterMirrorContract parameter) {
|
||||
final type = parameter.type;
|
||||
if (!type.hasReflectedType) {
|
||||
return false;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:meta/meta.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// A mixin that provides method forwarding functionality.
|
||||
///
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
/// A trait that provides functionality to reflect on closures.
|
||||
mixin ReflectsClosures {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import 'package:test/test.dart';
|
||||
import 'package:platform_support/platform_support.dart';
|
||||
import 'package:platform_macroable/platform_macroable.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
|
||||
// Test class to use with HigherOrderTapProxy
|
||||
class TestTarget {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:test/test.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'package:platform_support/platform_support.dart';
|
||||
|
||||
void main() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:test/test.dart';
|
||||
import 'package:platform_support/platform_support.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
@reflectable
|
||||
class TargetClass {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:test/test.dart';
|
||||
import 'package:platform_support/platform_support.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
@reflectable
|
||||
class TestObject {
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
import 'package:test/test.dart';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'package:platform_support/platform_support.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/src/core/reflector.dart';
|
||||
import 'package:platform_reflection/src/mirrors/method_mirror_impl.dart';
|
||||
import 'package:platform_reflection/src/mirrors/parameter_mirror_impl.dart';
|
||||
import 'package:platform_reflection/src/mirrors/type_mirror_impl.dart';
|
||||
import 'package:platform_reflection/src/mirrors/class_mirror_impl.dart';
|
||||
|
||||
class TestClass {
|
||||
void publicMethod() {}
|
||||
|
@ -28,29 +24,29 @@ enum BackedEnum {
|
|||
}
|
||||
|
||||
void main() {
|
||||
late ClassMirrorImpl testClassMirror;
|
||||
late ClassMirror testClassMirror;
|
||||
|
||||
setUp(() {
|
||||
// Create type mirrors
|
||||
final voidType = TypeMirrorImpl(
|
||||
final voidType = TypeMirror(
|
||||
type: Null, // Using Null as a stand-in for void
|
||||
name: 'void',
|
||||
owner: null,
|
||||
metadata: const [],
|
||||
);
|
||||
final stringType = TypeMirrorImpl(
|
||||
final stringType = TypeMirror(
|
||||
type: String,
|
||||
name: 'String',
|
||||
owner: null,
|
||||
metadata: const [],
|
||||
);
|
||||
final invocationType = TypeMirrorImpl(
|
||||
final invocationType = TypeMirror(
|
||||
type: Invocation,
|
||||
name: 'Invocation',
|
||||
owner: null,
|
||||
metadata: const [],
|
||||
);
|
||||
final objectType = TypeMirrorImpl(
|
||||
final objectType = TypeMirror(
|
||||
type: Object,
|
||||
name: 'Object',
|
||||
owner: null,
|
||||
|
@ -58,7 +54,7 @@ void main() {
|
|||
);
|
||||
|
||||
// Create class mirrors
|
||||
testClassMirror = ClassMirrorImpl(
|
||||
testClassMirror = ClassMirror(
|
||||
type: TestClass,
|
||||
name: 'TestClass',
|
||||
owner: null,
|
||||
|
@ -69,34 +65,34 @@ void main() {
|
|||
);
|
||||
|
||||
// Create parameter mirrors
|
||||
final selfParam = ParameterMirrorImpl(
|
||||
final selfParam = ParameterMirror(
|
||||
name: 'self',
|
||||
type: objectType, // Using Object type for inheritance test
|
||||
owner: testClassMirror,
|
||||
);
|
||||
|
||||
final invocationParam = ParameterMirrorImpl(
|
||||
final invocationParam = ParameterMirror(
|
||||
name: 'invocation',
|
||||
type: invocationType,
|
||||
owner: testClassMirror,
|
||||
);
|
||||
|
||||
// Create method mirrors
|
||||
final publicMethodMirror = MethodMirrorImpl(
|
||||
final publicMethodMirror = MethodMirror(
|
||||
name: 'publicMethod',
|
||||
owner: testClassMirror,
|
||||
returnType: voidType,
|
||||
parameters: [selfParam],
|
||||
);
|
||||
|
||||
final privateMethodMirror = MethodMirrorImpl(
|
||||
final privateMethodMirror = MethodMirror(
|
||||
name: '_privateMethod',
|
||||
owner: testClassMirror,
|
||||
returnType: voidType,
|
||||
parameters: [selfParam],
|
||||
);
|
||||
|
||||
final noSuchMethodMirror = MethodMirrorImpl(
|
||||
final noSuchMethodMirror = MethodMirror(
|
||||
name: 'noSuchMethod',
|
||||
owner: testClassMirror,
|
||||
returnType: voidType,
|
||||
|
@ -208,16 +204,16 @@ void main() {
|
|||
});
|
||||
|
||||
test('getParameterClassName returns correct class name', () {
|
||||
final method =
|
||||
testClassMirror.declarations[Symbol('publicMethod')] as MethodMirror;
|
||||
final method = testClassMirror.declarations[Symbol('publicMethod')]
|
||||
as MethodMirrorContract;
|
||||
final param = method.parameters.first;
|
||||
|
||||
expect(SupportReflector.getParameterClassName(param), equals('Object'));
|
||||
});
|
||||
|
||||
test('getParameterClassNames handles union types', () {
|
||||
final method =
|
||||
testClassMirror.declarations[Symbol('publicMethod')] as MethodMirror;
|
||||
final method = testClassMirror.declarations[Symbol('publicMethod')]
|
||||
as MethodMirrorContract;
|
||||
final param = method.parameters.first;
|
||||
|
||||
final classNames = SupportReflector.getParameterClassNames(param);
|
||||
|
@ -226,8 +222,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('isParameterSubclassOf checks inheritance correctly', () {
|
||||
final method =
|
||||
testClassMirror.declarations[Symbol('publicMethod')] as MethodMirror;
|
||||
final method = testClassMirror.declarations[Symbol('publicMethod')]
|
||||
as MethodMirrorContract;
|
||||
final param = method.parameters.first;
|
||||
|
||||
expect(SupportReflector.isParameterSubclassOf(param, 'Object'), isTrue);
|
||||
|
@ -236,13 +232,13 @@ void main() {
|
|||
test(
|
||||
'isParameterBackedEnumWithStringBackingType returns true for backed enums',
|
||||
() {
|
||||
final type = TypeMirrorImpl(
|
||||
final type = TypeMirror(
|
||||
type: BackedEnum,
|
||||
name: 'BackedEnum',
|
||||
owner: null,
|
||||
metadata: const [],
|
||||
);
|
||||
final param = ParameterMirrorImpl(
|
||||
final param = ParameterMirror(
|
||||
name: 'param',
|
||||
type: type,
|
||||
owner: testClassMirror,
|
||||
|
@ -255,13 +251,13 @@ void main() {
|
|||
test(
|
||||
'isParameterBackedEnumWithStringBackingType returns false for simple enums',
|
||||
() {
|
||||
final type = TypeMirrorImpl(
|
||||
final type = TypeMirror(
|
||||
type: SimpleEnum,
|
||||
name: 'SimpleEnum',
|
||||
owner: null,
|
||||
metadata: const [],
|
||||
);
|
||||
final param = ParameterMirrorImpl(
|
||||
final param = ParameterMirror(
|
||||
name: 'param',
|
||||
type: type,
|
||||
owner: testClassMirror,
|
||||
|
@ -274,13 +270,13 @@ void main() {
|
|||
test(
|
||||
'isParameterBackedEnumWithStringBackingType returns false for non-enums',
|
||||
() {
|
||||
final type = TypeMirrorImpl(
|
||||
final type = TypeMirror(
|
||||
type: String,
|
||||
name: 'String',
|
||||
owner: null,
|
||||
metadata: const [],
|
||||
);
|
||||
final param = ParameterMirrorImpl(
|
||||
final param = ParameterMirror(
|
||||
name: 'param',
|
||||
type: type,
|
||||
owner: testClassMirror,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:test/test.dart';
|
||||
import 'package:platform_support/platform_support.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
|
||||
@reflectable
|
||||
class TappableTest with Tappable {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:test/test.dart';
|
||||
import 'package:platform_reflection/reflection.dart';
|
||||
import 'package:platform_reflection/mirrors.dart';
|
||||
import 'package:platform_support/src/traits/reflects_closures.dart';
|
||||
|
||||
class TestClass with ReflectsClosures {}
|
||||
|
|
Loading…
Reference in a new issue