diff --git a/lib/generator.dart b/lib/generator.dart index 5bdd92e..657e1c4 100644 --- a/lib/generator.dart +++ b/lib/generator.dart @@ -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'; @@ -37,9 +38,9 @@ ActionsClass _actionsClassFromElement(ClassElement element) => ActionsClass( ); Iterable _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 _actionsFromElement(ClassElement element) => element.fields .where(_isActionDispatcher) @@ -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( @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml index 9c97c44..93a718e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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