refactor: refactoring mirrors further
This commit is contained in:
parent
a79809f46b
commit
d0ff4db4a0
6 changed files with 35 additions and 33 deletions
|
@ -13,8 +13,9 @@ export 'src/core/mirror_system.dart';
|
|||
|
||||
/// Discovery
|
||||
export 'src/discovery/type_analyzer.dart';
|
||||
export 'src/discovery/library_scanner.dart';
|
||||
export 'src/discovery/scanner.dart';
|
||||
export 'src/discovery/library_analyzer.dart';
|
||||
export 'src/discovery/runtime_library_discoverer.dart';
|
||||
export 'src/discovery/runtime_type_discoverer.dart';
|
||||
|
||||
/// Discovery Models
|
||||
export 'src/discovery/models/models.dart';
|
||||
|
|
|
@ -1,27 +1,6 @@
|
|||
import 'dart:core';
|
||||
import 'package:platform_contracts/contracts.dart';
|
||||
import 'package:platform_mirrors/mirrors.dart';
|
||||
|
||||
/// Runtime scanner that analyzes libraries and extracts their metadata.
|
||||
class LibraryScanner {
|
||||
// Private constructor to prevent instantiation
|
||||
LibraryScanner._();
|
||||
|
||||
// Cache for library metadata
|
||||
static final Map<Uri, LibraryInfo> _libraryCache = {};
|
||||
|
||||
/// Scans a library and extracts its metadata.
|
||||
static LibraryInfo scanLibrary(Uri uri) {
|
||||
if (_libraryCache.containsKey(uri)) {
|
||||
return _libraryCache[uri]!;
|
||||
}
|
||||
|
||||
final libraryInfo = LibraryAnalyzer.analyze(uri);
|
||||
_libraryCache[uri] = libraryInfo;
|
||||
return libraryInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/// Analyzes libraries at runtime to extract their metadata.
|
||||
class LibraryAnalyzer {
|
||||
// Private constructor to prevent instantiation
|
|
@ -0,0 +1,22 @@
|
|||
import 'dart:core';
|
||||
import 'package:platform_mirrors/mirrors.dart';
|
||||
|
||||
/// Runtime scanner that analyzes libraries and extracts their metadata.
|
||||
class RuntimeLibraryDiscoverer {
|
||||
// Private constructor to prevent instantiation
|
||||
RuntimeLibraryDiscoverer._();
|
||||
|
||||
// Cache for library metadata
|
||||
static final Map<Uri, LibraryInfo> _libraryCache = {};
|
||||
|
||||
/// Scans a library and extracts its metadata.
|
||||
static LibraryInfo scanLibrary(Uri uri) {
|
||||
if (_libraryCache.containsKey(uri)) {
|
||||
return _libraryCache[uri]!;
|
||||
}
|
||||
|
||||
final libraryInfo = LibraryAnalyzer.analyze(uri);
|
||||
_libraryCache[uri] = libraryInfo;
|
||||
return libraryInfo;
|
||||
}
|
||||
}
|
|
@ -2,9 +2,9 @@ import 'dart:core';
|
|||
import 'package:platform_mirrors/mirrors.dart';
|
||||
|
||||
/// Runtime scanner that analyzes types and extracts their metadata.
|
||||
class Scanner {
|
||||
class RuntimeTypeDiscoverer {
|
||||
// Private constructor to prevent instantiation
|
||||
Scanner._();
|
||||
RuntimeTypeDiscoverer._();
|
||||
|
||||
// Cache for type metadata
|
||||
static final Map<Type, TypeMetadata> _typeCache = {};
|
|
@ -37,7 +37,7 @@ class LibraryMirror extends TypedMirror implements LibraryMirrorContract {
|
|||
List<InstanceMirrorContract> metadata = const [],
|
||||
}) {
|
||||
// Scan library to get declarations
|
||||
final libraryInfo = LibraryScanner.scanLibrary(uri);
|
||||
final libraryInfo = RuntimeLibraryDiscoverer.scanLibrary(uri);
|
||||
final declarations = <Symbol, DeclarationMirrorContract>{};
|
||||
final topLevelValues = <Symbol, dynamic>{};
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ void main() {
|
|||
isWritable: false);
|
||||
|
||||
// Scan type
|
||||
Scanner.scanType(TestClass);
|
||||
RuntimeTypeDiscoverer.scanType(TestClass);
|
||||
final metadata = ReflectionRegistry.getPropertyMetadata(TestClass);
|
||||
|
||||
expect(metadata, isNotNull);
|
||||
|
@ -130,7 +130,7 @@ void main() {
|
|||
);
|
||||
|
||||
// Scan type
|
||||
Scanner.scanType(TestClass);
|
||||
RuntimeTypeDiscoverer.scanType(TestClass);
|
||||
final metadata = ReflectionRegistry.getMethodMetadata(TestClass);
|
||||
|
||||
expect(metadata, isNotNull);
|
||||
|
@ -187,7 +187,7 @@ void main() {
|
|||
);
|
||||
|
||||
// Scan type
|
||||
Scanner.scanType(TestClass);
|
||||
RuntimeTypeDiscoverer.scanType(TestClass);
|
||||
final metadata = ReflectionRegistry.getConstructorMetadata(TestClass);
|
||||
|
||||
expect(metadata, isNotNull);
|
||||
|
@ -255,7 +255,7 @@ void main() {
|
|||
);
|
||||
|
||||
// Scan type
|
||||
Scanner.scanType(TestClass);
|
||||
RuntimeTypeDiscoverer.scanType(TestClass);
|
||||
|
||||
final reflector = RuntimeReflector.instance;
|
||||
|
||||
|
@ -320,7 +320,7 @@ void main() {
|
|||
);
|
||||
|
||||
// Scan type
|
||||
Scanner.scanType(GenericTestClass);
|
||||
RuntimeTypeDiscoverer.scanType(GenericTestClass);
|
||||
final metadata = ReflectionRegistry.getPropertyMetadata(GenericTestClass);
|
||||
|
||||
expect(metadata, isNotNull);
|
||||
|
@ -364,8 +364,8 @@ void main() {
|
|||
);
|
||||
|
||||
// Scan types
|
||||
Scanner.scanType(ParentTestClass);
|
||||
Scanner.scanType(ChildTestClass);
|
||||
RuntimeTypeDiscoverer.scanType(ParentTestClass);
|
||||
RuntimeTypeDiscoverer.scanType(ChildTestClass);
|
||||
|
||||
final parentMeta =
|
||||
ReflectionRegistry.getPropertyMetadata(ParentTestClass);
|
||||
|
|
Loading…
Reference in a new issue