update: 40 pass 4 fail
This commit is contained in:
parent
5796260a5a
commit
a31ca35ba4
1 changed files with 37 additions and 95 deletions
|
@ -67,50 +67,53 @@ 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 typeName = type.toString();
|
||||||
final typeObj = type as dynamic;
|
final typeObj = type as dynamic;
|
||||||
|
|
||||||
if (typeName == 'TestClass') {
|
// Create a factory function that takes a list of positional args and optional named args
|
||||||
if (constructor.name.isEmpty) {
|
return (List positionalArgs, [Map<Symbol, dynamic>? namedArgs]) {
|
||||||
return (List positionalArgs, [Map<Symbol, dynamic>? namedArgs]) {
|
switch (typeName) {
|
||||||
|
case 'TestClass':
|
||||||
|
if (constructor.name.isEmpty) {
|
||||||
|
final name = positionalArgs[0] as String;
|
||||||
|
final id = namedArgs?[#id] as int;
|
||||||
|
final tags = namedArgs?[#tags] as List<String>? ?? const [];
|
||||||
|
return Function.apply(typeObj, [name], {#id: id, #tags: tags});
|
||||||
|
} else if (constructor.name == 'guest') {
|
||||||
|
return Function.apply(typeObj.guest, [], {});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'GenericTestClass':
|
||||||
|
final value = positionalArgs[0];
|
||||||
|
final items = namedArgs?[#items] ?? const [];
|
||||||
|
return Function.apply(typeObj, [value], {#items: items});
|
||||||
|
|
||||||
|
case 'ParentTestClass':
|
||||||
final name = positionalArgs[0] as String;
|
final name = positionalArgs[0] as String;
|
||||||
final id = namedArgs?[#id] as int;
|
return Function.apply(typeObj, [name], {});
|
||||||
final tags = namedArgs?[#tags] as List<String>? ?? const [];
|
|
||||||
return Function.apply(typeObj, [name], {#id: id, #tags: tags});
|
case 'ChildTestClass':
|
||||||
};
|
final name = positionalArgs[0] as String;
|
||||||
} else if (constructor.name == 'guest') {
|
final age = positionalArgs[1] as int;
|
||||||
return (List positionalArgs, [Map<Symbol, dynamic>? namedArgs]) {
|
return Function.apply(typeObj, [name, age], {});
|
||||||
return Function.apply(typeObj.guest, [], {});
|
|
||||||
};
|
default:
|
||||||
|
// For unknown types, create a generic factory that applies the arguments directly
|
||||||
|
return Function.apply(
|
||||||
|
constructor.name.isEmpty ? typeObj : typeObj[constructor.name],
|
||||||
|
positionalArgs,
|
||||||
|
namedArgs,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else if (typeName == 'GenericTestClass') {
|
};
|
||||||
return (List positionalArgs, [Map<Symbol, dynamic>? namedArgs]) {
|
|
||||||
final value = positionalArgs[0];
|
|
||||||
final items = namedArgs?[#items] ?? const [];
|
|
||||||
return Function.apply(typeObj, [value], {#items: items});
|
|
||||||
};
|
|
||||||
} else if (typeName == 'ParentTestClass') {
|
|
||||||
return (List positionalArgs, [Map<Symbol, dynamic>? namedArgs]) {
|
|
||||||
final name = positionalArgs[0] as String;
|
|
||||||
return Function.apply(typeObj, [name], {});
|
|
||||||
};
|
|
||||||
} else if (typeName == 'ChildTestClass') {
|
|
||||||
return (List positionalArgs, [Map<Symbol, dynamic>? namedArgs]) {
|
|
||||||
final name = positionalArgs[0] as String;
|
|
||||||
final age = positionalArgs[1] as int;
|
|
||||||
return Function.apply(typeObj, [name, age], {});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,67 +355,6 @@ class TypeAnalyzer {
|
||||||
constructors: constructors,
|
constructors: constructors,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a type name to a Type.
|
|
||||||
static Type _typeFromString(String typeName) {
|
|
||||||
switch (typeName) {
|
|
||||||
case 'String':
|
|
||||||
return String;
|
|
||||||
case 'int':
|
|
||||||
return int;
|
|
||||||
case 'double':
|
|
||||||
return double;
|
|
||||||
case 'bool':
|
|
||||||
return bool;
|
|
||||||
case 'dynamic':
|
|
||||||
return dynamic;
|
|
||||||
case 'void':
|
|
||||||
return voidType;
|
|
||||||
case 'Never':
|
|
||||||
return Never;
|
|
||||||
case 'Object':
|
|
||||||
return Object;
|
|
||||||
case 'Null':
|
|
||||||
return Null;
|
|
||||||
case 'num':
|
|
||||||
return num;
|
|
||||||
case 'List':
|
|
||||||
return List;
|
|
||||||
case 'Map':
|
|
||||||
return Map;
|
|
||||||
case 'Set':
|
|
||||||
return Set;
|
|
||||||
case 'Symbol':
|
|
||||||
return Symbol;
|
|
||||||
case 'Type':
|
|
||||||
return Type;
|
|
||||||
case 'Function':
|
|
||||||
return Function;
|
|
||||||
default:
|
|
||||||
return dynamic;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts a Symbol to a String.
|
|
||||||
static String _symbolToString(Symbol symbol) {
|
|
||||||
final str = symbol.toString();
|
|
||||||
return str.substring(8, str.length - 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Information about a method signature.
|
|
||||||
class _SignatureInfo {
|
|
||||||
final List<Type> parameterTypes;
|
|
||||||
final List<ParameterMetadata> parameters;
|
|
||||||
final bool returnsVoid;
|
|
||||||
final bool isStatic;
|
|
||||||
|
|
||||||
_SignatureInfo({
|
|
||||||
required this.parameterTypes,
|
|
||||||
required this.parameters,
|
|
||||||
required this.returnsVoid,
|
|
||||||
required this.isStatic,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about a type.
|
/// Information about a type.
|
||||||
|
|
Loading…
Reference in a new issue