Skip to content
Closed
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
1 change: 0 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ dependencies:

dev_dependencies:
build_runner:
build_resolvers:
functional_data_generator:
4 changes: 4 additions & 0 deletions functional_data_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.2

- Update analyzer dependency to `^8.0.0`

## 2.2.1

- Update analyzer dependency to `^7.4.0`
Expand Down
23 changes: 11 additions & 12 deletions functional_data_generator/lib/builder.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:io';

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:build/build.dart';
import 'package:collection/collection.dart';
import 'package:functional_data/functional_data.dart';
Expand All @@ -12,7 +12,7 @@ Builder functionalData(BuilderOptions options) => SharedPartBuilder([FunctionalD

class FunctionalDataGenerator extends GeneratorForAnnotation<FunctionalData> {
@override
Future<String> generateForAnnotatedElement(Element2 element, ConstantReader annotation, BuildStep buildStep) =>
Future<String> generateForAnnotatedElement(Element element, ConstantReader annotation, BuildStep buildStep) =>
_generateDataType(element, annotation, buildStep);
}

Expand All @@ -39,8 +39,8 @@ class Pair<T, S> {
final S second;
}

Future<String> _generateDataType(Element2 element, ConstantReader annotation, BuildStep buildStep) async {
if (element is! ClassElement2) {
Future<String> _generateDataType(Element element, ConstantReader annotation, BuildStep buildStep) async {
if (element is! ClassElement) {
throw Exception('FunctionalData annotation must only be used on classes');
}

Expand All @@ -63,26 +63,25 @@ Future<String> _generateDataType(Element2 element, ConstantReader annotation, Bu
throw Exception('[$element]: generateLenses requires copyWith to be generated');
}

final className = (element.name3 ?? '').replaceAll('\$', '');
final className = (element.name ?? '').replaceAll('\$', '');

final classElement = element;

// The one that can be used to specify every field
final genericConstructor = classElement.constructors2.firstWhere((element) => element.name3 == 'new');
final positionalFields =
genericConstructor.formalParameters.where((p) => p.isPositional).map((p) => p.name3).toList();
final genericConstructor = classElement.constructors.firstWhere((element) => element.name == 'new');
final positionalFields = genericConstructor.formalParameters.where((p) => p.isPositional).map((p) => p.name).toList();

final fieldsWithIndex =
await Future.wait(classElement.fields2.where((f) => !f.isSynthetic && !f.isStatic).map((f) async {
await Future.wait(classElement.fields.where((f) => !f.isSynthetic && !f.isStatic).map((f) async {
final declaration = await buildStep.resolver.astNodeFor(f.firstFragment) as VariableDeclaration?;
final declarationList = declaration?.parent as VariableDeclarationList?;
final positionalIndex = positionalFields.indexOf(f.name3);
final positionalIndex = positionalFields.indexOf(f.name);
return Pair(
positionalIndex == -1 ? 9999 : positionalIndex,
Field(
f.name3 ?? '',
f.name ?? '',
declarationList?.type?.toSource() ?? 'dynamic',
_getCustomEquality(f.metadata2.annotations),
_getCustomEquality(f.metadata.annotations),
isPositional: positionalIndex != -1,
),
);
Expand Down
11 changes: 5 additions & 6 deletions functional_data_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: functional_data_generator
version: 2.2.1
version: 2.2.2
description: >-
Simple and non-intrusive code generator for boilerplate of data types.
homepage: https://github.com/spkersten/dart_functional_data
Expand All @@ -8,13 +8,12 @@ environment:
sdk: '>=2.19.0 <4.0.0'

dependencies:
analyzer: '^7.4.0'
build: ^3.0.0
analyzer: '^8.0.0'
build: ^4.0.0
collection: ^1.15.0
functional_data: ^1.1.1
source_gen: ^3.1.0
source_gen: ^4.0.0
yaml: ^3.1.2

dev_dependencies:
build_resolvers: "^3.0.2"
build_runner: ^2.2.0
build_runner: ^2.10.4