diff --git a/CHANGELOG.md b/CHANGELOG.md index a98cf66..039bbeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +## 1.2.18 + +- `Reflection`: + - Fix `castMap`: + - Added `castMapKeys` and `castMapValues`. + - Added getters: `asTypeReflection`, `typeInfo`, `listType`, `mapKeyType` and `mapValueType`. +- `JsonCodec`: + - Added field `mapCaster`. +- `_JsonDecoder`: + - Now supports `Map` casting when decoding an entity field. +- Added `castMapType`. +- `ReflectionBuilder`: + - Optimize and reduce generated code. +- build: ^2.3.1 +- analyzer: ^4.7.0 +- dart_style: ^2.2.4 +- mime: ^1.0.3 +- pub_semver: ^2.1.3 +- path: ^1.8.3 +- build_runner: ^2.3.3 +- lints: ^2.0.1 +- test: ^1.22.1 +- coverage: ^1.6.1 + ## 1.2.17 - `FunctionReflection.parametersNamesWhere`: diff --git a/README.md b/README.md index 181932e..1f40281 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![pub package](https://img.shields.io/pub/v/reflection_factory.svg?logo=dart&logoColor=00b9fc)](https://pub.dev/packages/reflection_factory) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Codecov](https://img.shields.io/codecov/c/github/gmpassos/reflection_factory)](https://app.codecov.io/gh/gmpassos/reflection_factory) -[![CI](https://img.shields.io/github/workflow/status/gmpassos/reflection_factory/Dart%20CI/master?logo=github-actions&logoColor=white)](https://github.com/gmpassos/reflection_factory/actions) +[![Dart CI](https://github.com/gmpassos/reflection_factory/actions/workflows/dart.yml/badge.svg?branch=master)](https://github.com/gmpassos/reflection_factory/actions/workflows/dart.yml) [![GitHub Tag](https://img.shields.io/github/v/tag/gmpassos/reflection_factory?logo=git&logoColor=white)](https://github.com/gmpassos/reflection_factory/releases) [![New Commits](https://img.shields.io/github/commits-since/gmpassos/reflection_factory/latest?logo=git&logoColor=white)](https://github.com/gmpassos/reflection_factory/network) [![Last Commits](https://img.shields.io/github/last-commit/gmpassos/reflection_factory?logo=git&logoColor=white)](https://github.com/gmpassos/reflection_factory/commits/master) diff --git a/example/reflection_factory_bridge_example.reflection.g.dart b/example/reflection_factory_bridge_example.reflection.g.dart index fa72569..f0ca5ae 100644 --- a/example/reflection_factory_bridge_example.reflection.g.dart +++ b/example/reflection_factory_bridge_example.reflection.g.dart @@ -1,16 +1,29 @@ // // GENERATED CODE - DO NOT MODIFY BY HAND! -// BUILDER: reflection_factory/1.2.17 +// BUILDER: reflection_factory/1.2.18 // BUILD COMMAND: dart run build_runner build // // coverage:ignore-file +// ignore_for_file: unused_element // ignore_for_file: unnecessary_const // ignore_for_file: unnecessary_cast // ignore_for_file: unnecessary_type_check part of 'reflection_factory_bridge_example.dart'; +typedef __TR = TypeReflection; +typedef __TI = TypeInfo; +typedef __PR = ParameterReflection; + +mixin __ReflectionMixin { + static final Version _version = Version.parse('1.2.18'); + + Version get reflectionFactoryVersion => _version; + + List siblingsReflection() => _siblingsReflection(); +} + // ignore: non_constant_identifier_names User User$fromJson(Map map) => User$reflection.staticInstance.fromJson(map); @@ -18,7 +31,7 @@ User User$fromJson(Map map) => User User$fromJsonEncoded(String jsonEncoded) => User$reflection.staticInstance.fromJsonEncoded(jsonEncoded); -class User$reflection extends ClassReflection { +class User$reflection extends ClassReflection with __ReflectionMixin { User$reflection([User? object]) : super(User, 'User', object); static bool _registered = false; @@ -34,9 +47,6 @@ class User$reflection extends ClassReflection { @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override User$reflection withObject([User? obj]) => User$reflection(obj); @@ -86,11 +96,9 @@ class User$reflection extends ClassReflection { User, '', () => (String? email, String pass) => User(email, pass), - const [ - ParameterReflection( - TypeReflection.tString, 'email', true, true, null, null), - ParameterReflection( - TypeReflection.tString, 'pass', false, true, null, null) + const <__PR>[ + __PR(__TR.tString, 'email', true, true), + __PR(__TR.tString, 'pass', false, true) ], null, null, @@ -106,13 +114,6 @@ class User$reflection extends ClassReflection { @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -136,7 +137,7 @@ class User$reflection extends ClassReflection { return FieldReflection( this, User, - TypeReflection.tString, + __TR.tString, 'email', true, (o) => () => o!.email as T, @@ -144,13 +145,12 @@ class User$reflection extends ClassReflection { obj, false, false, - null, ); case 'pass': return FieldReflection( this, User, - TypeReflection.tString, + __TR.tString, 'pass', false, (o) => () => o!.pass as T, @@ -158,13 +158,12 @@ class User$reflection extends ClassReflection { obj, false, false, - null, ); case 'hasemail': return FieldReflection( this, User, - TypeReflection.tBool, + __TR.tBool, 'hasEmail', false, (o) => () => o!.hasEmail as T, @@ -172,7 +171,6 @@ class User$reflection extends ClassReflection { obj, false, false, - null, ); default: return null; @@ -202,15 +200,12 @@ class User$reflection extends ClassReflection { this, User, 'checkPassword', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.checkPassword, obj, false, - const [ - ParameterReflection( - TypeReflection.tString, 'pass', false, true, null, null) - ], + const <__PR>[__PR(__TR.tString, 'pass', false, true)], null, null, null); diff --git a/example/reflection_factory_example.reflection.g.dart b/example/reflection_factory_example.reflection.g.dart index ae9bc82..4a456d3 100644 --- a/example/reflection_factory_example.reflection.g.dart +++ b/example/reflection_factory_example.reflection.g.dart @@ -1,16 +1,29 @@ // // GENERATED CODE - DO NOT MODIFY BY HAND! -// BUILDER: reflection_factory/1.2.17 +// BUILDER: reflection_factory/1.2.18 // BUILD COMMAND: dart run build_runner build // // coverage:ignore-file +// ignore_for_file: unused_element // ignore_for_file: unnecessary_const // ignore_for_file: unnecessary_cast // ignore_for_file: unnecessary_type_check part of 'reflection_factory_example.dart'; +typedef __TR = TypeReflection; +typedef __TI = TypeInfo; +typedef __PR = ParameterReflection; + +mixin __ReflectionMixin { + static final Version _version = Version.parse('1.2.18'); + + Version get reflectionFactoryVersion => _version; + + List siblingsReflection() => _siblingsReflection(); +} + // ignore: non_constant_identifier_names User User$fromJson(Map map) => User$reflection.staticInstance.fromJson(map); @@ -18,7 +31,7 @@ User User$fromJson(Map map) => User User$fromJsonEncoded(String jsonEncoded) => User$reflection.staticInstance.fromJsonEncoded(jsonEncoded); -class User$reflection extends ClassReflection { +class User$reflection extends ClassReflection with __ReflectionMixin { User$reflection([User? object]) : super(User, 'User', object); static bool _registered = false; @@ -34,9 +47,6 @@ class User$reflection extends ClassReflection { @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override User$reflection withObject([User? obj]) => User$reflection(obj); @@ -86,11 +96,9 @@ class User$reflection extends ClassReflection { User, '', () => (String? email, String pass) => User(email, pass), - const [ - ParameterReflection( - TypeReflection.tString, 'email', true, true, null, null), - ParameterReflection( - TypeReflection.tString, 'pass', false, true, null, null) + const <__PR>[ + __PR(__TR.tString, 'email', true, true), + __PR(__TR.tString, 'pass', false, true) ], null, null, @@ -106,13 +114,6 @@ class User$reflection extends ClassReflection { @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -136,7 +137,7 @@ class User$reflection extends ClassReflection { return FieldReflection( this, User, - TypeReflection.tString, + __TR.tString, 'email', true, (o) => () => o!.email as T, @@ -144,13 +145,12 @@ class User$reflection extends ClassReflection { obj, false, false, - null, ); case 'pass': return FieldReflection( this, User, - TypeReflection.tString, + __TR.tString, 'pass', false, (o) => () => o!.pass as T, @@ -158,13 +158,12 @@ class User$reflection extends ClassReflection { obj, false, false, - null, ); case 'hasemail': return FieldReflection( this, User, - TypeReflection.tBool, + __TR.tBool, 'hasEmail', false, (o) => () => o!.hasEmail as T, @@ -172,7 +171,6 @@ class User$reflection extends ClassReflection { obj, false, false, - null, ); default: return null; @@ -202,15 +200,12 @@ class User$reflection extends ClassReflection { this, User, 'checkPassword', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.checkPassword, obj, false, - const [ - ParameterReflection( - TypeReflection.tString, 'pass', false, true, null, null) - ], + const <__PR>[__PR(__TR.tString, 'pass', false, true)], null, null, null); diff --git a/lib/src/analyzer/library.dart b/lib/src/analyzer/library.dart index 237bbb5..64f0735 100644 --- a/lib/src/analyzer/library.dart +++ b/lib/src/analyzer/library.dart @@ -3,6 +3,7 @@ // Original source: https://github.com/dart-lang/source_gen import 'package:analyzer/dart/element/element.dart'; +import 'package:collection/collection.dart'; import 'reader.dart'; import 'type_checker.dart'; @@ -40,6 +41,20 @@ class LibraryReader { } } + /// All of the elements names in this library + /// (classes, enums, mixins, functions, extensions, typeAliases, topLevelVariables). + Iterable get elementsNames => element.units + .expand((CompilationUnitElement cu) => [ + ...cu.classes.map((e) => e.name), + ...cu.enums2.map((e) => e.name), + ...cu.mixins2.map((e) => e.name), + ...cu.functions.map((e) => e.name), + ...cu.extensions.map((e) => e.name), + ...cu.typeAliases.map((e) => e.name), + ...cu.topLevelVariables.map((e) => e.name), + ]) + .whereNotNull(); + /// All of the elements representing classes in this library. Iterable get classes => element.units.expand((CompilationUnitElement cu) => cu.classes); diff --git a/lib/src/reflection_factory_base.dart b/lib/src/reflection_factory_base.dart index a03f95a..f4d0bb6 100644 --- a/lib/src/reflection_factory_base.dart +++ b/lib/src/reflection_factory_base.dart @@ -20,7 +20,7 @@ import 'reflection_factory_type.dart'; /// Class with all registered reflections ([ClassReflection]). class ReflectionFactory { // ignore: constant_identifier_names - static const String VERSION = '1.2.17'; + static const String VERSION = '1.2.18'; static final ReflectionFactory _instance = ReflectionFactory._(); @@ -156,7 +156,16 @@ abstract class Reflection { /// The reflection level (complexity). int get reflectionLevel; - /// Cast [list] to [classType] if [type] == [classType] or return `null`. + TypeReflection? _typeReflection; + + /// Returns [reflectedType] as a [TypeReflection]. + TypeReflection get asTypeReflection => + _typeReflection ??= TypeReflection(reflectedType); + + /// Returns [reflectedType] as a [TypeInfo]. + TypeInfo get typeInfo => asTypeReflection.typeInfo; + + /// Cast [list] to [reflectedType] if [type] == [reflectedType] or return `null`. /// - If [nullable] is `true` casts to a [List] of nullable values. List? castList(List list, Type type, {bool nullable = false}) { if (type == reflectedType) { @@ -191,7 +200,7 @@ abstract class Reflection { return l; } - /// Cast [set] to [classType] if [type] == [classType] or return `null`. + /// Cast [set] to [reflectedType] if [type] == [reflectedType] or return `null`. /// - If [nullable] is `true` casts to a [Set] of nullable values. Set? castSet(Set set, Type type, {bool nullable = false}) { if (type == reflectedType) { @@ -226,7 +235,7 @@ abstract class Reflection { return l; } - /// Cast [itr] to [classType] if [type] == [classType] or return `null`. + /// Cast [itr] to [reflectedType] if [type] == [reflectedType] or return `null`. /// - If [nullable] is `true` casts to an [Iterable] of nullable values. Iterable? castIterable(Iterable itr, Type type, {bool nullable = false}) { if (type == reflectedType) { @@ -260,8 +269,9 @@ abstract class Reflection { return l; } - /// Cast [map] values to [classType] if [type] == [classType] or return `null`. - /// - If [nullable] is `true` casts to a [Map] of nullable values. + /// Cast [map] keys & values to [reflectedType] if [type] == [reflectedType] or return `null`. + /// - If [nullable] is `true` casts to a [Map] of nullable key & values. + /// - See [castMapKeys] and [castMapValues]. Map? castMap(Map map, TypeInfo typeInfo, {bool nullable = false}) { if (!typeInfo.isMap) { return map; @@ -270,6 +280,111 @@ abstract class Reflection { var keyType = typeInfo.argumentType(0) ?? TypeInfo.tDynamic; var valueType = typeInfo.argumentType(1) ?? TypeInfo.tDynamic; + if (keyType.type == reflectedType && valueType.type == reflectedType) { + var m = nullable + ? map.map((key, value) => MapEntry(key, value)) + : map.map((key, value) => MapEntry(key, value)); + + return m; + } else if (keyType.type == reflectedType) { + Map? callVal() => map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + Map? callValNullable() => map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + + var m = nullable + ? valueType.callCasted(callValNullable) + : valueType.callCasted(callVal); + + return m; + } else if (valueType.type == reflectedType) { + Map? callKey() => map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + Map? callKeyNullable() => map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + + var m = nullable + ? keyType.callCasted(callKeyNullable) + : keyType.callCasted(callKey); + + return m; + } else { + Map? callKey() => valueType.callCasted(() { + return map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + }); + + Map? callKeyNullable() => valueType.callCasted(() { + return map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + }); + + var m = nullable + ? keyType.callCasted(callKeyNullable) + : keyType.callCasted(callKey); + return m; + } + } + + /// Cast [map] keys to [reflectedType] if [type] == [reflectedType] or return `null`. + /// - If [nullable] is `true` casts to a [Map] of nullable keys. + Map? castMapKeys(Map map, TypeInfo typeInfo, {bool nullable = false}) { + if (!typeInfo.isMap) { + return map; + } + + var keyType = typeInfo.argumentType(0) ?? TypeInfo.tDynamic; + var valueType = typeInfo.argumentType(1) ?? TypeInfo.tDynamic; + + if (keyType.type == reflectedType) { + Map? callVal() => map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + Map? callValNullable() => map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + + var m = nullable + ? valueType.callCasted(callValNullable) + : valueType.callCasted(callVal); + + return m; + } else { + Map? callKey() => valueType.callCasted(() { + return map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + }); + + Map? callKeyNullable() => valueType.callCasted(() { + return map is Map + ? map + : map.map((key, value) => MapEntry(key, value)); + }); + + var m = nullable + ? keyType.callCasted(callKeyNullable) + : keyType.callCasted(callKey); + return m; + } + } + + /// Cast [map] values to [reflectedType] if [type] == [reflectedType] or return `null`. + /// - If [nullable] is `true` casts to a [Map] of nullable values. + Map? castMapValues(Map map, TypeInfo typeInfo, {bool nullable = false}) { + if (!typeInfo.isMap) { + return map; + } + + var keyType = typeInfo.argumentType(0) ?? TypeInfo.tDynamic; + var valueType = typeInfo.argumentType(1) ?? TypeInfo.tDynamic; + if (valueType.type == reflectedType) { Map? callKey() => map is Map ? map @@ -364,7 +479,7 @@ abstract class Reflection { /// Base for Enum reflection. abstract class EnumReflection extends Reflection - implements Comparable> { + implements Comparable { /// Then reflected enum [Type]. final Type enumType; @@ -426,7 +541,8 @@ abstract class EnumReflection extends Reflection } /// Returns a [List] of siblings [ClassReflection] (declared in the same code unit). - List siblingsEnumReflection(); + List siblingsEnumReflection() => + siblingsReflection().whereType().toList(); /// Returns a [siblingsEnumReflection] for [type], [obj] or [T]. EnumReflection? siblingEnumReflectionFor({T? obj, Type? type}) { @@ -591,7 +707,7 @@ abstract class EnumReflection extends Reflection } @override - int compareTo(EnumReflection other) => + int compareTo(EnumReflection other) => reflectionLevel.compareTo(other.reflectionLevel); @override @@ -608,7 +724,7 @@ typedef OnConstructorInvocationError = void Function( /// Base for Class reflection. abstract class ClassReflection extends Reflection - implements Comparable> { + implements Comparable { /// The reflected class [Type]. final Type classType; @@ -664,8 +780,8 @@ abstract class ClassReflection extends Reflection int get reflectionLevel => fieldsNames.length + staticFieldsNames.length + - methodsNames.length + - staticMethodsNames.length; + (methodsNames.length * 2) + + (staticMethodsNames.length * 2); /// Calls [function] with correct casting for [ClassReflection]. @override @@ -674,7 +790,8 @@ abstract class ClassReflection extends Reflection } /// Returns a [List] of siblings [ClassReflection] (declared in the same code unit). - List siblingsClassReflection(); + List siblingsClassReflection() => + siblingsReflection().whereType().toList(); /// Returns a [siblingsClassReflection] for [type], [obj] or [T]. ClassReflection? siblingClassReflectionFor({T? obj, Type? type}) { @@ -1643,7 +1760,7 @@ abstract class ClassReflection extends Reflection } @override - int compareTo(ClassReflection other) => + int compareTo(ClassReflection other) => reflectionLevel.compareTo(other.reflectionLevel); @override @@ -1805,7 +1922,7 @@ class ParameterReflection { : _annotationsEmpty; const ParameterReflection(this.type, this.name, this.nullable, this.required, - this.defaultValue, this._annotations); + [this.defaultValue, this._annotations]); /// Returns `true` if [defaultValue] is NOT `null`. bool get hasDefaultValue => defaultValue != null; @@ -2288,7 +2405,24 @@ class TypeReflection { isIterableType && hasArguments && arguments.first.isEntityType; /// The [TypeReflection] of the [List] elements type. - TypeReflection? get listEntityType => isIterableType ? arguments.first : null; + TypeReflection? get listEntityType => + isIterableEntity ? arguments.first : null; + + /// The [TypeReflection] of the [List] elements type. + TypeReflection? get listType => isIterableType ? arguments.firstOrNull : null; + + /// The [TypeReflection] of the [Map] key type. + TypeReflection? get mapKeyType => isMapType ? arguments.firstOrNull : null; + + /// The [TypeReflection] of the [Map] value type. + TypeReflection? get mapValueType { + if (isMapType) { + var args = arguments; + return args.length > 1 ? args[1] : null; + } else { + return null; + } + } @override bool operator ==(Object other) => @@ -2385,18 +2519,18 @@ class FieldReflection extends ElementReflection jsonAnnotations.whereType().toList(); FieldReflection( - ClassReflection classReflection, - Type declaringType, - this.type, - this.name, - this.nullable, - this.getterAccessor, - this.setterAccessor, - this.object, - bool isStatic, - this.isFinal, - List? annotations, - ) : _annotations = annotations == null || annotations.isEmpty + ClassReflection classReflection, + Type declaringType, + this.type, + this.name, + this.nullable, + this.getterAccessor, + this.setterAccessor, + this.object, + bool isStatic, + this.isFinal, + [List? annotations]) + : _annotations = annotations == null || annotations.isEmpty ? _annotationsEmpty : List.unmodifiable(annotations), super(classReflection, declaringType, isStatic); diff --git a/lib/src/reflection_factory_builder.dart b/lib/src/reflection_factory_builder.dart index 65b73e5..4237720 100644 --- a/lib/src/reflection_factory_builder.dart +++ b/lib/src/reflection_factory_builder.dart @@ -72,7 +72,10 @@ class ReflectionBuilder implements Builder { "Can't generate multiple `reflection` files. Multiple reflection parts directives: $siblingParts AND $subParts"); } - var codeTable = await _buildCodeTable(buildStep, libraryReader); + var typeAliasTable = _TypeAliasTable.fromLibraryReader(libraryReader); + + var codeTable = + await _buildCodeTable(buildStep, libraryReader, typeAliasTable); if (codeTable.isEmpty) { return; @@ -100,6 +103,7 @@ class ReflectionBuilder implements Builder { var genId = isSiblingPart ? genSiblingId : genSubId; + var reflectionMixin = _buildReflectionMixin(codeTable, typeAliasTable); var siblingsClassReflection = _buildSiblingsClassReflection(codeTable); var fullCode = StringBuffer(); @@ -112,6 +116,7 @@ class ReflectionBuilder implements Builder { fullCode.write('// \n\n'); fullCode.write('// coverage:ignore-file\n'); + fullCode.write('// ignore_for_file: unused_element\n'); fullCode.write('// ignore_for_file: unnecessary_const\n'); fullCode.write('// ignore_for_file: unnecessary_cast\n'); fullCode.write('// ignore_for_file: unnecessary_type_check\n\n'); @@ -122,6 +127,9 @@ class ReflectionBuilder implements Builder { fullCode.write("part of '../$inputFile';\n\n"); } + fullCode.write(typeAliasTable.code); + fullCode.write(reflectionMixin); + var codeKeys = codeTable.allKeys.toList(); _sortCodeKeys(codeKeys); @@ -194,8 +202,8 @@ class ReflectionBuilder implements Builder { return [outputFileSibling, outputFileSub]; } - Future<_CodeTable> _buildCodeTable( - BuildStep buildStep, LibraryReader libraryReader) async { + Future<_CodeTable> _buildCodeTable(BuildStep buildStep, + LibraryReader libraryReader, _TypeAliasTable typeAliasTable) async { var codeTable = _CodeTable(); var annotatedReflectionBridge = @@ -203,7 +211,8 @@ class ReflectionBuilder implements Builder { for (var annotated in annotatedReflectionBridge) { if (annotated.element.kind == ElementKind.CLASS) { - var codes = await _reflectionBridge(buildStep, annotated); + var codes = + await _reflectionBridge(buildStep, annotated, typeAliasTable); codeTable.addAllClasses(codes); } } @@ -221,23 +230,15 @@ class ReflectionBuilder implements Builder { if (annotated.element.kind == ElementKind.CLASS) { var classElement = annotated.element as ClassElement; - var codes = await _enableReflectionClass( - buildStep, - classElement, - reflectionClassName, - reflectionExtensionName, - ); + var codes = await _enableReflectionClass(buildStep, classElement, + reflectionClassName, reflectionExtensionName, typeAliasTable); codeTable.addAllClasses(codes); } else if (annotated.element.kind == ElementKind.ENUM) { var enumElement = annotated.element; - var codes = await _enableReflectionEnum( - buildStep, - enumElement, - reflectionClassName, - reflectionExtensionName, - ); + var codes = await _enableReflectionEnum(buildStep, enumElement, + reflectionClassName, reflectionExtensionName, typeAliasTable); codeTable.addAllClasses(codes); } @@ -248,7 +249,7 @@ class ReflectionBuilder implements Builder { for (var annotated in annotatedClassProxy) { if (annotated.element.kind == ElementKind.CLASS) { - var codes = await _classProxy(buildStep, annotated); + var codes = await _classProxy(buildStep, annotated, typeAliasTable); codeTable.addProxies(codes); } } @@ -273,8 +274,8 @@ class ReflectionBuilder implements Builder { return idx >= 0 ? s.substring(idx + 1) : s; } - Future> _classProxy( - BuildStep buildStep, AnnotatedElement annotated) async { + Future> _classProxy(BuildStep buildStep, + AnnotatedElement annotated, _TypeAliasTable typeAliasTable) async { var annotation = annotated.annotation; var annotatedClass = annotated.element as ClassElement; @@ -316,6 +317,7 @@ class ReflectionBuilder implements Builder { var classElement = candidateClasses.first; var classTree = _ClassTree( + typeAliasTable, classElement, '?%', '?%', @@ -390,8 +392,8 @@ class ReflectionBuilder implements Builder { return candidateClasses; } - Future> _reflectionBridge( - BuildStep buildStep, AnnotatedElement annotated) async { + Future> _reflectionBridge(BuildStep buildStep, + AnnotatedElement annotated, _TypeAliasTable typeAliasTable) async { var annotation = annotated.annotation; var annotatedClass = annotated.element as ClassElement; @@ -432,6 +434,7 @@ class ReflectionBuilder implements Builder { var reflectionExtensionName = reflectionExtensionNames[classType] ?? ''; var classTree = _ClassTree( + typeAliasTable, classElement, reflectionClassName, reflectionExtensionName, @@ -446,8 +449,8 @@ class ReflectionBuilder implements Builder { codeTable.putIfAbsent(classTree.classGlobalFunction('_'), () => classTree.buildClassGlobalFunctions()); - codeTable.putIfAbsent( - classTree.reflectionClass, () => classTree.buildReflectionClass()); + codeTable.putIfAbsent(classTree.reflectionClass, + () => classTree.buildReflectionClass(typeAliasTable)); codeTable.putIfAbsent(classTree.reflectionExtension, () => classTree.buildReflectionExtension()); } @@ -505,7 +508,8 @@ class ReflectionBuilder implements Builder { BuildStep buildStep, Element enumElement, String reflectionClassName, - String reflectionExtensionName) async { + String reflectionExtensionName, + _TypeAliasTable typeAliasTable) async { var enumLibrary = await _getElementLibrary(buildStep, enumElement); var enumTree = _EnumTree( @@ -521,7 +525,7 @@ class ReflectionBuilder implements Builder { } var enumGlobalFunctions = enumTree.buildEnumGlobalFunctions(); - var reflectionClassCode = enumTree.buildReflectionEnum(); + var reflectionClassCode = enumTree.buildReflectionEnum(typeAliasTable); var reflectionExtensionCode = enumTree.buildReflectionExtension(); return { @@ -535,10 +539,12 @@ class ReflectionBuilder implements Builder { BuildStep buildStep, ClassElement classElement, String reflectionClassName, - String reflectionExtensionName) async { + String reflectionExtensionName, + _TypeAliasTable typeAliasTable) async { var classLibrary = await _getElementLibrary(buildStep, classElement); var classTree = _ClassTree( + typeAliasTable, classElement, reflectionClassName, reflectionExtensionName, @@ -552,7 +558,7 @@ class ReflectionBuilder implements Builder { } var classGlobalFunctions = classTree.buildClassGlobalFunctions(); - var reflectionClassCode = classTree.buildReflectionClass(); + var reflectionClassCode = classTree.buildReflectionClass(typeAliasTable); var reflectionExtensionCode = classTree.buildReflectionExtension(); return { @@ -570,6 +576,28 @@ class ReflectionBuilder implements Builder { return library; } + String _buildReflectionMixin( + _CodeTable codeTable, _TypeAliasTable typeAliasTable) { + if (codeTable.reflectionClassesIsEmpty) return ''; + + var str = StringBuffer(); + + str.write('mixin ${typeAliasTable.reflectionMixinName} {\n'); + + str.write( + " static final Version _version = Version.parse('${ReflectionFactory.VERSION}');\n\n"); + + str.write(" Version get reflectionFactoryVersion => _version;\n\n"); + + str.write( + ' List siblingsReflection() => _siblingsReflection();\n\n'); + + str.write('}\n\n'); + + var code = str.toString(); + return code; + } + String _buildSiblingsClassReflection(_CodeTable codeTable) { if (codeTable.reflectionClassesIsEmpty) return ''; @@ -676,6 +704,45 @@ extension IterableLibraryElementExtension on Iterable { }; } +class _TypeAliasTable { + late final String trName; + late final String tiName; + late final String prName; + late final String reflectionMixinName; + late final String code; + + factory _TypeAliasTable.fromLibraryReader(LibraryReader libraryReader) { + var privateNames = + libraryReader.elementsNames.where((e) => e.startsWith('_')).toList(); + return _TypeAliasTable(privateNames); + } + + _TypeAliasTable(List privateNames) { + trName = _buildAliasName('__TR', privateNames); + tiName = _buildAliasName('__TI', privateNames); + prName = _buildAliasName('__PR', privateNames); + reflectionMixinName = _buildAliasName('__ReflectionMixin', privateNames); + + var str = StringBuffer(); + + str.write('typedef $trName = TypeReflection;\n'); + str.write('typedef $tiName = TypeInfo;\n'); + str.write('typedef $prName = ParameterReflection;\n\n'); + + code = str.toString(); + } + + String _buildAliasName(String prefix, Iterable usedNames) { + if (!usedNames.contains(prefix)) return prefix; + + var i = 0; + while (true) { + var name = '$prefix$i'; + if (!usedNames.contains(name)) return name; + } + } +} + class _CodeTable { final Map _reflectionClasses = {}; final Map _reflectionProxies = {}; @@ -823,12 +890,13 @@ class _EnumTree extends RecursiveElementVisitor { return str.toString(); } - String buildReflectionEnum() { + String buildReflectionEnum(_TypeAliasTable typeAliasTable) { var str = StringBuffer(); var reflectionClass = this.reflectionClass; - str.write('class $reflectionClass extends EnumReflection<$enumName> {\n\n'); + str.write( + 'class $reflectionClass extends EnumReflection<$enumName> with ${typeAliasTable.reflectionMixinName} {\n\n'); str.write( ' $reflectionClass([$enumName? object]) : super($enumName, \'$enumName\', object);\n\n'); @@ -847,10 +915,6 @@ class _EnumTree extends RecursiveElementVisitor { str.write( " Version get languageVersion => Version.parse('$languageVersion');\n\n"); - str.write(' @override\n'); - str.write( - " Version get reflectionFactoryVersion => Version.parse('${ReflectionFactory.VERSION}');\n\n"); - str.write(' @override\n'); str.write( ' $reflectionClass withObject([$enumName? obj]) => $reflectionClass(obj);\n\n'); @@ -889,14 +953,6 @@ class _EnumTree extends RecursiveElementVisitor { ' List get classAnnotations => List.unmodifiable([]);\n\n'); } - str.write('\n @override\n'); - str.write( - ' List siblingsEnumReflection() => _siblingsReflection().whereType().toList();\n\n'); - - str.write('\n @override\n'); - str.write( - ' List siblingsReflection() => _siblingsReflection();\n\n'); - _buildField(str); str.write('}\n\n'); @@ -989,6 +1045,8 @@ class _EnumTree extends RecursiveElementVisitor { } class _ClassTree extends RecursiveElementVisitor { + final _TypeAliasTable typeAliasTable; + final ClassElement _classElement; final String reflectionClassName; @@ -1002,6 +1060,7 @@ class _ClassTree extends RecursiveElementVisitor { final String className; _ClassTree( + this.typeAliasTable, this._classElement, this.reflectionClassName, this.reflectionExtensionName, @@ -1260,13 +1319,13 @@ class _ClassTree extends RecursiveElementVisitor { return str.toString(); } - String buildReflectionClass() { + String buildReflectionClass(_TypeAliasTable typeAliasTable) { var str = StringBuffer(); var reflectionClass = this.reflectionClass; str.write( - 'class $reflectionClass extends ClassReflection<$className> {\n\n'); + 'class $reflectionClass extends ClassReflection<$className> with ${typeAliasTable.reflectionMixinName} {\n\n'); str.write( ' $reflectionClass([$className? object]) : super($className, \'$className\', object);\n\n'); @@ -1285,10 +1344,6 @@ class _ClassTree extends RecursiveElementVisitor { str.write( " Version get languageVersion => Version.parse('$languageVersion');\n\n"); - str.write(' @override\n'); - str.write( - " Version get reflectionFactoryVersion => Version.parse('${ReflectionFactory.VERSION}');\n\n"); - str.write(' @override\n'); str.write( ' $reflectionClass withObject([$className? obj]) => $reflectionClass(obj);\n\n'); @@ -1329,14 +1384,6 @@ class _ClassTree extends RecursiveElementVisitor { ' List get classAnnotations => List.unmodifiable([]);\n\n'); } - str.write('\n @override\n'); - str.write( - ' List siblingsClassReflection() => _siblingsReflection().whereType().toList();\n\n'); - - str.write('\n @override\n'); - str.write( - ' List siblingsReflection() => _siblingsReflection();\n\n'); - str.write('\n @override\n'); str.write( ' List get supperTypes => const [${supperTypes.map((e) => e.name).join(', ')}];\n\n'); @@ -1476,7 +1523,7 @@ class _ClassTree extends RecursiveElementVisitor { } var declaringType = field.declaringType!.typeNameResolvable; - var typeCode = field.typeAsCode; + var typeCode = field.typeAsCode(typeAliasTable); var fullType = field.typeNameAsNullableCode; var nullable = field.nullable ? 'true' : 'false'; var isFinal = field.isFinal ? 'true' : 'false'; @@ -1491,7 +1538,7 @@ class _ClassTree extends RecursiveElementVisitor { "$typeCode, '$name', $nullable, " "$getter , $setter , " "obj, false, $isFinal, " - "$annotations, " + "${annotations != 'null' ? '$annotations, ' : ''} " ")"; }); @@ -1516,7 +1563,7 @@ class _ClassTree extends RecursiveElementVisitor { } var declaringType = field.declaringType!.typeNameResolvable; - var typeCode = field.typeAsCode; + var typeCode = field.typeAsCode(typeAliasTable); var fullType = field.typeNameAsNullableCode; var nullable = field.nullable ? 'true' : 'false'; var isFinal = field.isFinal ? 'true' : 'false'; @@ -1639,7 +1686,7 @@ class _ClassTree extends RecursiveElementVisitor { Map _toMethodsEntries(Set elements) { return Map.fromEntries(elements.map((m) { - return MapEntry(m.name, _Method(m)); + return MapEntry(m.name, _Method(this, m)); })); } @@ -1848,7 +1895,8 @@ class _ClassTree extends RecursiveElementVisitor { str.write(' {\n'); - var returnTypeAsCode = proxyMethod.returnType.asTypeReflectionCode; + var returnTypeAsCode = + proxyMethod.returnType.asTypeReflectionCode(typeAliasTable); var call = StringBuffer(); @@ -2176,6 +2224,8 @@ class _Constructor extends _Element { _Constructor(this.classTree, this.constructorElement) : super(constructorElement); + _TypeAliasTable get typeAliasTable => classTree.typeAliasTable; + String get name => constructorElement.name; bool get returnNullable => constructorElement.returnType.isNullable; @@ -2186,7 +2236,7 @@ class _Constructor extends _Element { constructorElement.returnType.typeNameAsCode; String get returnTypeAsCode => - constructorElement.returnType.asTypeReflectionCode; + constructorElement.returnType.asTypeReflectionCode(typeAliasTable); List<_Parameter> get normalParameters => constructorElement.type.normalParameters; @@ -2198,15 +2248,16 @@ class _Constructor extends _Element { constructorElement.type.namedParameters; String get normalParametersAsCode => - _buildParameterReflectionList(normalParameters, + _buildParameterReflectionList(typeAliasTable, normalParameters, nullOnEmpty: true, required: true); String get optionalParametersAsCode => - _buildParameterReflectionList(optionalParameters, + _buildParameterReflectionList(typeAliasTable, optionalParameters, nullOnEmpty: true, required: false); String get namedParametersAsCode => - _buildNamedParameterReflectionMap(namedParameters, nullOnEmpty: true); + _buildNamedParameterReflectionMap(typeAliasTable, namedParameters, + nullOnEmpty: true); String get asCallerCode { var s = StringBuffer(); @@ -2329,9 +2380,12 @@ class _Constructor extends _Element { } class _Method extends _Element { + final _ClassTree classTree; final MethodElement methodElement; - _Method(this.methodElement) : super(methodElement); + _Method(this.classTree, this.methodElement) : super(methodElement); + + _TypeAliasTable get typeAliasTable => classTree.typeAliasTable; String get name => methodElement.name; @@ -2341,7 +2395,8 @@ class _Method extends _Element { String get returnTypeNameAsCode => methodElement.returnType.typeNameAsCode; - String get returnTypeAsCode => methodElement.returnType.asTypeReflectionCode; + String get returnTypeAsCode => + methodElement.returnType.asTypeReflectionCode(typeAliasTable); List<_Parameter> get normalParameters => methodElement.type.normalParameters; @@ -2356,15 +2411,16 @@ class _Method extends _Element { .isNotEmpty; String get normalParametersAsCode => - _buildParameterReflectionList(normalParameters, + _buildParameterReflectionList(typeAliasTable, normalParameters, nullOnEmpty: true, required: true); String get optionalParametersAsCode => - _buildParameterReflectionList(optionalParameters, + _buildParameterReflectionList(typeAliasTable, optionalParameters, nullOnEmpty: true, required: false); String get namedParametersAsCode => - _buildNamedParameterReflectionMap(namedParameters, nullOnEmpty: true); + _buildNamedParameterReflectionMap(typeAliasTable, namedParameters, + nullOnEmpty: true); @override String toString() { @@ -2401,7 +2457,8 @@ class _Field extends _Element { String get typeNameAsNullableCode => fieldElement.type.typeNameAsNullableCode; - String get typeAsCode => fieldElement.type.asTypeReflectionCode; + String typeAsCode(_TypeAliasTable typeAliasTable) => + fieldElement.type.asTypeReflectionCode(typeAliasTable); @override String toString() { @@ -2435,22 +2492,26 @@ extension _ListDartTypeExtension on List { List get typesNamesResolvable => map((a) => a.typeNameResolvable).toList(); - String get toListOfConstTypeCode { + String toListOfConstTypeCode(_TypeAliasTable typeAliasTable) { + final tr = typeAliasTable.trName; + final ti = typeAliasTable.tiName; + var listConstTypeReflection = - map((e) => e.asConstTypeReflectionCode).toList(growable: false); + map((e) => e.asConstTypeReflectionCode(typeAliasTable)) + .toList(growable: false); if (listConstTypeReflection.every((e) => e != null)) { - return '[${listConstTypeReflection.join(',')}]'; + return '<$tr>[${listConstTypeReflection.join(',')}]'; } - var listConstTypeInfo = - map((e) => e.asConstTypeInfoCode).toList(growable: false); + var listConstTypeInfo = map((e) => e.asConstTypeInfoCode(typeAliasTable)) + .toList(growable: false); if (listConstTypeInfo.every((e) => e != null)) { - return '[${listConstTypeInfo.join(',')}]'; + return '<$ti>[${listConstTypeInfo.join(',')}]'; } - var listTypeReflection = - map((e) => e.asTypeReflectionCode).toList(growable: false); - return '[${listTypeReflection.join(',')}]'; + var listTypeReflection = map((e) => e.asTypeReflectionCode(typeAliasTable)) + .toList(growable: false); + return '<$tr>[${listTypeReflection.join(',')}]'; } String get typesNames => @@ -2586,11 +2647,13 @@ extension _DartTypeExtension on DartType { ? '$typeNameAsCode?' : typeNameAsCode; - String? get asConstTypeReflectionCode { + String? asConstTypeReflectionCode(_TypeAliasTable typeAliasTable) { var self = this; + final tr = typeAliasTable.trName; + if (self is VoidType) { - return 'TypeReflection.tVoid'; + return '$tr.tVoid'; } if (self is FunctionType) { @@ -2598,7 +2661,7 @@ extension _DartTypeExtension on DartType { if (alias != null) { return null; } else { - return 'TypeReflection.tFunction'; + return '$tr.tFunction'; } } @@ -2611,7 +2674,7 @@ extension _DartTypeExtension on DartType { var constName = TypeReflection.getConstantName(name, typeArgs); if (constName != null) { - return 'TypeReflection.$constName'; + return '$tr.$constName'; } } @@ -2619,20 +2682,21 @@ extension _DartTypeExtension on DartType { } else { var constName = _getTypeReflectionConstantName(name); if (constName != null) { - return 'TypeReflection.$constName'; + return '$tr.$constName'; } else if (this is TypeParameterType) { - return 'TypeReflection.tDynamic'; + return '$tr.tDynamic'; } return null; } } - String get asTypeReflectionCode { + String asTypeReflectionCode(_TypeAliasTable typeAliasTable) { var self = this; + final tr = typeAliasTable.trName; if (self is VoidType) { - return 'TypeReflection.tVoid'; + return '$tr.tVoid'; } if (self is FunctionType) { @@ -2642,12 +2706,12 @@ extension _DartTypeExtension on DartType { List arguments = alias.typeArguments; if (arguments.isEmpty) { - return 'TypeReflection<$name>($name)'; + return '$tr<$name>($name)'; } else { - return 'TypeReflection<$name<${arguments.typesNames}>>($name, ${arguments.toListOfConstTypeCode})'; + return '$tr<$name<${arguments.typesNames}>>($name, ${arguments.toListOfConstTypeCode(typeAliasTable)})'; } } else { - return 'TypeReflection.tFunction'; + return '$tr.tFunction'; } } @@ -2660,23 +2724,23 @@ extension _DartTypeExtension on DartType { var constName = TypeReflection.getConstantName(name, typeArgs); if (constName != null) { - return 'TypeReflection.$constName'; + return '$tr.$constName'; } } var argsT = arguments.typesNames; - var argsCode = arguments.toListOfConstTypeCode; + var argsCode = arguments.toListOfConstTypeCode(typeAliasTable); - return 'TypeReflection<$name<$argsT>>($name, $argsCode)'; + return '$tr<$name<$argsT>>($name, $argsCode)'; } else { var constName = _getTypeReflectionConstantName(name); if (constName != null) { - return 'TypeReflection.$constName'; + return '$tr.$constName'; } else { if (this is TypeParameterType) { - return 'TypeReflection.tDynamic'; + return '$tr.tDynamic'; } else { - return 'TypeReflection<$name>($name)'; + return '$tr<$name>($name)'; } } } @@ -2704,9 +2768,10 @@ extension _DartTypeExtension on DartType { return TypeReflection.getConstantName(name, args); } - String? get asConstTypeInfoCode { + String? asConstTypeInfoCode(_TypeAliasTable typeAliasTable) { + final ti = typeAliasTable.tiName; var constName = _getTypeReflectionConstantName(); - return constName == null ? null : 'TypeInfo.$constName'; + return constName == null ? null : '$ti.$constName'; } } @@ -2789,42 +2854,55 @@ String _buildStringListCode(Iterable? o, } } -String _buildParameterReflectionList(Iterable<_Parameter>? o, +String _buildParameterReflectionList( + _TypeAliasTable typeAliasTable, Iterable<_Parameter>? o, {required bool nullOnEmpty, required bool required}) { + final pr = typeAliasTable.prName; + if (o == null || o.isEmpty) { - return nullOnEmpty ? 'null' : 'const []'; + return nullOnEmpty ? 'null' : 'const <$pr>[]'; } else { - var parameters = o - .map((e) => "ParameterReflection( " - "${e.type.asTypeReflectionCode} , " - "'${e.name}' , " - "${e.isNullable ? 'true' : 'false'} , " - "$required , " - "${e.defaultValue ?? 'null'} , " - "${e.annotationsAsListCode}" - ")") - .join(', '); - return 'const [$parameters]'; + var parameters = o.map((e) { + var defaultValue = e.defaultValue ?? 'null'; + var annotationsAsListCode = e.annotationsAsListCode; + + return "$pr( " + "${e.type.asTypeReflectionCode(typeAliasTable)} , " + "'${e.name}' , " + "${e.isNullable} , " + "$required" + "${defaultValue == 'null' && annotationsAsListCode == 'null' ? '' : ', $defaultValue '}" + "${annotationsAsListCode == 'null' ? '' : ', $annotationsAsListCode'}" + ")"; + }).join(', '); + + return 'const <$pr>[$parameters]'; } } -String _buildNamedParameterReflectionMap(Map? o, +String _buildNamedParameterReflectionMap( + _TypeAliasTable typeAliasTable, Map? o, {bool nullOnEmpty = false}) { + final pr = typeAliasTable.prName; + if (o == null || o.isEmpty) { return nullOnEmpty ? 'null' : 'const {}}'; } else { var parameters = o.entries.map((e) { var key = e.key; var value = e.value; - return "'$key': ParameterReflection( " - "${value.type.asTypeReflectionCode} , " + var defaultValue = e.value.defaultValue ?? 'null'; + var annotationsAsListCode = e.value.annotationsAsListCode; + + return "'$key': $pr( " + "${value.type.asTypeReflectionCode(typeAliasTable)} , " "'${e.value.name}' , " - "${e.value.isNullable ? 'true' : 'false'} , " - "${e.value.required ? 'true' : 'false'} , " - "${e.value.defaultValue ?? 'null'} , " - "${e.value.annotationsAsListCode}" + "${e.value.isNullable} , " + "${e.value.required} " + "${defaultValue == 'null' && annotationsAsListCode == 'null' ? '' : ', $defaultValue '}" + "${annotationsAsListCode == 'null' ? '' : ', $annotationsAsListCode'}" ")"; }).join(', '); - return 'const {$parameters}'; + return 'const {$parameters}'; } } diff --git a/lib/src/reflection_factory_json.dart b/lib/src/reflection_factory_json.dart index f14b9a7..7d019db 100644 --- a/lib/src/reflection_factory_json.dart +++ b/lib/src/reflection_factory_json.dart @@ -125,6 +125,8 @@ typedef JsomMapDecoderAsyncProvider = JsomMapDecoderAsync? Function( typedef IterableCaster = Object? Function(Iterable value, TypeReflection type); +typedef MapCaster = Object? Function(Map value, TypeReflection type); + /// JSON codec integrated with [ReflectionFactory]. class JsonCodec { static final JsonCodec defaultCodec = @@ -143,6 +145,7 @@ class JsonCodec { JsomMapDecoderAsyncProvider? jsomMapDecoderAsyncProvider, JsomMapDecoderAsync? jsomMapDecoderAsync, IterableCaster? iterableCaster, + MapCaster? mapCaster, JsonEntityCache? entityCache, bool forceDuplicatedEntitiesAsID = false, autoResetEntityCache = true}) { @@ -156,6 +159,7 @@ class JsonCodec { jsomMapDecoderAsyncProvider == null && jsomMapDecoderAsync == null && iterableCaster == null && + mapCaster == null && entityCache == null && !forceDuplicatedEntitiesAsID && autoResetEntityCache) { @@ -180,6 +184,7 @@ class JsonCodec { jsomMapDecoderAsyncProvider, jsomMapDecoderAsync, iterableCaster, + mapCaster, entityCache, forceDuplicatedEntitiesAsID, autoResetEntityCache)); @@ -834,6 +839,7 @@ abstract class JsonDecoder extends JsonConverter { JsomMapDecoderAsyncProvider? jsomMapDecoderAsyncProvider, JsomMapDecoderAsync? jsomMapDecoderAsync, IterableCaster? iterableCaster, + MapCaster? mapCaster, JsonEntityCache? entityCache, bool forceDuplicatedEntitiesAsID = false, bool autoResetEntityCache = true}) { @@ -842,6 +848,7 @@ abstract class JsonDecoder extends JsonConverter { jsomMapDecoderAsyncProvider == null && jsomMapDecoderAsync == null && iterableCaster == null && + mapCaster == null && entityCache == null && !forceDuplicatedEntitiesAsID && autoResetEntityCache) { @@ -855,6 +862,7 @@ abstract class JsonDecoder extends JsonConverter { jsomMapDecoderAsyncProvider, jsomMapDecoderAsync, iterableCaster, + mapCaster, entityCache, forceDuplicatedEntitiesAsID, autoResetEntityCache); @@ -943,8 +951,8 @@ abstract class JsonDecoder extends JsonConverter { class _JsonDecoder extends dart_convert.Converter implements JsonDecoder { - static final _JsonDecoder _defaultDecoder = - _JsonDecoder._(null, null, null, null, null, null, null, false, true); + static final _JsonDecoder _defaultDecoder = _JsonDecoder._( + null, null, null, null, null, null, null, null, false, true); factory _JsonDecoder( JsonValueDecoderProvider? jsonValueDecoderProvider, @@ -953,6 +961,7 @@ class _JsonDecoder extends dart_convert.Converter JsomMapDecoderAsyncProvider? jsomMapDecoderAsyncProvider, JsomMapDecoderAsync? jsomMapDecoderAsync, IterableCaster? iterableCaster, + MapCaster? mapCaster, JsonEntityCache? entityCache, bool forceDuplicatedEntitiesAsID, bool autoResetEntityCache) { @@ -962,6 +971,7 @@ class _JsonDecoder extends dart_convert.Converter jsomMapDecoderAsyncProvider == null && jsomMapDecoderAsync == null && iterableCaster == null && + mapCaster == null && entityCache == null && !forceDuplicatedEntitiesAsID && autoResetEntityCache) { @@ -975,6 +985,7 @@ class _JsonDecoder extends dart_convert.Converter jsomMapDecoderAsyncProvider, jsomMapDecoderAsync, iterableCaster, + mapCaster, entityCache, forceDuplicatedEntitiesAsID, autoResetEntityCache); @@ -989,6 +1000,7 @@ class _JsonDecoder extends dart_convert.Converter final JsomMapDecoderAsync? jsomMapDecoderAsync; final IterableCaster? iterableCaster; + final MapCaster? mapCaster; @override final JsonEntityCache entityCache; @@ -1005,6 +1017,7 @@ class _JsonDecoder extends dart_convert.Converter this.jsomMapDecoderAsyncProvider, this.jsomMapDecoderAsync, this.iterableCaster, + this.mapCaster, JsonEntityCache? entityCache, this.forceDuplicatedEntitiesAsID, this.autoResetEntityCache, @@ -1364,7 +1377,9 @@ class _JsonDecoder extends dart_convert.Converter if (map is Map || map is Map || - map is Map) { + map is Map || + map is Map || + map is Map) { return map as O; } @@ -1743,6 +1758,8 @@ class _JsonDecoder extends dart_convert.Converter bool duplicatedEntitiesAsID) { if (type.isIterableType && value is Iterable) { return _castEntityList(value, type, duplicatedEntitiesAsID); + } else if (type.isMapType && value is Map) { + return _castEntityMap(value, type, duplicatedEntitiesAsID); } else { return _fromJsonImpl(value, type.typeInfo, duplicatedEntitiesAsID); } @@ -1758,20 +1775,87 @@ class _JsonDecoder extends dart_convert.Converter } } - var castTypeInfo = type.listEntityType!; - var castType = castTypeInfo.type; + var castTypeRefl = type.listType; - var val = - _fromJsonListImpl(value, castTypeInfo.typeInfo, duplicatedEntitiesAsID); + if (castTypeRefl != null) { + var castType = castTypeRefl.type; - var classReflection = - ReflectionFactory().getRegisterClassReflection(castType); + var val = _fromJsonListImpl( + value, castTypeRefl.typeInfo, duplicatedEntitiesAsID); + + var classReflection = + ReflectionFactory().getRegisterClassReflection(castType); + + if (classReflection != null) { + var nullable = val.any((e) => e == null); + return classReflection.castList(val, castType, nullable: nullable) ?? + val; + } - if (classReflection != null) { - var nullable = val.any((e) => e == null); - return classReflection.castList(val, castType, nullable: nullable) ?? val; - } else { return castListType(val, castType); + } else { + return value; + } + } + + Object? _castEntityMap( + Map value, TypeReflection type, bool duplicatedEntitiesAsID) { + var mapCaster = this.mapCaster; + if (mapCaster != null) { + var casted = mapCaster(value, type); + if (casted != null) { + return casted; + } + } + + var castKeyTypeRefl = type.mapKeyType; + var castValueTypeRefl = type.mapValueType; + + var val = value; + + if (castKeyTypeRefl != null && castKeyTypeRefl.isEntityType) { + val = val.map((key, value) => MapEntry( + _fromJsonImpl(key, castKeyTypeRefl.typeInfo, duplicatedEntitiesAsID), + value)); + } + + if (castValueTypeRefl != null && castValueTypeRefl.isEntityType) { + val = val.map((key, value) => MapEntry( + key, + _fromJsonImpl( + value, castValueTypeRefl.typeInfo, duplicatedEntitiesAsID))); + } + + var castKeyType = castKeyTypeRefl?.type; + var castValueType = castValueTypeRefl?.type; + + var classReflectionKey = castKeyType != null + ? ReflectionFactory().getRegisterClassReflection(castKeyType) + : null; + var classReflectionValue = castValueType != null + ? ReflectionFactory().getRegisterClassReflection(castValueType) + : null; + + if (classReflectionKey != null) { + var nullableKey = val.entries.any((e) => e.key == null); + + val = classReflectionKey.castMapKeys(val, type.typeInfo, + nullable: nullableKey) ?? + val; + } + + if (classReflectionValue != null) { + var nullableVal = val.entries.any((e) => e.value == null); + + val = classReflectionValue.castMapValues(val, type.typeInfo, + nullable: nullableVal) ?? + val; + } + + if (castKeyType != null || castValueType != null) { + return castMapType(val, castKeyType ?? dynamic, castValueType ?? dynamic); + } else { + return val; } } @@ -1880,6 +1964,58 @@ List castListType(List list, Type type) { } } +Map castMapType(Map map, Type keyType, Type valueType) { + if (map is Map && + K != dynamic && + K != Object && + V != dynamic && + V != Object) { + return map; + } else if (keyType == String) { + return _castMapValueType(map, keyType, valueType); + } else if (keyType == int) { + return _castMapValueType(map, keyType, valueType); + } else if (keyType == double) { + return _castMapValueType(map, keyType, valueType); + } else if (keyType == num) { + return _castMapValueType(map, keyType, valueType); + } else if (keyType == bool) { + return _castMapValueType(map, keyType, valueType); + } else if (keyType == DateTime) { + return _castMapValueType(map, keyType, valueType); + } else if (keyType == BigInt) { + return _castMapValueType(map, keyType, valueType); + } else if (keyType == Uint8List) { + return _castMapValueType(map, keyType, valueType); + } else { + return map; + } +} + +Map _castMapValueType(Map map, Type keyType, Type valueType) { + assert(K == keyType); + + if (valueType == String) { + return map.cast(); + } else if (valueType == int) { + return map.cast(); + } else if (valueType == double) { + return map.cast(); + } else if (valueType == num) { + return map.cast(); + } else if (valueType == bool) { + return map.cast(); + } else if (valueType == DateTime) { + return map.cast(); + } else if (valueType == BigInt) { + return map.cast(); + } else if (valueType == Uint8List) { + return map.cast(); + } else { + return map; + } +} + /// A JSON entity encoding/decoding cache. abstract class JsonEntityCache { /// The cache ID. diff --git a/lib/src/reflection_factory_type.dart b/lib/src/reflection_factory_type.dart index 38aa4d3..04f34c1 100644 --- a/lib/src/reflection_factory_type.dart +++ b/lib/src/reflection_factory_type.dart @@ -1514,19 +1514,26 @@ class TypeInfo { reflectionFactory.getRegisterEnumReflection(valueType.type); if (keyReflection != null && valueReflection != null) { - var mapKeysCast = keyReflection.castMap( - map, TypeInfo.fromMapType(keyType, TypeInfo.tDynamic), - nullable: nullable) ?? - map; + var tMap = TypeInfo.fromMapType( + keyReflection.typeInfo, valueReflection.typeInfo); + + if (valueReflection == keyReflection) { + return keyReflection.castMap(map, tMap, nullable: nullable) ?? map; + } else { + var mapKeysCast = + keyReflection.castMapKeys(map, tMap, nullable: nullable) ?? map; - var mapCast = - valueReflection.castMap(mapKeysCast, this, nullable: nullable) ?? map; + var mapCast = valueReflection.castMapValues(mapKeysCast, this, + nullable: nullable) ?? + map; - return mapCast; + return mapCast; + } } else if (keyReflection != null) { - return keyReflection.castMap(map, this, nullable: nullable) ?? map; + return keyReflection.castMapKeys(map, this, nullable: nullable) ?? map; } else if (valueReflection != null) { - return valueReflection.castMap(map, this, nullable: nullable) ?? map; + return valueReflection.castMapValues(map, this, nullable: nullable) ?? + map; } if (keyType.isValidGenericType && valueType.isValidGenericType) { diff --git a/pubspec.yaml b/pubspec.yaml index 4aececf..5fb93b2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,30 +1,30 @@ name: reflection_factory description: Allows Dart reflection with an easy approach, even for third-party classes, using code generation portable for all Dart platforms. -version: 1.2.17 +version: 1.2.18 homepage: https://github.com/gmpassos/reflection_factory environment: sdk: '>=2.17.0 <3.0.0' dependencies: - build: ^2.3.0 - analyzer: ^4.6.0 - dart_style: ^2.2.3 + build: ^2.3.1 + analyzer: ^4.7.0 + dart_style: ^2.2.4 meta: ^1.8.0 - mime: ^1.0.2 + mime: ^1.0.3 base_codecs: ^1.0.1 - pub_semver: ^2.1.1 - path: ^1.8.2 + pub_semver: ^2.1.3 + path: ^1.8.3 collection: ^1.16.0 yaml: ^3.1.1 source_span: ^1.9.1 dev_dependencies: - build_runner: ^2.2.0 + build_runner: ^2.3.3 build_test: ^2.1.5 - lints: ^2.0.0 + lints: ^2.0.1 pubspec: ^2.3.0 data_serializer: ^1.0.7 dependency_validator: ^3.2.2 - test: ^1.21.4 - coverage: ^1.5.0 + test: ^1.22.1 + coverage: ^1.6.1 diff --git a/reflection_factory.iml b/reflection_factory.iml index ebc67ac..b1d89b9 100644 --- a/reflection_factory.iml +++ b/reflection_factory.iml @@ -1,5 +1,5 @@ - + diff --git a/test/reflection_factory_build_test.dart b/test/reflection_factory_build_test.dart index 18bee89..fa50b2e 100644 --- a/test/reflection_factory_build_test.dart +++ b/test/reflection_factory_build_test.dart @@ -102,13 +102,15 @@ void main() { contains( 'BUILDER: reflection_factory/${ReflectionFactory.VERSION}'), contains("part of 'foo.dart'"), + contains( + "Version _version = Version.parse('${ReflectionFactory.VERSION}')"), ), allOf( contains('User\$reflection'), contains('User\$reflectionExtension'), ), matches(RegExp( - r"'ignoreCase':\s*ParameterReflection\(\s*TypeReflection.tBool\s*,\s*'ignoreCase'\s*,\s*false\s*,\s*false\s*,\s*false\s*,\s*null\s*\)")), + r"'ignoreCase':\s*__PR\(\s*__TR.tBool\s*,\s*'ignoreCase'\s*,\s*false\s*,\s*false\s*,\s*false\s*\)")), allOf( contains("TestAnnotation(['static method', 'version checker'])"), contains("TestAnnotation(['method', 'password checker'])"), @@ -205,13 +207,13 @@ void main() { 'Domain? createInstanceWithNoRequiredArgsConstructor() => Domain.empty();'), ), matches(RegExp( - r"'suffix':\s*ParameterReflection\(\s*TypeReflection.tString\s*,\s*'suffix'\s*,\s*false\s*,\s*false\s*,\s*'net'\s*,\s*null\s*\)")), + r"'suffix':\s*__PR\(\s*__TR.tString\s*,\s*'suffix'\s*,\s*false\s*,\s*false\s*,\s*'net'\s*\)")), allOf( matches(RegExp( - r"case 'callfx':.*?const \[\s*ParameterReflection\(\s*TypeReflection\(Fx\), 'f', true, false, null, null\)\s*\]", + r"case 'callfx':.*?const <__PR>\[\s*__PR\(\s*__TR\(Fx\), 'f', true, false\)\s*\]", dotAll: true)), matches(RegExp( - r"case 'callallfx':.*?ParameterReflection\(\s*TypeReflection>\(\s*List, \[TypeInfo.tFunction\]\),\s*'fxs',\s*false,\s*true,\s*null,\s*null\)", + r"case 'callallfx':.*?__PR\(\s*__TR>\(\s*List, <__TI>\[__TI.tFunction\]\),\s*'fxs',\s*false,\s*true\)", dotAll: true)), matches(RegExp( r'Object\?\s+toJson\(.*?\)\s+=>\s+reflection.toJson\(')), @@ -325,11 +327,11 @@ void main() { contains("case 'value':"), contains("fieldsNames => const ['type', 'value']"), matches(RegExp( - r"TypeReflection>>\(\s*List, \[TypeReflection.tSetInt\]\)")), + r"__TR>>\(\s*List, <__TR>\[__TR.tSetInt\]\)")), matches(RegExp( - r"TypeReflection>>\(\s*List, \[TypeReflection.tSetInt\]\)")), + r"__TR>>\(\s*List, <__TR>\[__TR.tSetInt\]\)")), matches(RegExp( - r"TypeReflection>>\(\s*Set, \[TypeReflection.tListDynamic\]\)")), + r"__TR>>\(\s*Set, <__TR>\[__TR.tListDynamic\]\)")), ), )), }, diff --git a/test/reflection_factory_json_test.dart b/test/reflection_factory_json_test.dart index c719e52..63bcb94 100644 --- a/test/reflection_factory_json_test.dart +++ b/test/reflection_factory_json_test.dart @@ -141,6 +141,8 @@ void main() { group('JSON', () { test('castListType', () { expect(['a', 'b'], isNot(isA>())); + expect(castListType(['a', 'b'], String), + isA>()); expect(castListType(['a', 'b'], String), isA>()); expect(castListType([1, 2], int), isA>()); expect(castListType([1.2, 2.3], double), isA>()); @@ -153,6 +155,56 @@ void main() { expect(castListType([Uint8List(10)], Uint8List), isA>()); }); + + test('castMapType', () { + expect({'a': 'b'}, isNot(isA>())); + expect( + castMapType( + {'a': 'b'}, String, String), + isA>()); + expect(castMapType({'a': 'b'}, String, String), + isA>()); + expect(castMapType({'a': 1}, String, int), + isA>()); + expect(castMapType({'a': 1.2}, String, double), + isA>()); + expect(castMapType({'a': 1.2, 'b': 2}, String, num), + isA>()); + expect(castMapType({'a': true}, String, bool), + isA>()); + expect( + castMapType( + {'a': DateTime.now()}, String, DateTime), + isA>()); + expect(castMapType({'a': BigInt.zero}, String, BigInt), + isA>()); + expect( + castMapType( + {'a': Uint8List(10)}, String, Uint8List), + isA>()); + + expect(castMapType({1: 'b'}, int, String), + isA>()); + + expect(castMapType({1: 'b'}, int, String), + isA>()); + expect(castMapType({1.2: 'b'}, double, String), + isA>()); + expect(castMapType({1.2: 'b', 1: 'a'}, num, String), + isA>()); + expect(castMapType({true: 'b'}, bool, String), + isA>()); + expect( + castMapType( + {DateTime.now(): 'b'}, DateTime, String), + isA>()); + expect(castMapType({BigInt.zero: 'b'}, BigInt, String), + isA>()); + expect( + castMapType( + {Uint8List(10): 'b'}, Uint8List, String), + isA>()); + }); }); group('JsonCodec', () { @@ -251,6 +303,22 @@ void main() { TestAddressWithReflection('State3', city: 'City3') ], isNot(isA>())); + expect( + JsonCodec().toJson(TestFranchiseWithReflection( + 'FooInc', + { + 'main': TestAddressWithReflection('State1', city: 'City1'), + 'extra': TestAddressWithReflection('State1', city: 'City2') + }, + )), + equals({ + 'addresses': { + 'main': {'state': 'State1', 'city': 'City1'}, + 'extra': {'state': 'State1', 'city': 'City2'} + }, + 'name': 'FooInc' + })); + // List: expect( @@ -660,6 +728,21 @@ void main() { TestAddressWithReflection('State3', city: 'City3') ]))); + expect( + await JsonCodec.defaultCodec.fromJsonAsync( + Future.value({ + 'addresses': { + 'a': {'state': 'State', 'city': 'A'}, + 'b': {'state': 'State', 'city': 'B'} + }, + 'name': 'FooFranchise' + }), + type: TestFranchiseWithReflection), + equals(TestFranchiseWithReflection('FooFranchise', { + 'a': TestAddressWithReflection('State', city: 'A'), + 'b': TestAddressWithReflection('State', city: 'B'), + }))); + expect( JsonCodec.defaultCodec.fromJsonList([ TestAddressWithReflection('State2', city: 'City2'), diff --git a/test/reflection_factory_test.dart b/test/reflection_factory_test.dart index 7dab3de..17092a9 100644 --- a/test/reflection_factory_test.dart +++ b/test/reflection_factory_test.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:reflection_factory/reflection_factory.dart'; import 'package:test/test.dart'; @@ -464,6 +465,117 @@ void main() { 'Joe', 'joe@mail.com', '123') }), isA>())); + + var tMapKV1 = TypeInfo< + Map>.fromMapType( + TestUserWithReflection, TestAddressWithReflection); + + var mapKV1 = tMapKV1.castMap({ + TestUserWithReflection.fields('Joe', 'joe@mail.com', '123'): + TestAddressWithReflection('NY', city: 'New York') + }); + + expect( + mapKV1, + allOf( + equals({ + TestUserWithReflection.fields('Joe', 'joe@mail.com', '123'): + TestAddressWithReflection('NY', city: 'New York') + }), + isA>())); + + var tMapKV2 = TypeInfo< + Map>.fromMapType( + TestAddressWithReflection, TestAddressWithReflection); + + var mapKV2 = tMapKV2.castMap({ + TestAddressWithReflection('CA', city: 'Los Angeles'): + TestAddressWithReflection('NY', city: 'New York') + }); + + expect( + mapKV2, + allOf( + equals({ + TestAddressWithReflection('CA', city: 'Los Angeles'): + TestAddressWithReflection('NY', city: 'New York') + }), + isA< + Map>())); + + var tMapK2 = TypeInfo>.fromMapType( + TestUserWithReflection, TypeInfo.tDynamic); + + var mapK2 = TestUserWithReflection$reflection.staticInstance + .castMap({ + TestUserWithReflection.fields('Joe', 'joe@mail.com', '123'): + TestAddressWithReflection('NY', city: 'New York') + }, tMapK2); + + expect( + mapK2, + allOf( + equals({ + TestUserWithReflection.fields('Joe', 'joe@mail.com', '123'): + TestAddressWithReflection('NY', city: 'New York') + }), + isA>())); + + var tMapV2 = TypeInfo>.fromMapType( + TypeInfo.tDynamic, TestUserWithReflection); + + var mapV2 = TestUserWithReflection$reflection.staticInstance + .castMap({ + TestAddressWithReflection('NY', city: 'New York'): + TestUserWithReflection.fields('Joe', 'joe@mail.com', '123') + }, tMapV2); + + expect( + mapV2, + allOf( + equals({ + TestAddressWithReflection('NY', city: 'New York'): + TestUserWithReflection.fields( + 'Joe', 'joe@mail.com', '123') + }), + isA>())); + + var tMapK3 = TypeInfo>.fromMapType( + TypeInfo.tString, TestUserWithReflection); + + var mapK3 = TestUserWithReflection$reflection.staticInstance + .castMapKeys({ + 'a': TestUserWithReflection.fields('Joe', 'joe@mail.com', '123') + }, tMapK3); + + expect( + mapK3, + allOf( + equals({ + 'a': TestUserWithReflection.fields( + 'Joe', 'joe@mail.com', '123') + }), + isA>())); + + var tMapV3 = TypeInfo>.fromMapType( + TestUserWithReflection, TypeInfo.tString); + + var mapV3 = TestUserWithReflection$reflection.staticInstance + .castMapValues({ + TestUserWithReflection.fields('Joe', 'joe@mail.com', '123'): 'a' + }, tMapV3); + + expect( + mapV3, + allOf( + equals({ + TestUserWithReflection.fields('Joe', 'joe@mail.com', '123'): + 'a' + }), + isA>())); } expect( @@ -487,6 +599,7 @@ void main() { TestUserWithReflection, TestAddressWithReflection, TestCompanyWithReflection, + TestFranchiseWithReflection, TestDataWithReflection, TestDomainWithReflection, TestOpWithReflection, @@ -495,6 +608,24 @@ void main() { TestTransactionWithReflection, ])); + expect( + userReflection + .siblingsClassReflection() + .sorted() + .map((e) => e.classType), + equals([ + TestTransactionWithReflection, + TestFranchiseWithReflection, + TestDataWithReflection, + TestOpWithReflection, + TestOpAWithReflection, + TestAddressWithReflection, + TestCompanyWithReflection, + TestOpBWithReflection, + TestDomainWithReflection, + TestUserWithReflection + ])); + expect( TestEnumWithReflection$from('x'), equals(TestEnumWithReflection.x)); diff --git a/test/src/reflection/user_with_reflection.g.dart b/test/src/reflection/user_with_reflection.g.dart index 54528e3..4fa16c6 100644 --- a/test/src/reflection/user_with_reflection.g.dart +++ b/test/src/reflection/user_with_reflection.g.dart @@ -1,16 +1,29 @@ // // GENERATED CODE - DO NOT MODIFY BY HAND! -// BUILDER: reflection_factory/1.2.17 +// BUILDER: reflection_factory/1.2.18 // BUILD COMMAND: dart run build_runner build // // coverage:ignore-file +// ignore_for_file: unused_element // ignore_for_file: unnecessary_const // ignore_for_file: unnecessary_cast // ignore_for_file: unnecessary_type_check part of '../user_with_reflection.dart'; +typedef __TR = TypeReflection; +typedef __TI = TypeInfo; +typedef __PR = ParameterReflection; + +mixin __ReflectionMixin { + static final Version _version = Version.parse('1.2.18'); + + Version get reflectionFactoryVersion => _version; + + List siblingsReflection() => _siblingsReflection(); +} + // ignore: non_constant_identifier_names TestAddressWithReflection TestAddressWithReflection$fromJson( Map map) => @@ -51,6 +64,15 @@ TestDomainWithReflection TestDomainWithReflection$fromJsonEncoded( TestEnumWithReflection? TestEnumWithReflection$from(Object? o) => TestEnumWithReflection$reflection.staticInstance.from(o); // ignore: non_constant_identifier_names +TestFranchiseWithReflection TestFranchiseWithReflection$fromJson( + Map map) => + TestFranchiseWithReflection$reflection.staticInstance.fromJson(map); +// ignore: non_constant_identifier_names +TestFranchiseWithReflection TestFranchiseWithReflection$fromJsonEncoded( + String jsonEncoded) => + TestFranchiseWithReflection$reflection.staticInstance + .fromJsonEncoded(jsonEncoded); +// ignore: non_constant_identifier_names TestOpAWithReflection TestOpAWithReflection$fromJson( Map map) => TestOpAWithReflection$reflection.staticInstance.fromJson(map); @@ -94,7 +116,7 @@ TestUserWithReflection TestUserWithReflection$fromJsonEncoded( .fromJsonEncoded(jsonEncoded); class TestAddressWithReflection$reflection - extends ClassReflection { + extends ClassReflection with __ReflectionMixin { TestAddressWithReflection$reflection([TestAddressWithReflection? object]) : super(TestAddressWithReflection, 'TestAddressWithReflection', object); @@ -111,9 +133,6 @@ class TestAddressWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestAddressWithReflection$reflection withObject( [TestAddressWithReflection? obj]) => @@ -170,16 +189,11 @@ class TestAddressWithReflection$reflection '', () => (String state, {String city = '', int? id}) => TestAddressWithReflection(state, city: city, id: id), - const [ - ParameterReflection( - TypeReflection.tString, 'state', false, true, null, null) - ], + const <__PR>[__PR(__TR.tString, 'state', false, true)], null, - const { - 'city': ParameterReflection( - TypeReflection.tString, 'city', false, false, '', null), - 'id': ParameterReflection( - TypeReflection.tInt, 'id', true, false, null, null) + const { + 'city': __PR(__TR.tString, 'city', false, false, ''), + 'id': __PR(__TR.tInt, 'id', true, false) }, null); case 'empty': @@ -200,13 +214,6 @@ class TestAddressWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -235,7 +242,7 @@ class TestAddressWithReflection$reflection return FieldReflection( this, TestAddressWithReflection, - TypeReflection.tInt, + __TR.tInt, 'id', true, (o) => () => o!.id as T, @@ -243,13 +250,12 @@ class TestAddressWithReflection$reflection obj, false, false, - null, ); case 'state': return FieldReflection( this, TestAddressWithReflection, - TypeReflection.tString, + __TR.tString, 'state', false, (o) => () => o!.state as T, @@ -257,13 +263,12 @@ class TestAddressWithReflection$reflection obj, false, true, - null, ); case 'city': return FieldReflection( this, TestAddressWithReflection, - TypeReflection.tString, + __TR.tString, 'city', false, (o) => () => o!.city as T, @@ -271,13 +276,12 @@ class TestAddressWithReflection$reflection obj, false, true, - null, ); case 'hashcode': return FieldReflection( this, TestAddressWithReflection, - TypeReflection.tInt, + __TR.tInt, 'hashCode', false, (o) => () => o!.hashCode as T, @@ -317,7 +321,7 @@ class TestAddressWithReflection$reflection this, TestAddressWithReflection, 'toJson', - TypeReflection.tMapStringDynamic, + __TR.tMapStringDynamic, false, (o) => o!.toJson, obj, @@ -331,7 +335,7 @@ class TestAddressWithReflection$reflection this, TestAddressWithReflection, 'toString', - TypeReflection.tString, + __TR.tString, false, (o) => o!.toString, obj, @@ -356,7 +360,7 @@ class TestAddressWithReflection$reflection } class TestCompanyWithReflection$reflection - extends ClassReflection { + extends ClassReflection with __ReflectionMixin { TestCompanyWithReflection$reflection([TestCompanyWithReflection? object]) : super(TestCompanyWithReflection, 'TestCompanyWithReflection', object); @@ -373,9 +377,6 @@ class TestCompanyWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestCompanyWithReflection$reflection withObject( [TestCompanyWithReflection? obj]) => @@ -439,44 +440,31 @@ class TestCompanyWithReflection$reflection extraAddresses: extraAddresses, branchesAddresses: branchesAddresses, extraNames: extraNames), - const [ - ParameterReflection( - TypeReflection.tString, 'name', false, true, null, null), - ParameterReflection( - TypeReflection( - TestAddressWithReflection), - 'mainAddress', - true, - true, - null, - null) + const <__PR>[ + __PR(__TR.tString, 'name', false, true), + __PR(__TR(TestAddressWithReflection), + 'mainAddress', true, true) ], null, - const { - 'branchesAddresses': ParameterReflection( - TypeReflection>( - List, [ - TypeReflection( - TestAddressWithReflection) + const { + 'branchesAddresses': __PR( + __TR>(List, <__TR>[ + __TR(TestAddressWithReflection) ]), 'branchesAddresses', false, false, - const [], - null), - 'extraAddresses': ParameterReflection( - TypeReflection>( - List, [ - TypeReflection( - TestAddressWithReflection) + const []), + 'extraAddresses': __PR( + __TR>(List, <__TR>[ + __TR(TestAddressWithReflection) ]), 'extraAddresses', false, false, - const [], - null), - 'extraNames': ParameterReflection(TypeReflection.tListString, - 'extraNames', false, false, const [], null) + const []), + 'extraNames': __PR(__TR.tListString, 'extraNames', false, false, + const []) }, null); default: @@ -487,13 +475,6 @@ class TestCompanyWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -526,7 +507,7 @@ class TestCompanyWithReflection$reflection return FieldReflection( this, TestCompanyWithReflection, - TypeReflection.tString, + __TR.tString, 'name', false, (o) => () => o!.name as T, @@ -534,13 +515,12 @@ class TestCompanyWithReflection$reflection obj, false, true, - null, ); case 'mainaddress': return FieldReflection( this, TestCompanyWithReflection, - TypeReflection(TestAddressWithReflection), + __TR(TestAddressWithReflection), 'mainAddress', true, (o) => () => o!.mainAddress as T, @@ -548,13 +528,12 @@ class TestCompanyWithReflection$reflection obj, false, false, - null, ); case 'extranames': return FieldReflection( this, TestCompanyWithReflection, - TypeReflection.tListString, + __TR.tListString, 'extraNames', false, (o) => () => o!.extraNames as T, @@ -562,15 +541,13 @@ class TestCompanyWithReflection$reflection obj, false, true, - null, ); case 'branchesaddresses': return FieldReflection( this, TestCompanyWithReflection, - TypeReflection>( - List, [ - TypeReflection(TestAddressWithReflection) + __TR>(List, <__TR>[ + __TR(TestAddressWithReflection) ]), 'branchesAddresses', false, @@ -580,15 +557,13 @@ class TestCompanyWithReflection$reflection obj, false, false, - null, ); case 'extraaddresses': return FieldReflection( this, TestCompanyWithReflection, - TypeReflection>( - List, [ - TypeReflection(TestAddressWithReflection) + __TR>(List, <__TR>[ + __TR(TestAddressWithReflection) ]), 'extraAddresses', false, @@ -598,13 +573,12 @@ class TestCompanyWithReflection$reflection obj, false, false, - null, ); case 'local': return FieldReflection( this, TestCompanyWithReflection, - TypeReflection.tBool, + __TR.tBool, 'local', false, (o) => () => o!.local as T, @@ -618,7 +592,7 @@ class TestCompanyWithReflection$reflection return FieldReflection( this, TestCompanyWithReflection, - TypeReflection.tInt, + __TR.tInt, 'hashCode', false, (o) => () => o!.hashCode as T, @@ -658,7 +632,7 @@ class TestCompanyWithReflection$reflection this, TestCompanyWithReflection, 'toString', - TypeReflection.tString, + __TR.tString, false, (o) => o!.toString, obj, @@ -683,7 +657,7 @@ class TestCompanyWithReflection$reflection } class TestDataWithReflection$reflection - extends ClassReflection { + extends ClassReflection with __ReflectionMixin { TestDataWithReflection$reflection([TestDataWithReflection? object]) : super(TestDataWithReflection, 'TestDataWithReflection', object); @@ -700,9 +674,6 @@ class TestDataWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestDataWithReflection$reflection withObject([TestDataWithReflection? obj]) => TestDataWithReflection$reflection(obj); @@ -757,24 +728,18 @@ class TestDataWithReflection$reflection () => (String name, Uint8List bytes, {BigInt? id, TestDomainWithReflection? domain}) => TestDataWithReflection(name, bytes, id: id, domain: domain), - const [ - ParameterReflection( - TypeReflection.tString, 'name', false, true, null, null), - ParameterReflection(TypeReflection(Uint8List), 'bytes', - false, true, null, null) + const <__PR>[ + __PR(__TR.tString, 'name', false, true), + __PR(__TR(Uint8List), 'bytes', false, true) ], null, - const { - 'domain': ParameterReflection( - TypeReflection( - TestDomainWithReflection), + const { + 'domain': __PR( + __TR(TestDomainWithReflection), 'domain', true, - false, - null, - null), - 'id': ParameterReflection( - TypeReflection.tBigInt, 'id', true, false, null, null) + false), + 'id': __PR(__TR.tBigInt, 'id', true, false) }, null); default: @@ -785,13 +750,6 @@ class TestDataWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -817,7 +775,7 @@ class TestDataWithReflection$reflection return FieldReflection( this, TestDataWithReflection, - TypeReflection.tString, + __TR.tString, 'name', false, (o) => () => o!.name as T, @@ -825,13 +783,12 @@ class TestDataWithReflection$reflection obj, false, true, - null, ); case 'id': return FieldReflection( this, TestDataWithReflection, - TypeReflection.tBigInt, + __TR.tBigInt, 'id', false, (o) => () => o!.id as T, @@ -839,13 +796,12 @@ class TestDataWithReflection$reflection obj, false, false, - null, ); case 'bytes': return FieldReflection( this, TestDataWithReflection, - TypeReflection(Uint8List), + __TR(Uint8List), 'bytes', false, (o) => () => o!.bytes as T, @@ -853,13 +809,12 @@ class TestDataWithReflection$reflection obj, false, false, - null, ); case 'domain': return FieldReflection( this, TestDataWithReflection, - TypeReflection(TestDomainWithReflection), + __TR(TestDomainWithReflection), 'domain', true, (o) => () => o!.domain as T, @@ -867,13 +822,12 @@ class TestDataWithReflection$reflection obj, false, false, - null, ); case 'hashcode': return FieldReflection( this, TestDataWithReflection, - TypeReflection.tInt, + __TR.tInt, 'hashCode', false, (o) => () => o!.hashCode as T, @@ -918,7 +872,7 @@ class TestDataWithReflection$reflection } class TestDomainWithReflection$reflection - extends ClassReflection { + extends ClassReflection with __ReflectionMixin { TestDomainWithReflection$reflection([TestDomainWithReflection? object]) : super(TestDomainWithReflection, 'TestDomainWithReflection', object); @@ -935,9 +889,6 @@ class TestDomainWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestDomainWithReflection$reflection withObject( [TestDomainWithReflection? obj]) => @@ -996,22 +947,14 @@ class TestDomainWithReflection$reflection bool Function()? extraFunction]) => TestDomainWithReflection( name, suffix, domainFunction, extraFunction), - const [ - ParameterReflection( - TypeReflection.tString, 'name', false, true, null, null), - ParameterReflection( - TypeReflection.tString, 'suffix', false, true, null, null) + const <__PR>[ + __PR(__TR.tString, 'name', false, true), + __PR(__TR.tString, 'suffix', false, true) ], - const [ - ParameterReflection( - TypeReflection(DomainFunction), - 'domainFunction', - true, - false, - null, - null), - ParameterReflection(TypeReflection.tFunction, 'extraFunction', - true, false, null, null) + const <__PR>[ + __PR(__TR(DomainFunction), 'domainFunction', true, + false), + __PR(__TR.tFunction, 'extraFunction', true, false) ], null, null); @@ -1032,20 +975,13 @@ class TestDomainWithReflection$reflection extraFunction: extraFunction), null, null, - const { - 'domainFunction': ParameterReflection( - TypeReflection(DomainFunction), - 'domainFunction', - true, - false, - null, - null), - 'extraFunction': ParameterReflection(TypeReflection.tFunction, - 'extraFunction', true, false, null, null), - 'name': ParameterReflection( - TypeReflection.tString, 'name', false, true, null, null), - 'suffix': ParameterReflection( - TypeReflection.tString, 'suffix', false, false, 'net', null) + const { + 'domainFunction': __PR(__TR(DomainFunction), + 'domainFunction', true, false), + 'extraFunction': + __PR(__TR.tFunction, 'extraFunction', true, false), + 'name': __PR(__TR.tString, 'name', false, true), + 'suffix': __PR(__TR.tString, 'suffix', false, false, 'net') }, null); case 'parse': @@ -1054,10 +990,7 @@ class TestDomainWithReflection$reflection TestDomainWithReflection, 'parse', () => (String s) => TestDomainWithReflection.parse(s), - const [ - ParameterReflection( - TypeReflection.tString, 's', false, true, null, null) - ], + const <__PR>[__PR(__TR.tString, 's', false, true)], null, null, null); @@ -1069,13 +1002,6 @@ class TestDomainWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -1109,7 +1035,7 @@ class TestDomainWithReflection$reflection return FieldReflection( this, TestDomainWithReflection, - TypeReflection.tString, + __TR.tString, 'name', false, (o) => () => o!.name as T, @@ -1117,13 +1043,12 @@ class TestDomainWithReflection$reflection obj, false, true, - null, ); case 'suffix': return FieldReflection( this, TestDomainWithReflection, - TypeReflection.tString, + __TR.tString, 'suffix', false, (o) => () => o!.suffix as T, @@ -1131,13 +1056,12 @@ class TestDomainWithReflection$reflection obj, false, true, - null, ); case 'domainfunction': return FieldReflection( this, TestDomainWithReflection, - TypeReflection(DomainFunction), + __TR(DomainFunction), 'domainFunction', true, (o) => () => o!.domainFunction as T, @@ -1145,13 +1069,12 @@ class TestDomainWithReflection$reflection obj, false, true, - null, ); case 'extrafunction': return FieldReflection( this, TestDomainWithReflection, - TypeReflection.tFunction, + __TR.tFunction, 'extraFunction', true, (o) => () => o!.extraFunction as T, @@ -1159,13 +1082,12 @@ class TestDomainWithReflection$reflection obj, false, true, - null, ); case 'hashcode': return FieldReflection( this, TestDomainWithReflection, - TypeReflection.tInt, + __TR.tInt, 'hashCode', false, (o) => () => o!.hashCode as T, @@ -1206,22 +1128,19 @@ class TestDomainWithReflection$reflection this, TestDomainWithReflection, 'typedFunction', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.typedFunction, obj, false, - const [ - ParameterReflection( - TypeReflection>( - TypedFunction, [TypeReflection.tDynamic]), + const <__PR>[ + __PR( + __TR>( + TypedFunction, <__TR>[__TR.tDynamic]), 'f', false, - true, - null, - null), - ParameterReflection( - TypeReflection.tDynamic, 'x', false, true, null, null) + true), + __PR(__TR.tDynamic, 'x', false, true) ], null, null, @@ -1231,7 +1150,7 @@ class TestDomainWithReflection$reflection this, TestDomainWithReflection, 'toJson', - TypeReflection.tString, + __TR.tString, false, (o) => o!.toJson, obj, @@ -1245,7 +1164,7 @@ class TestDomainWithReflection$reflection this, TestDomainWithReflection, 'toString', - TypeReflection.tString, + __TR.tString, false, (o) => o!.toString, obj, @@ -1270,7 +1189,7 @@ class TestDomainWithReflection$reflection } class TestEnumWithReflection$reflection - extends EnumReflection { + extends EnumReflection with __ReflectionMixin { TestEnumWithReflection$reflection([TestEnumWithReflection? object]) : super(TestEnumWithReflection, 'TestEnumWithReflection', object); @@ -1287,9 +1206,6 @@ class TestEnumWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestEnumWithReflection$reflection withObject([TestEnumWithReflection? obj]) => TestEnumWithReflection$reflection(obj); @@ -1316,13 +1232,6 @@ class TestEnumWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsEnumReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get fieldsNames => const ['Z', 'x', 'y', 'z']; @@ -1339,8 +1248,225 @@ class TestEnumWithReflection$reflection List get values => TestEnumWithReflection.values; } +class TestFranchiseWithReflection$reflection + extends ClassReflection + with __ReflectionMixin { + TestFranchiseWithReflection$reflection([TestFranchiseWithReflection? object]) + : super( + TestFranchiseWithReflection, 'TestFranchiseWithReflection', object); + + static bool _registered = false; + @override + void register() { + if (!_registered) { + _registered = true; + super.register(); + _registerSiblingsReflection(); + } + } + + @override + Version get languageVersion => Version.parse('2.17.0'); + + @override + TestFranchiseWithReflection$reflection withObject( + [TestFranchiseWithReflection? obj]) => + TestFranchiseWithReflection$reflection(obj); + + static TestFranchiseWithReflection$reflection? _withoutObjectInstance; + @override + TestFranchiseWithReflection$reflection withoutObjectInstance() => + _withoutObjectInstance ??= super.withoutObjectInstance() + as TestFranchiseWithReflection$reflection; + + static TestFranchiseWithReflection$reflection get staticInstance => + _withoutObjectInstance ??= TestFranchiseWithReflection$reflection(); + + @override + TestFranchiseWithReflection$reflection getStaticInstance() => staticInstance; + + static bool _boot = false; + static void boot() { + if (_boot) return; + _boot = true; + TestFranchiseWithReflection$reflection.staticInstance; + } + + @override + bool get hasDefaultConstructor => false; + @override + TestFranchiseWithReflection? createInstanceWithDefaultConstructor() => null; + + @override + bool get hasEmptyConstructor => false; + @override + TestFranchiseWithReflection? createInstanceWithEmptyConstructor() => null; + @override + bool get hasNoRequiredArgsConstructor => false; + @override + TestFranchiseWithReflection? createInstanceWithNoRequiredArgsConstructor() => + null; + + @override + List get constructorsNames => const ['']; + + @override + ConstructorReflection? constructor( + String constructorName) { + var lc = constructorName.trim().toLowerCase(); + + switch (lc) { + case '': + return ConstructorReflection( + this, + TestFranchiseWithReflection, + '', + () => (String name, + Map addresses) => + TestFranchiseWithReflection(name, addresses), + const <__PR>[ + __PR(__TR.tString, 'name', false, true), + __PR( + __TR>(Map, <__TR>[ + __TR.tString, + __TR(TestAddressWithReflection) + ]), + 'addresses', + false, + true) + ], + null, + null, + null); + default: + return null; + } + } + + @override + List get classAnnotations => List.unmodifiable([]); + + @override + List get supperTypes => const []; + + @override + bool get hasMethodToJson => false; + + @override + Object? callMethodToJson([TestFranchiseWithReflection? obj]) => null; + + @override + List get fieldsNames => + const ['addresses', 'hashCode', 'name']; + + @override + FieldReflection? field(String fieldName, + [TestFranchiseWithReflection? obj]) { + obj ??= object; + + var lc = fieldName.trim().toLowerCase(); + + switch (lc) { + case 'name': + return FieldReflection( + this, + TestFranchiseWithReflection, + __TR.tString, + 'name', + false, + (o) => () => o!.name as T, + null, + obj, + false, + true, + ); + case 'addresses': + return FieldReflection( + this, + TestFranchiseWithReflection, + __TR>(Map, <__TR>[ + __TR.tString, + __TR(TestAddressWithReflection) + ]), + 'addresses', + false, + (o) => () => o!.addresses as T, + (o) => (T? v) => + o!.addresses = v as Map, + obj, + false, + false, + ); + case 'hashcode': + return FieldReflection( + this, + TestFranchiseWithReflection, + __TR.tInt, + 'hashCode', + false, + (o) => () => o!.hashCode as T, + null, + obj, + false, + false, + [override], + ); + default: + return null; + } + } + + @override + List get staticFieldsNames => const []; + + @override + FieldReflection? staticField( + String fieldName) { + return null; + } + + @override + List get methodsNames => const ['toString']; + + @override + MethodReflection? method(String methodName, + [TestFranchiseWithReflection? obj]) { + obj ??= object; + + var lc = methodName.trim().toLowerCase(); + + switch (lc) { + case 'tostring': + return MethodReflection( + this, + TestFranchiseWithReflection, + 'toString', + __TR.tString, + false, + (o) => o!.toString, + obj, + false, + null, + null, + null, + [override]); + default: + return null; + } + } + + @override + List get staticMethodsNames => const []; + + @override + MethodReflection? staticMethod( + String methodName) { + return null; + } +} + class TestOpAWithReflection$reflection - extends ClassReflection { + extends ClassReflection with __ReflectionMixin { TestOpAWithReflection$reflection([TestOpAWithReflection? object]) : super(TestOpAWithReflection, 'TestOpAWithReflection', object); @@ -1357,9 +1483,6 @@ class TestOpAWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestOpAWithReflection$reflection withObject([TestOpAWithReflection? obj]) => TestOpAWithReflection$reflection(obj); @@ -1412,10 +1535,7 @@ class TestOpAWithReflection$reflection TestOpAWithReflection, '', () => (int value) => TestOpAWithReflection(value), - const [ - ParameterReflection( - TypeReflection.tInt, 'value', false, true, null, null) - ], + const <__PR>[__PR(__TR.tInt, 'value', false, true)], null, null, null); @@ -1427,13 +1547,6 @@ class TestOpAWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const [TestOpWithReflection]; @@ -1458,7 +1571,7 @@ class TestOpAWithReflection$reflection return FieldReflection( this, TestOpAWithReflection, - TypeReflection.tInt, + __TR.tInt, 'value', false, (o) => () => o!.value as T, @@ -1472,7 +1585,7 @@ class TestOpAWithReflection$reflection return FieldReflection( this, TestOpWithReflection, - TypeReflection.tString, + __TR.tString, 'type', false, (o) => () => o!.type as T, @@ -1480,7 +1593,6 @@ class TestOpAWithReflection$reflection obj, false, true, - null, ); default: return null; @@ -1499,7 +1611,7 @@ class TestOpAWithReflection$reflection return FieldReflection( this, TestOpAWithReflection, - TypeReflection.tInt, + __TR.tInt, 'staticFieldA', false, (o) => () => TestOpAWithReflection.staticFieldA as T, @@ -1530,7 +1642,7 @@ class TestOpAWithReflection$reflection this, TestOpAWithReflection, 'methodA', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.methodA, obj, @@ -1544,7 +1656,7 @@ class TestOpAWithReflection$reflection this, TestOpWithReflection, 'isEmptyType', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.isEmptyType, obj, @@ -1569,7 +1681,7 @@ class TestOpAWithReflection$reflection } class TestOpBWithReflection$reflection - extends ClassReflection { + extends ClassReflection with __ReflectionMixin { TestOpBWithReflection$reflection([TestOpBWithReflection? object]) : super(TestOpBWithReflection, 'TestOpBWithReflection', object); @@ -1586,9 +1698,6 @@ class TestOpBWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestOpBWithReflection$reflection withObject([TestOpBWithReflection? obj]) => TestOpBWithReflection$reflection(obj); @@ -1641,10 +1750,7 @@ class TestOpBWithReflection$reflection TestOpBWithReflection, '', () => (double amount) => TestOpBWithReflection(amount), - const [ - ParameterReflection( - TypeReflection.tDouble, 'amount', false, true, null, null) - ], + const <__PR>[__PR(__TR.tDouble, 'amount', false, true)], null, null, null); @@ -1656,13 +1762,6 @@ class TestOpBWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const [TestOpWithReflection]; @@ -1687,7 +1786,7 @@ class TestOpBWithReflection$reflection return FieldReflection( this, TestOpBWithReflection, - TypeReflection.tDouble, + __TR.tDouble, 'amount', false, (o) => () => o!.amount as T, @@ -1695,13 +1794,12 @@ class TestOpBWithReflection$reflection obj, false, false, - null, ); case 'type': return FieldReflection( this, TestOpWithReflection, - TypeReflection.tString, + __TR.tString, 'type', false, (o) => () => o!.type as T, @@ -1709,13 +1807,12 @@ class TestOpBWithReflection$reflection obj, false, true, - null, ); case 'value': return FieldReflection( this, TestOpWithReflection, - TypeReflection.tDynamic, + __TR.tDynamic, 'value', true, (o) => () => o!.value as T, @@ -1723,7 +1820,6 @@ class TestOpBWithReflection$reflection obj, false, false, - null, ); default: return null; @@ -1754,7 +1850,7 @@ class TestOpBWithReflection$reflection this, TestOpBWithReflection, 'methodB', - TypeReflection.tSetDynamic, + __TR.tSetDynamic, false, (o) => o!.methodB, obj, @@ -1768,7 +1864,7 @@ class TestOpBWithReflection$reflection this, TestOpWithReflection, 'isEmptyType', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.isEmptyType, obj, @@ -1796,7 +1892,7 @@ class TestOpBWithReflection$reflection this, TestOpBWithReflection, 'staticMethodB', - TypeReflection.tBool, + __TR.tBool, false, (o) => TestOpBWithReflection.staticMethodB, null, @@ -1812,7 +1908,7 @@ class TestOpBWithReflection$reflection } class TestOpWithReflection$reflection - extends ClassReflection { + extends ClassReflection with __ReflectionMixin { TestOpWithReflection$reflection([TestOpWithReflection? object]) : super(TestOpWithReflection, 'TestOpWithReflection', object); @@ -1829,9 +1925,6 @@ class TestOpWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestOpWithReflection$reflection withObject([TestOpWithReflection? obj]) => TestOpWithReflection$reflection(obj); @@ -1887,11 +1980,9 @@ class TestOpWithReflection$reflection '', () => (String type, dynamic value) => TestOpWithReflection(type, value), - const [ - ParameterReflection( - TypeReflection.tString, 'type', false, true, null, null), - ParameterReflection( - TypeReflection.tDynamic, 'value', true, true, null, null) + const <__PR>[ + __PR(__TR.tString, 'type', false, true), + __PR(__TR.tDynamic, 'value', true, true) ], null, null, @@ -1914,13 +2005,6 @@ class TestOpWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -1945,7 +2029,7 @@ class TestOpWithReflection$reflection return FieldReflection( this, TestOpWithReflection, - TypeReflection.tString, + __TR.tString, 'type', false, (o) => () => o!.type as T, @@ -1953,13 +2037,12 @@ class TestOpWithReflection$reflection obj, false, true, - null, ); case 'value': return FieldReflection( this, TestOpWithReflection, - TypeReflection.tDynamic, + __TR.tDynamic, 'value', true, (o) => () => o!.value as T, @@ -1967,7 +2050,6 @@ class TestOpWithReflection$reflection obj, false, false, - null, ); default: return null; @@ -1986,7 +2068,7 @@ class TestOpWithReflection$reflection return FieldReflection( this, TestOpWithReflection, - TypeReflection.tInt, + __TR.tInt, 'staticField', false, (o) => () => TestOpWithReflection.staticField as T, @@ -2017,7 +2099,7 @@ class TestOpWithReflection$reflection this, TestOpWithReflection, 'isEmptyType', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.isEmptyType, obj, @@ -2045,7 +2127,7 @@ class TestOpWithReflection$reflection this, TestOpWithReflection, 'staticMethod', - TypeReflection.tBool, + __TR.tBool, false, (o) => TestOpWithReflection.staticMethod, null, @@ -2061,7 +2143,8 @@ class TestOpWithReflection$reflection } class TestTransactionWithReflection$reflection - extends ClassReflection { + extends ClassReflection + with __ReflectionMixin { TestTransactionWithReflection$reflection( [TestTransactionWithReflection? object]) : super(TestTransactionWithReflection, 'TestTransactionWithReflection', @@ -2080,9 +2163,6 @@ class TestTransactionWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestTransactionWithReflection$reflection withObject( [TestTransactionWithReflection? obj]) => @@ -2140,25 +2220,12 @@ class TestTransactionWithReflection$reflection () => (int amount, TestUserWithReflection fromUser, TestUserWithReflection toUser) => TestTransactionWithReflection.fromTo(amount, fromUser, toUser), - const [ - ParameterReflection( - TypeReflection.tInt, 'amount', false, true, null, null), - ParameterReflection( - TypeReflection( - TestUserWithReflection), - 'fromUser', - false, - true, - null, - null), - ParameterReflection( - TypeReflection( - TestUserWithReflection), - 'toUser', - false, - true, - null, - null) + const <__PR>[ + __PR(__TR.tInt, 'amount', false, true), + __PR(__TR(TestUserWithReflection), + 'fromUser', false, true), + __PR(__TR(TestUserWithReflection), + 'toUser', false, true) ], null, null, @@ -2171,13 +2238,6 @@ class TestTransactionWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -2203,7 +2263,7 @@ class TestTransactionWithReflection$reflection return FieldReflection( this, TestTransactionWithReflection, - TypeReflection(TestUserWithReflection), + __TR(TestUserWithReflection), 'fromUser', false, (o) => () => o!.fromUser as T, @@ -2211,13 +2271,12 @@ class TestTransactionWithReflection$reflection obj, false, true, - null, ); case 'touser': return FieldReflection( this, TestTransactionWithReflection, - TypeReflection(TestUserWithReflection), + __TR(TestUserWithReflection), 'toUser', false, (o) => () => o!.toUser as T, @@ -2225,13 +2284,12 @@ class TestTransactionWithReflection$reflection obj, false, true, - null, ); case 'amount': return FieldReflection( this, TestTransactionWithReflection, - TypeReflection.tInt, + __TR.tInt, 'amount', false, (o) => () => o!.amount as T, @@ -2239,7 +2297,6 @@ class TestTransactionWithReflection$reflection obj, false, true, - null, ); default: return null; @@ -2278,7 +2335,7 @@ class TestTransactionWithReflection$reflection } class TestUserWithReflection$reflection - extends ClassReflection { + extends ClassReflection with __ReflectionMixin { TestUserWithReflection$reflection([TestUserWithReflection? object]) : super(TestUserWithReflection, 'TestUserWithReflection', object); @@ -2295,9 +2352,6 @@ class TestUserWithReflection$reflection @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestUserWithReflection$reflection withObject([TestUserWithReflection? obj]) => TestUserWithReflection$reflection(obj); @@ -2357,30 +2411,19 @@ class TestUserWithReflection$reflection int? id}) => TestUserWithReflection.fields(name, email, passphrase, enabled: enabled, axis: axis, level: level, id: id), - const [ - ParameterReflection( - TypeReflection.tString, 'name', false, true, null, null), - ParameterReflection( - TypeReflection.tString, 'email', true, true, null, null), - ParameterReflection(TypeReflection.tString, 'passphrase', false, - true, null, [JsonFieldAlias('password')]) + const <__PR>[ + __PR(__TR.tString, 'name', false, true), + __PR(__TR.tString, 'email', true, true), + __PR(__TR.tString, 'passphrase', false, true, null, + [JsonFieldAlias('password')]) ], null, - const { - 'axis': ParameterReflection( - TypeReflection( - TestEnumWithReflection), - 'axis', - false, - false, - TestEnumWithReflection.x, - null), - 'enabled': ParameterReflection( - TypeReflection.tBool, 'enabled', false, false, true, null), - 'id': ParameterReflection( - TypeReflection.tInt, 'id', true, false, null, null), - 'level': ParameterReflection( - TypeReflection.tInt, 'level', true, false, null, null) + const { + 'axis': __PR(__TR(TestEnumWithReflection), + 'axis', false, false, TestEnumWithReflection.x), + 'enabled': __PR(__TR.tBool, 'enabled', false, false, true), + 'id': __PR(__TR.tInt, 'id', true, false), + 'level': __PR(__TR.tInt, 'level', true, false) }, null); case '': @@ -2401,13 +2444,6 @@ class TestUserWithReflection$reflection @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -2443,7 +2479,7 @@ class TestUserWithReflection$reflection return FieldReflection( this, TestUserWithReflection, - TypeReflection.tInt, + __TR.tInt, 'id', true, (o) => () => o!.id as T, @@ -2451,13 +2487,12 @@ class TestUserWithReflection$reflection obj, false, false, - null, ); case 'name': return FieldReflection( this, TestUserWithReflection, - TypeReflection.tString, + __TR.tString, 'name', false, (o) => () => o!.name as T, @@ -2465,13 +2500,12 @@ class TestUserWithReflection$reflection obj, false, true, - null, ); case 'email': return FieldReflection( this, TestUserWithReflection, - TypeReflection.tString, + __TR.tString, 'email', true, (o) => () => o!.email as T, @@ -2479,13 +2513,12 @@ class TestUserWithReflection$reflection obj, false, false, - null, ); case 'password': return FieldReflection( this, TestUserWithReflection, - TypeReflection.tString, + __TR.tString, 'password', false, (o) => () => o!.password as T, @@ -2493,13 +2526,12 @@ class TestUserWithReflection$reflection obj, false, false, - null, ); case 'enabled': return FieldReflection( this, TestUserWithReflection, - TypeReflection.tBool, + __TR.tBool, 'enabled', false, (o) => () => o!.enabled as T, @@ -2507,13 +2539,12 @@ class TestUserWithReflection$reflection obj, false, false, - null, ); case 'axis': return FieldReflection( this, TestUserWithReflection, - TypeReflection(TestEnumWithReflection), + __TR(TestEnumWithReflection), 'axis', false, (o) => () => o!.axis as T, @@ -2521,13 +2552,12 @@ class TestUserWithReflection$reflection obj, false, false, - null, ); case 'level': return FieldReflection( this, TestUserWithReflection, - TypeReflection.tInt, + __TR.tInt, 'level', true, (o) => () => o!.level as T, @@ -2541,7 +2571,7 @@ class TestUserWithReflection$reflection return FieldReflection( this, TestUserWithReflection, - TypeReflection.tBool, + __TR.tBool, 'isEnabled', false, (o) => () => o!.isEnabled as T, @@ -2555,7 +2585,7 @@ class TestUserWithReflection$reflection return FieldReflection( this, TestUserWithReflection, - TypeReflection.tBool, + __TR.tBool, 'isNotEnabled', false, (o) => () => o!.isNotEnabled as T, @@ -2569,7 +2599,7 @@ class TestUserWithReflection$reflection return FieldReflection( this, TestUserWithReflection, - TypeReflection.tInt, + __TR.tInt, 'hashCode', false, (o) => () => o!.hashCode as T, @@ -2597,7 +2627,7 @@ class TestUserWithReflection$reflection return FieldReflection( this, TestUserWithReflection, - TypeReflection.tDouble, + __TR.tDouble, 'version', false, (o) => () => TestUserWithReflection.version as T, @@ -2611,7 +2641,7 @@ class TestUserWithReflection$reflection return FieldReflection( this, TestUserWithReflection, - TypeReflection.tBool, + __TR.tBool, 'withReflection', false, (o) => () => TestUserWithReflection.withReflection as T, @@ -2643,15 +2673,12 @@ class TestUserWithReflection$reflection this, TestUserWithReflection, 'checkPassword', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.checkPassword, obj, false, - const [ - ParameterReflection( - TypeReflection.tString, 'password', false, true, null, null) - ], + const <__PR>[__PR(__TR.tString, 'password', false, true)], null, null, null); @@ -2660,19 +2687,13 @@ class TestUserWithReflection$reflection this, TestUserWithReflection, 'getField', - TypeReflection.tDynamic, + __TR.tDynamic, true, (o) => o!.getField, obj, false, - const [ - ParameterReflection( - TypeReflection.tString, 'key', false, true, null, null) - ], - const [ - ParameterReflection( - TypeReflection.tDynamic, 'def', true, false, null, null) - ], + const <__PR>[__PR(__TR.tString, 'key', false, true)], + const <__PR>[__PR(__TR.tDynamic, 'def', true, false)], null, null); case 'setfield': @@ -2680,21 +2701,18 @@ class TestUserWithReflection$reflection this, TestUserWithReflection, 'setField', - TypeReflection.tVoid, + __TR.tVoid, false, (o) => o!.setField, obj, false, - const [ - ParameterReflection( - TypeReflection.tString, 'key', false, true, null, null), - ParameterReflection( - TypeReflection.tDynamic, 'value', true, true, null, null) + const <__PR>[ + __PR(__TR.tString, 'key', false, true), + __PR(__TR.tDynamic, 'value', true, true) ], null, - const { - 'def': ParameterReflection( - TypeReflection.tDynamic, 'def', true, false, null, null) + const { + 'def': __PR(__TR.tDynamic, 'def', true, false) }, null); case 'tostring': @@ -2702,7 +2720,7 @@ class TestUserWithReflection$reflection this, TestUserWithReflection, 'toString', - TypeReflection.tString, + __TR.tString, false, (o) => o!.toString, obj, @@ -2730,15 +2748,12 @@ class TestUserWithReflection$reflection this, TestUserWithReflection, 'isVersion', - TypeReflection.tBool, + __TR.tBool, false, (o) => TestUserWithReflection.isVersion, null, true, - const [ - ParameterReflection( - TypeReflection.tDouble, 'ver', false, true, null, null) - ], + const <__PR>[__PR(__TR.tDouble, 'ver', false, true)], null, null, null); @@ -2858,6 +2873,31 @@ extension TestEnumWithReflection$reflectionExtension on TestEnumWithReflection { reflection.toJsonEncoded(pretty: pretty); } +extension TestFranchiseWithReflection$reflectionExtension + on TestFranchiseWithReflection { + /// Returns a [ClassReflection] for type [TestFranchiseWithReflection]. (Generated by [ReflectionFactory]) + ClassReflection get reflection => + TestFranchiseWithReflection$reflection(this); + + /// Returns a JSON for type [TestFranchiseWithReflection]. (Generated by [ReflectionFactory]) + Object? toJson({bool duplicatedEntitiesAsID = false}) => + reflection.toJson(null, null, duplicatedEntitiesAsID); + + /// Returns a JSON [Map] for type [TestFranchiseWithReflection]. (Generated by [ReflectionFactory]) + Map? toJsonMap({bool duplicatedEntitiesAsID = false}) => + reflection.toJsonMap(duplicatedEntitiesAsID: duplicatedEntitiesAsID); + + /// Returns an encoded JSON [String] for type [TestFranchiseWithReflection]. (Generated by [ReflectionFactory]) + String toJsonEncoded( + {bool pretty = false, bool duplicatedEntitiesAsID = false}) => + reflection.toJsonEncoded( + pretty: pretty, duplicatedEntitiesAsID: duplicatedEntitiesAsID); + + /// Returns a JSON for type [TestFranchiseWithReflection] using the class fields. (Generated by [ReflectionFactory]) + Object? toJsonFromFields({bool duplicatedEntitiesAsID = false}) => reflection + .toJsonFromFields(duplicatedEntitiesAsID: duplicatedEntitiesAsID); +} + extension TestOpAWithReflection$reflectionExtension on TestOpAWithReflection { /// Returns a [ClassReflection] for type [TestOpAWithReflection]. (Generated by [ReflectionFactory]) ClassReflection get reflection => @@ -2983,6 +3023,7 @@ List _listSiblingsReflection() => [ TestUserWithReflection$reflection(), TestAddressWithReflection$reflection(), TestCompanyWithReflection$reflection(), + TestFranchiseWithReflection$reflection(), TestDataWithReflection$reflection(), TestDomainWithReflection$reflection(), TestOpWithReflection$reflection(), diff --git a/test/src/user_reflection_bridge.reflection.g.dart b/test/src/user_reflection_bridge.reflection.g.dart index 7da6c12..b3ca263 100644 --- a/test/src/user_reflection_bridge.reflection.g.dart +++ b/test/src/user_reflection_bridge.reflection.g.dart @@ -1,16 +1,29 @@ // // GENERATED CODE - DO NOT MODIFY BY HAND! -// BUILDER: reflection_factory/1.2.17 +// BUILDER: reflection_factory/1.2.18 // BUILD COMMAND: dart run build_runner build // // coverage:ignore-file +// ignore_for_file: unused_element // ignore_for_file: unnecessary_const // ignore_for_file: unnecessary_cast // ignore_for_file: unnecessary_type_check part of 'user_reflection_bridge.dart'; +typedef __TR = TypeReflection; +typedef __TI = TypeInfo; +typedef __PR = ParameterReflection; + +mixin __ReflectionMixin { + static final Version _version = Version.parse('1.2.18'); + + Version get reflectionFactoryVersion => _version; + + List siblingsReflection() => _siblingsReflection(); +} + // ignore: non_constant_identifier_names TestAddress TestAddress$fromJson(Map map) => TestAddress$reflection.staticInstance.fromJson(map); @@ -24,7 +37,8 @@ TestUserSimple TestUserSimple$fromJson(Map map) => TestUserSimple TestUserSimple$fromJsonEncoded(String jsonEncoded) => TestUserSimple$reflection.staticInstance.fromJsonEncoded(jsonEncoded); -class TestAddress$reflection extends ClassReflection { +class TestAddress$reflection extends ClassReflection + with __ReflectionMixin { TestAddress$reflection([TestAddress? object]) : super(TestAddress, 'TestAddress', object); @@ -41,9 +55,6 @@ class TestAddress$reflection extends ClassReflection { @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestAddress$reflection withObject([TestAddress? obj]) => TestAddress$reflection(obj); @@ -94,11 +105,9 @@ class TestAddress$reflection extends ClassReflection { TestAddress, '', () => (String state, String city) => TestAddress(state, city), - const [ - ParameterReflection( - TypeReflection.tString, 'state', false, true, null, null), - ParameterReflection( - TypeReflection.tString, 'city', false, true, null, null) + const <__PR>[ + __PR(__TR.tString, 'state', false, true), + __PR(__TR.tString, 'city', false, true) ], null, null, @@ -111,13 +120,6 @@ class TestAddress$reflection extends ClassReflection { @override List get classAnnotations => List.unmodifiable([]); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -145,7 +147,7 @@ class TestAddress$reflection extends ClassReflection { return FieldReflection( this, TestAddress, - TypeReflection.tString, + __TR.tString, 'state', false, (o) => () => o!.state as T, @@ -153,13 +155,12 @@ class TestAddress$reflection extends ClassReflection { obj, false, true, - null, ); case 'city': return FieldReflection( this, TestAddress, - TypeReflection.tString, + __TR.tString, 'city', false, (o) => () => o!.city as T, @@ -167,13 +168,12 @@ class TestAddress$reflection extends ClassReflection { obj, false, true, - null, ); case 'hashcode': return FieldReflection( this, TestAddress, - TypeReflection.tInt, + __TR.tInt, 'hashCode', false, (o) => () => o!.hashCode as T, @@ -212,7 +212,7 @@ class TestAddress$reflection extends ClassReflection { this, TestAddress, 'toJson', - TypeReflection.tMapStringDynamic, + __TR.tMapStringDynamic, false, (o) => o!.toJson, obj, @@ -235,7 +235,8 @@ class TestAddress$reflection extends ClassReflection { } } -class TestUserSimple$reflection extends ClassReflection { +class TestUserSimple$reflection extends ClassReflection + with __ReflectionMixin { TestUserSimple$reflection([TestUserSimple? object]) : super(TestUserSimple, 'TestUserSimple', object); @@ -252,9 +253,6 @@ class TestUserSimple$reflection extends ClassReflection { @override Version get languageVersion => Version.parse('2.17.0'); - @override - Version get reflectionFactoryVersion => Version.parse('1.2.17'); - @override TestUserSimple$reflection withObject([TestUserSimple? obj]) => TestUserSimple$reflection(obj); @@ -310,13 +308,10 @@ class TestUserSimple$reflection extends ClassReflection { '', () => (String name, String? email, String password) => TestUserSimple(name, email, password), - const [ - ParameterReflection( - TypeReflection.tString, 'name', false, true, null, null), - ParameterReflection( - TypeReflection.tString, 'email', true, true, null, null), - ParameterReflection( - TypeReflection.tString, 'password', false, true, null, null) + const <__PR>[ + __PR(__TR.tString, 'name', false, true), + __PR(__TR.tString, 'email', true, true), + __PR(__TR.tString, 'password', false, true) ], null, null, @@ -344,13 +339,6 @@ class TestUserSimple$reflection extends ClassReflection { List get classAnnotations => List.unmodifiable(_classAnnotations); - @override - List siblingsClassReflection() => - _siblingsReflection().whereType().toList(); - - @override - List siblingsReflection() => _siblingsReflection(); - @override List get supperTypes => const []; @@ -376,7 +364,7 @@ class TestUserSimple$reflection extends ClassReflection { return FieldReflection( this, TestUserSimple, - TypeReflection.tString, + __TR.tString, 'name', false, (o) => () => o!.name as T, @@ -392,7 +380,7 @@ class TestUserSimple$reflection extends ClassReflection { return FieldReflection( this, TestUserSimple, - TypeReflection.tString, + __TR.tString, 'email', true, (o) => () => o!.email as T, @@ -400,13 +388,12 @@ class TestUserSimple$reflection extends ClassReflection { obj, false, false, - null, ); case 'password': return FieldReflection( this, TestUserSimple, - TypeReflection.tString, + __TR.tString, 'password', false, (o) => () => o!.password as T, @@ -414,13 +401,12 @@ class TestUserSimple$reflection extends ClassReflection { obj, false, false, - null, ); case 'hashcode': return FieldReflection( this, TestUserSimple, - TypeReflection.tInt, + __TR.tInt, 'hashCode', false, (o) => () => o!.hashCode as T, @@ -448,7 +434,7 @@ class TestUserSimple$reflection extends ClassReflection { return FieldReflection( this, TestUserSimple, - TypeReflection.tDouble, + __TR.tDouble, 'version', false, (o) => () => TestUserSimple.version as T, @@ -464,7 +450,7 @@ class TestUserSimple$reflection extends ClassReflection { return FieldReflection( this, TestUserSimple, - TypeReflection.tBool, + __TR.tBool, 'withReflection', false, (o) => () => TestUserSimple.withReflection as T, @@ -496,21 +482,19 @@ class TestUserSimple$reflection extends ClassReflection { this, TestUserSimple, 'checkThePassword', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.checkThePassword, obj, false, - const [ - ParameterReflection( - TypeReflection.tString, 'password', false, true, null, [ + const <__PR>[ + __PR(__TR.tString, 'password', false, true, null, [ TestAnnotation(['parameter', 'password']) ]) ], null, - const { - 'ignoreCase': ParameterReflection( - TypeReflection.tBool, 'ignoreCase', false, false, false, null) + const { + 'ignoreCase': __PR(__TR.tBool, 'ignoreCase', false, false, false) }, [ TestAnnotation(['method', 'password checker']) @@ -520,7 +504,7 @@ class TestUserSimple$reflection extends ClassReflection { this, TestUserSimple, 'hasEmail', - TypeReflection.tBool, + __TR.tBool, false, (o) => o!.hasEmail, obj, @@ -534,7 +518,7 @@ class TestUserSimple$reflection extends ClassReflection { this, TestUserSimple, 'toString', - TypeReflection.tString, + __TR.tString, false, (o) => o!.toString, obj, @@ -561,15 +545,12 @@ class TestUserSimple$reflection extends ClassReflection { this, TestUserSimple, 'isVersion', - TypeReflection.tBool, + __TR.tBool, false, (o) => TestUserSimple.isVersion, null, true, - const [ - ParameterReflection( - TypeReflection.tDouble, 'ver', false, true, null, null) - ], + const <__PR>[__PR(__TR.tDouble, 'ver', false, true)], null, null, [ @@ -661,13 +642,12 @@ extension TestUserSimpleProxy$reflectionProxy on TestUserSimpleProxy { 'password': password, 'ignoreCase': ignoreCase, }, - TypeReflection.tBool); + __TR.tBool); return ret as dynamic; } bool hasEmail() { - var ret = - onCall(this, 'hasEmail', {}, TypeReflection.tBool); + var ret = onCall(this, 'hasEmail', {}, __TR.tBool); return ret as dynamic; } } @@ -681,7 +661,7 @@ extension TestUserSimpleProxyAsync$reflectionProxy on TestUserSimpleProxyAsync { 'password': password, 'ignoreCase': ignoreCase, }, - TypeReflection.tFutureBool); + __TR.tFutureBool); return ret is Future ? ret as Future : (ret is Future @@ -690,8 +670,7 @@ extension TestUserSimpleProxyAsync$reflectionProxy on TestUserSimpleProxyAsync { } Future hasEmail() { - var ret = onCall( - this, 'hasEmail', {}, TypeReflection.tFutureBool); + var ret = onCall(this, 'hasEmail', {}, __TR.tFutureBool); return ret is Future ? ret as Future : (ret is Future diff --git a/test/src/user_with_reflection.dart b/test/src/user_with_reflection.dart index 45faaa8..a37fc90 100644 --- a/test/src/user_with_reflection.dart +++ b/test/src/user_with_reflection.dart @@ -204,6 +204,34 @@ class TestCompanyWithReflection { } } +@EnableReflection() +class TestFranchiseWithReflection { + final String name; + + Map addresses; + + TestFranchiseWithReflection(this.name, this.addresses); + + @override + bool operator ==(Object other) => + identical(this, other) || + other is TestFranchiseWithReflection && + runtimeType == other.runtimeType && + name == other.name && + MapEquality() + .equals(addresses, other.addresses); + + @override + int get hashCode => + name.hashCode ^ + MapEquality().hash(addresses); + + @override + String toString() { + return 'TestFranchiseWithReflection{name: $name, addresses: $addresses}'; + } +} + @EnableReflection() class TestDataWithReflection { final String name;