start implement generator code

This commit is contained in:
Sergey Penkovsky
2025-05-16 09:30:30 +03:00
parent 9b0741199c
commit b906e927c3
29 changed files with 535 additions and 102 deletions

View File

@@ -1,6 +0,0 @@
// TODO: Put public facing types in this file.
/// Checks if you are awesome. Spoiler: you are.
class Awesome {
bool get isAwesome => true;
}

View File

@@ -1,28 +0,0 @@
import 'dart:async';
import 'package:build/build.dart';
import 'package:source_gen/source_gen.dart';
import 'package:cherrypick_annotations/cherrypick_annotations.dart';
import 'package:analyzer/dart/element/element.dart';
class InjectGenerator extends GeneratorForAnnotation<Inject> {
@override
FutureOr<String> generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep) {
if (element is! FieldElement) {
throw InvalidGenerationSourceError(
'Генератор не может работать с `${element.name}`.',
);
}
final named = annotation.peek('named')?.stringValue;
final resolveSnippet = named == null
? 'CherryPickProvider.of(context).openRootScope().resolve<${element.type}>()'
: 'CherryPickProvider.of(context).openRootScope().resolve<${element.type}>(named: \'$named\')';
return '''
void _initState(BuildContext context) {
${element.name} = $resolveSnippet;
}
''';
}
}