Skip to content

Commit

Permalink
Merge v1.2.18
Browse files Browse the repository at this point in the history
- `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
  • Loading branch information
gmpassos authored Jan 4, 2023
2 parents 92c4e73 + 7061d6d commit 3c14474
Show file tree
Hide file tree
Showing 17 changed files with 1,342 additions and 694 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 23 additions & 28 deletions example/reflection_factory_bridge_example.reflection.g.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
//
// 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<T> = TypeReflection<T>;
typedef __TI<T> = TypeInfo<T>;
typedef __PR = ParameterReflection;

mixin __ReflectionMixin {
static final Version _version = Version.parse('1.2.18');

Version get reflectionFactoryVersion => _version;

List<Reflection> siblingsReflection() => _siblingsReflection();
}

// ignore: non_constant_identifier_names
User User$fromJson(Map<String, Object?> map) =>
User$reflection.staticInstance.fromJson(map);
// ignore: non_constant_identifier_names
User User$fromJsonEncoded(String jsonEncoded) =>
User$reflection.staticInstance.fromJsonEncoded(jsonEncoded);

class User$reflection extends ClassReflection<User> {
class User$reflection extends ClassReflection<User> with __ReflectionMixin {
User$reflection([User? object]) : super(User, 'User', object);

static bool _registered = false;
Expand All @@ -34,9 +47,6 @@ class User$reflection extends ClassReflection<User> {
@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);

Expand Down Expand Up @@ -86,11 +96,9 @@ class User$reflection extends ClassReflection<User> {
User,
'',
() => (String? email, String pass) => User(email, pass),
const <ParameterReflection>[
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,
Expand All @@ -106,13 +114,6 @@ class User$reflection extends ClassReflection<User> {
@override
List<Object> get classAnnotations => List<Object>.unmodifiable(<Object>[]);

@override
List<ClassReflection> siblingsClassReflection() =>
_siblingsReflection().whereType<ClassReflection>().toList();

@override
List<Reflection> siblingsReflection() => _siblingsReflection();

@override
List<Type> get supperTypes => const <Type>[];

Expand All @@ -136,43 +137,40 @@ class User$reflection extends ClassReflection<User> {
return FieldReflection<User, T>(
this,
User,
TypeReflection.tString,
__TR.tString,
'email',
true,
(o) => () => o!.email as T,
(o) => (T? v) => o!.email = v as String?,
obj,
false,
false,
null,
);
case 'pass':
return FieldReflection<User, T>(
this,
User,
TypeReflection.tString,
__TR.tString,
'pass',
false,
(o) => () => o!.pass as T,
(o) => (T? v) => o!.pass = v as String,
obj,
false,
false,
null,
);
case 'hasemail':
return FieldReflection<User, T>(
this,
User,
TypeReflection.tBool,
__TR.tBool,
'hasEmail',
false,
(o) => () => o!.hasEmail as T,
null,
obj,
false,
false,
null,
);
default:
return null;
Expand Down Expand Up @@ -202,15 +200,12 @@ class User$reflection extends ClassReflection<User> {
this,
User,
'checkPassword',
TypeReflection.tBool,
__TR.tBool,
false,
(o) => o!.checkPassword,
obj,
false,
const <ParameterReflection>[
ParameterReflection(
TypeReflection.tString, 'pass', false, true, null, null)
],
const <__PR>[__PR(__TR.tString, 'pass', false, true)],
null,
null,
null);
Expand Down
51 changes: 23 additions & 28 deletions example/reflection_factory_example.reflection.g.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
//
// 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<T> = TypeReflection<T>;
typedef __TI<T> = TypeInfo<T>;
typedef __PR = ParameterReflection;

mixin __ReflectionMixin {
static final Version _version = Version.parse('1.2.18');

Version get reflectionFactoryVersion => _version;

List<Reflection> siblingsReflection() => _siblingsReflection();
}

// ignore: non_constant_identifier_names
User User$fromJson(Map<String, Object?> map) =>
User$reflection.staticInstance.fromJson(map);
// ignore: non_constant_identifier_names
User User$fromJsonEncoded(String jsonEncoded) =>
User$reflection.staticInstance.fromJsonEncoded(jsonEncoded);

class User$reflection extends ClassReflection<User> {
class User$reflection extends ClassReflection<User> with __ReflectionMixin {
User$reflection([User? object]) : super(User, 'User', object);

static bool _registered = false;
Expand All @@ -34,9 +47,6 @@ class User$reflection extends ClassReflection<User> {
@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);

Expand Down Expand Up @@ -86,11 +96,9 @@ class User$reflection extends ClassReflection<User> {
User,
'',
() => (String? email, String pass) => User(email, pass),
const <ParameterReflection>[
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,
Expand All @@ -106,13 +114,6 @@ class User$reflection extends ClassReflection<User> {
@override
List<Object> get classAnnotations => List<Object>.unmodifiable(<Object>[]);

@override
List<ClassReflection> siblingsClassReflection() =>
_siblingsReflection().whereType<ClassReflection>().toList();

@override
List<Reflection> siblingsReflection() => _siblingsReflection();

@override
List<Type> get supperTypes => const <Type>[];

Expand All @@ -136,43 +137,40 @@ class User$reflection extends ClassReflection<User> {
return FieldReflection<User, T>(
this,
User,
TypeReflection.tString,
__TR.tString,
'email',
true,
(o) => () => o!.email as T,
(o) => (T? v) => o!.email = v as String?,
obj,
false,
false,
null,
);
case 'pass':
return FieldReflection<User, T>(
this,
User,
TypeReflection.tString,
__TR.tString,
'pass',
false,
(o) => () => o!.pass as T,
(o) => (T? v) => o!.pass = v as String,
obj,
false,
false,
null,
);
case 'hasemail':
return FieldReflection<User, T>(
this,
User,
TypeReflection.tBool,
__TR.tBool,
'hasEmail',
false,
(o) => () => o!.hasEmail as T,
null,
obj,
false,
false,
null,
);
default:
return null;
Expand Down Expand Up @@ -202,15 +200,12 @@ class User$reflection extends ClassReflection<User> {
this,
User,
'checkPassword',
TypeReflection.tBool,
__TR.tBool,
false,
(o) => o!.checkPassword,
obj,
false,
const <ParameterReflection>[
ParameterReflection(
TypeReflection.tString, 'pass', false, true, null, null)
],
const <__PR>[__PR(__TR.tString, 'pass', false, true)],
null,
null,
null);
Expand Down
15 changes: 15 additions & 0 deletions lib/src/analyzer/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -40,6 +41,20 @@ class LibraryReader {
}
}

/// All of the elements names in this library
/// (classes, enums, mixins, functions, extensions, typeAliases, topLevelVariables).
Iterable<String> get elementsNames => element.units
.expand((CompilationUnitElement cu) => <String?>[
...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<ClassElement> get classes =>
element.units.expand((CompilationUnitElement cu) => cu.classes);
Expand Down
Loading

0 comments on commit 3c14474

Please sign in to comment.