chore(generator): improve annotation validation, unify async type handling, and refactor BindSpec creation

- Enhance annotation validation in DI code generation.
- Move from manual Future<T> extraction to unified type parsing.
- Refactor BindSpec creation logic to provide better error messages and type consistency.
- Add missing source files for exceptions, annotation validation, and type parsing.

BREAKING CHANGE:
Invalid annotation combinations now produce custom generator errors. Async detection is now handled via unified type parser.
This commit is contained in:
Sergey Penkovsky
2025-07-25 11:58:56 +03:00
parent c722ad0c07
commit feb7258302
6 changed files with 1070 additions and 81 deletions

View File

@@ -49,10 +49,15 @@ class GeneratedClass {
/// Список всех обнаруженных биндингов
final List<BindSpec> binds;
/// Source file name for the part directive
/// Имя исходного файла для part директивы
final String sourceFile;
GeneratedClass(
this.className,
this.generatedClassName,
this.binds,
this.sourceFile,
);
/// -------------------------------------------------------------------------
@@ -72,13 +77,15 @@ class GeneratedClass {
final className = element.displayName;
// Generated class name with '$' prefix (standard for generated Dart code).
final generatedClassName = r'$' + className;
// Get source file name
final sourceFile = element.source.shortName;
// Collect bindings for all non-abstract methods.
final binds = element.methods
.where((m) => !m.isAbstract)
.map(BindSpec.fromMethod)
.toList();
return GeneratedClass(className, generatedClassName, binds);
return GeneratedClass(className, generatedClassName, binds, sourceFile);
}
/// -------------------------------------------------------------------------
@@ -95,11 +102,10 @@ class GeneratedClass {
/// и регистрирует все зависимости через методы bind<Type>()...
/// -------------------------------------------------------------------------
String generate() {
final buffer = StringBuffer();
buffer.writeln('final class $generatedClassName extends $className {');
buffer.writeln(' @override');
buffer.writeln(' void builder(Scope currentScope) {');
final buffer = StringBuffer()
..writeln('final class $generatedClassName extends $className {')
..writeln(' @override')
..writeln(' void builder(Scope currentScope) {');
// For each binding, generate bind<Type>() code string.
// Для каждого биндинга — генерируем строку bind<Type>()...
@@ -107,8 +113,9 @@ class GeneratedClass {
buffer.writeln(bind.generateBind(4));
}
buffer.writeln(' }');
buffer.writeln('}');
buffer
..writeln(' }')
..writeln('}');
return buffer.toString();
}