Skip to content

Commit

Permalink
v1.0.1-rc1
Browse files Browse the repository at this point in the history
- @EnableReflection:
  - Added `reflectionClassName`, `reflectionExtensionName`.
- @ReflectionBridge:
  - Added `bridgeExtensionName`, `reflectionClassNames`, `reflectionExtensionNames`.
- Builder: improved console output and verbose mode.
- Improved tests.
  • Loading branch information
gmpassos committed Aug 23, 2021
1 parent 1533d60 commit 08954ad
Show file tree
Hide file tree
Showing 14 changed files with 841 additions and 170 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.0.1

- @EnableReflection:
- Added `reflectionClassName`, `reflectionExtensionName`.
- @ReflectionBridge:
- Added `bridgeExtensionName`, `reflectionClassNames`, `reflectionExtensionNames`.
- Builder: improved console output and verbose mode.
- Improved tests.

## 1.0.0

- Support for Class reflection:
Expand Down
30 changes: 14 additions & 16 deletions example/reflection_factory_bridge_example.reflection.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@

part of 'reflection_factory_bridge_example.dart';

// ignore: camel_case_extensions
extension ReflectionExtension$User on User {
ClassReflection<User> get reflection => _ReflectionClass$User(this);

Map<String, dynamic> toJson() => reflection.toJson();

String toJsonEncoded() => reflection.toJsonEncoded();
}

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

@override
_ReflectionClass$User withObject([User? obj]) => _ReflectionClass$User(obj);
User$reflection withObject([User? obj]) => User$reflection(obj);

@override
Version get languageVersion => Version.parse('2.13.0');

@override
List<String> get fieldsNames => const <String>['email', 'pass', 'hasEmail'];
List<String> get fieldsNames => const <String>['email', 'hasEmail', 'pass'];

@override
FieldReflection<User, T>? field<T>(String fieldName, [User? obj]) {
Expand Down Expand Up @@ -108,12 +99,19 @@ class _ReflectionClass$User extends ClassReflection<User> {
}
}

extension ReflectionBridgeExtension$UserReflectionBridge
on UserReflectionBridge {
extension User$reflectionExtension on User {
ClassReflection<User> get reflection => User$reflection(this);

Map<String, dynamic> toJson() => reflection.toJson();

String toJsonEncoded() => reflection.toJsonEncoded();
}

extension UserReflectionBridge$reflectionExtension on UserReflectionBridge {
ClassReflection<T> reflection<T>([T? obj]) {
switch (T) {
case User:
return _ReflectionClass$User(obj as User?) as ClassReflection<T>;
return User$reflection(obj as User?) as ClassReflection<T>;
default:
throw UnsupportedError('<$runtimeType> No reflection for Type: $T');
}
Expand Down
25 changes: 12 additions & 13 deletions example/reflection_factory_example.reflection.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@

part of 'reflection_factory_example.dart';

// ignore: camel_case_extensions
extension ReflectionExtension$User on User {
ClassReflection<User> get reflection => _ReflectionClass$User(this);

Map<String, dynamic> toJson() => reflection.toJson();

String toJsonEncoded() => reflection.toJsonEncoded();
}

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

@override
_ReflectionClass$User withObject([User? obj]) => _ReflectionClass$User(obj);
User$reflection withObject([User? obj]) => User$reflection(obj);

@override
Version get languageVersion => Version.parse('2.13.0');

@override
List<String> get fieldsNames => const <String>['email', 'pass', 'hasEmail'];
List<String> get fieldsNames => const <String>['email', 'hasEmail', 'pass'];

@override
FieldReflection<User, T>? field<T>(String fieldName, [User? obj]) {
Expand Down Expand Up @@ -107,3 +98,11 @@ class _ReflectionClass$User extends ClassReflection<User> {
return null;
}
}

extension User$reflectionExtension on User {
ClassReflection<User> get reflection => User$reflection(this);

Map<String, dynamic> toJson() => reflection.toJson();

String toJsonEncoded() => reflection.toJsonEncoded();
}
36 changes: 34 additions & 2 deletions lib/src/reflection_factory_annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,45 @@ import 'package:meta/meta_meta.dart';
/// Enables reflection for a class.
@Target({TargetKind.classType})
class EnableReflection {
const EnableReflection();
/// Name of the generated reflection class (optional).
/// - Defaults to `class name` + `$reflection`.
/// - Example: `User$reflection`
final String reflectionClassName;

/// Name of the generated reflection extension (optional).
/// - Defaults to `class name` + `$reflectionExtension`.
/// - Example: `User$reflectionExtension`
final String reflectionExtensionName;

const EnableReflection({
this.reflectionClassName = '',
this.reflectionExtensionName = '',
});
}

/// Indicates that a class is a reflection bridge of [Type]s in [classesTypes] [List].
@Target({TargetKind.classType})
class ReflectionBridge {
/// List of classes to generate/enable reflection.
final List<Type> classesTypes;

const ReflectionBridge(this.classesTypes);
/// Name of the generated reflection bridge extension (optional).
/// - Defaults to `bridge class name` + `$reflectionExtension`.
/// - Example: `UserBridge$reflectionExtension`
final String bridgeExtensionName;

/// Name of the generated reflection class for [classesTypes] (optional).
/// See [EnableReflection.reflectionClassName].
final Map<Type, String> reflectionClassNames;

/// Name of the generated reflection extension for [classesTypes] (optional).
/// See [EnableReflection.reflectionExtensionName].
final Map<Type, String> reflectionExtensionNames;

const ReflectionBridge(
this.classesTypes, {
this.bridgeExtensionName = '',
this.reflectionClassNames = const <Type, String>{},
this.reflectionExtensionNames = const <Type, String>{},
});
}
Loading

0 comments on commit 08954ad

Please sign in to comment.