Skip to content
Open
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
20 changes: 10 additions & 10 deletions lib/generator.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';

import 'package:analyzer/dart/element/element.dart';
import 'package:build/build.dart';
import 'package:source_gen/source_gen.dart';
Expand Down Expand Up @@ -37,9 +38,9 @@ ActionsClass _actionsClassFromElement(ClassElement element) => ActionsClass(
);

Iterable<ComposedActionClass> _composedActionClasses(ClassElement element) =>
element.fields.where((f) => _isReduxActions(f.type.element)).map((f) =>
ComposedActionClass(
f.name, f.type.getDisplayString(withNullability: true)));
element.fields
.where((f) => _isReduxActions(f.type.element))
.map((f) => ComposedActionClass(f.name, f.type.element!.name!));

Iterable<Action> _actionsFromElement(ClassElement element) => element.fields
.where(_isActionDispatcher)
Expand All @@ -63,16 +64,16 @@ String _fieldType(ClassElement element, FieldElement field) {
if (field.isSynthetic) {
return _syntheticFieldType(element, field);
}
return _getGenerics(field.source!.contents.data, field.nameOffset);
return _getGenerics(field.source?.contents.data, field.nameOffset);
}

String _syntheticFieldType(ClassElement element, FieldElement field) {
final method = element.getGetter(field.name);
return _getGenerics(method!.source.contents.data, method.nameOffset);
return _getGenerics(method?.source.contents.data, method?.nameOffset ?? 0);
}

String _getGenerics(String source, int nameOffset) {
final trimAfterName = source.substring(0, nameOffset);
String _getGenerics(String? source, int nameOffset) {
final trimAfterName = source?.substring(0, nameOffset) ?? '';
final trimBeforeActionDispatcher =
trimAfterName.substring(trimAfterName.lastIndexOf('ActionDispatcher'));
return trimBeforeActionDispatcher.substring(
Expand All @@ -83,9 +84,8 @@ String _getGenerics(String source, int nameOffset) {
bool _isReduxActions(Element? element) =>
element is ClassElement && _hasSuperType(element, 'ReduxActions');

bool _isActionDispatcher(FieldElement element) => element.type
.getDisplayString(withNullability: true)
.startsWith('ActionDispatcher<');
bool _isActionDispatcher(FieldElement element) =>
element.type.element?.name == 'ActionDispatcher';

bool _hasSuperType(ClassElement classElement, String type) =>
classElement.allSupertypes
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: built_redux
version: 8.0.0
version: 8.0.1
description: A state management library written in dart that enforces immutability
homepage: https://github.com/davidmarne/built_redux
dependencies:
analyzer: ^1.0.0
build: ">=1.0.0 <3.0.0"
analyzer: ">=1.8.0 <3.0.0"
build: ^2.0.0
built_collection: ^5.0.0
built_value: ^8.0.0
source_gen: ">=0.9.4 <2.0.0"
test: ^1.16.0

dev_dependencies:
build_runner: ^1.7.1
build_runner: ">=1.0.0 <3.0.0"
build_test: ">=1.2.0 <3.0.0"
built_value_generator: ^8.0.0
build_web_compilers: ^2.7.1
Expand Down