Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 2.7.3

- `lib/src/reflection_factory_builder.dart`:
- `_EnumTree<T>`: Filtered enum entries to include only those marked as `const` when generating `_valuesByName` map.

- `pubspec.yaml`:
- Updated dependencies:
- `build`: ^4.0.3
- `analyzer`: ^8.4.1
- `dart_style`: ^3.1.3
- Updated dev_dependencies:
- `build_runner`: ^2.10.4
- `build_test`: ^3.5.4
- `test`: ^1.29.0

## 2.7.2

- `BasicDartType`: added `function`.
Expand Down
11 changes: 11 additions & 0 deletions bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

APIKEY=$1
shift # remove the first argument (API key) from "$@"

## dart pub global activate dart_bump

dart_bump . \
--extra-file "lib/src/reflection_factory_base.dart=String\\s+VERSION\\s+=\\s+['\"](.*)['\"]" \
--api-key $APIKEY \
"$@"
4 changes: 2 additions & 2 deletions example/reflection_factory_bridge_example.reflection.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/reflection_factory_example.reflection.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/reflection_factory_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'reflection_factory_utils.dart';
/// Class with all registered reflections ([ClassReflection]).
class ReflectionFactory {
// ignore: constant_identifier_names
static const String VERSION = '2.7.2';
static const String VERSION = '2.7.3';

static final ReflectionFactory _instance = ReflectionFactory._();

Expand Down
1 change: 1 addition & 0 deletions lib/src/reflection_factory_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,7 @@ class _EnumTree<T> extends RecursiveElementVisitor2<T> {

var enumsEntries = entries.entries
.where((e) => e.value.thisType == enumType)
.where((e) => e.value.isConst)
.sortedBy((e) => e.key)
.toList();

Expand Down
14 changes: 7 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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: 2.7.2
version: 2.7.3
homepage: https://github.com/gmpassos/reflection_factory

environment:
sdk: '>=3.9.0 <4.0.0'

dependencies:
build: ^4.0.2
analyzer: ^8.4.0
dart_style: ^3.1.2
build: ^4.0.3
analyzer: ^8.4.1
dart_style: ^3.1.3
meta: ^1.17.0
mime: ^2.0.0
base_codecs: ^1.0.1
Expand All @@ -21,12 +21,12 @@ dependencies:
logging: ^1.3.0

dev_dependencies:
build_runner: ^2.10.1
build_test: ^3.5.1
build_runner: ^2.10.4
build_test: ^3.5.4
lints: ^6.0.0
pubspec_parse: ^1.5.0
data_serializer: ^1.2.1
#dependency_validator: ^5.0.2
test: ^1.26.3
test: ^1.29.0
coverage: ^1.15.0
benchmark: ^0.3.0
75 changes: 75 additions & 0 deletions test/reflection_factory_build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,81 @@ void main() {
},
);

test('EnableReflection + advanced enum', () async {
var builder = ReflectionBuilder(verbose: true);

var sourceAssets = {
'$_pkgName|lib/status.dart': '''

import 'package:reflection_factory/reflection_factory.dart';

part 'status.reflection.g.dart';

@EnableReflection()
enum Status {
a(10),
b(20);

static final defaultStatus = Status.a;

final int id;

const Status(this.id);

bool get isFoo => true;

int calc(int m) => 10 * m;
}

''',
};

final readerWriter = TestReaderWriter(rootPackage: _pkgName);
await readerWriter.testing.loadIsolateSources();

await testBuilder(
builder,
sourceAssets,
readerWriter: readerWriter,
generateFor: {'$_pkgName|lib/status.dart'},
outputs: {
'$_pkgName|lib/status.reflection.g.dart': decodedMatches(
allOf(
allOf(
contains('GENERATED CODE - DO NOT MODIFY BY HAND'),
contains(
'BUILDER: reflection_factory/${ReflectionFactory.VERSION}',
),
contains("part of 'status.dart'"),
),
allOf([
contains('Status\$reflection extends EnumReflection<Status>'),
contains('Status\$reflectionExtension'),
isNot(contains('Foo\$reflection extends')),
isNot(contains('Foo\$reflectionExtension')),
]),
allOf([
contains(
'final Expando<Status\$reflection> _objectReflections',
),
contains('factory Status\$reflection([Status? object]) {'),
contains(
' _valuesByName = const <String, Status>{\n'
' \'a\': Status.a,\n'
' \'b\': Status.b,\n'
' };\n',
),
contains('_fieldsNames = const <String>[\'id\', \'isFoo\'];'),
]),
),
),
},
onLog: (msg) {
_printToConsole(msg);
},
);
});

test('ReflectionBridge', () async {
var builder = ReflectionBuilder(verbose: true);

Expand Down
4 changes: 2 additions & 2 deletions test/src/reflection/user_with_reflection.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/src/user_reflection_bridge.reflection.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.