update: 41 pass 3 fail
This commit is contained in:
parent
74e91914c2
commit
7b5290e9d9
2 changed files with 21 additions and 40 deletions
|
@ -67,46 +67,32 @@ class Scanner {
|
||||||
|
|
||||||
// Create and register factory function
|
// Create and register factory function
|
||||||
final factory = _createConstructorFactory(type, constructor);
|
final factory = _createConstructorFactory(type, constructor);
|
||||||
|
if (factory != null) {
|
||||||
Reflector.registerConstructorFactory(type, constructor.name, factory);
|
Reflector.registerConstructorFactory(type, constructor.name, factory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a constructor factory function for a given type and constructor.
|
/// Creates a constructor factory function for a given type and constructor.
|
||||||
static Function _createConstructorFactory(
|
static Function? _createConstructorFactory(
|
||||||
Type type, ConstructorInfo constructor) {
|
Type type, ConstructorInfo constructor) {
|
||||||
final typeName = type.toString();
|
|
||||||
final typeObj = type as dynamic;
|
final typeObj = type as dynamic;
|
||||||
|
|
||||||
// Create a factory function that takes a list of positional args and optional named args
|
// Create a factory function that takes a list of positional args and optional named args
|
||||||
return (List positionalArgs, [Map<Symbol, dynamic>? namedArgs]) {
|
return (List positionalArgs, [Map<Symbol, dynamic>? namedArgs]) {
|
||||||
switch (typeName) {
|
try {
|
||||||
case 'TestClass':
|
|
||||||
if (constructor.name.isEmpty) {
|
if (constructor.name.isEmpty) {
|
||||||
final name = positionalArgs[0] as String;
|
// For default constructor
|
||||||
final id = namedArgs?[#id] as int;
|
return Function.apply(typeObj, positionalArgs, namedArgs);
|
||||||
final tags = namedArgs?[#tags] as List<String>? ?? const [];
|
} else {
|
||||||
return Function.apply(typeObj, [name], {#id: id, #tags: tags});
|
// For named constructor
|
||||||
} else if (constructor.name == 'guest') {
|
final namedConstructor = typeObj[constructor.name];
|
||||||
return Function.apply(typeObj.guest, [], {});
|
return Function.apply(namedConstructor, positionalArgs, namedArgs);
|
||||||
}
|
}
|
||||||
break;
|
} catch (e) {
|
||||||
|
print('Warning: Failed to create instance: $e');
|
||||||
case 'GenericTestClass':
|
return null;
|
||||||
final value = positionalArgs[0];
|
|
||||||
final items = namedArgs?[#items] ?? const [];
|
|
||||||
return Function.apply(typeObj, [value], {#items: items});
|
|
||||||
|
|
||||||
case 'ParentTestClass':
|
|
||||||
final name = positionalArgs[0] as String;
|
|
||||||
return Function.apply(typeObj, [name], {});
|
|
||||||
|
|
||||||
case 'ChildTestClass':
|
|
||||||
final name = positionalArgs[0] as String;
|
|
||||||
final age = positionalArgs[1] as int;
|
|
||||||
return Function.apply(typeObj, [name, age], {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw UnsupportedError('Cannot create instance of $typeName');
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,20 +61,15 @@ class IsolateMirrorImpl implements IsolateMirror {
|
||||||
if (identical(this, other)) return true;
|
if (identical(this, other)) return true;
|
||||||
if (other is! IsolateMirrorImpl) return false;
|
if (other is! IsolateMirrorImpl) return false;
|
||||||
|
|
||||||
return _debugName == other._debugName &&
|
// Only compare debug name and isCurrent flag
|
||||||
_isCurrent == other._isCurrent &&
|
// Two mirrors pointing to the same isolate should be equal
|
||||||
_rootLibrary == other._rootLibrary &&
|
return _debugName == other._debugName && _isCurrent == other._isCurrent;
|
||||||
_underlyingIsolate == other._underlyingIsolate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode {
|
int get hashCode {
|
||||||
return Object.hash(
|
// Hash code should be consistent with equals
|
||||||
_debugName,
|
return Object.hash(_debugName, _isCurrent);
|
||||||
_isCurrent,
|
|
||||||
_rootLibrary,
|
|
||||||
_underlyingIsolate,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in a new issue