mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-25 22:36:44 +00:00
docs(generator): improve and unify English documentation and examples for all DI source files
- Added comprehensive English documentation for all DI generator and support files: * inject_generator.dart — full class/method doc-comments, usage samples * module_generator.dart — doc-comments, feature explanation, complete example * src/annotation_validator.dart — class and detailed static method descriptions * src/type_parser.dart — doc, example for ParsedType and TypeParser, specific codegen notes * src/bind_spec.dart — interface, static factory, and codegen docs with DI scenarios * src/bind_parameters_spec.dart — details and samples for code generation logic * src/metadata_utils.dart — full doc and examples for annotation utilities * src/exceptions.dart — user- and contributor-friendly errors, structured output, category explanations * src/generated_class.dart — usage-centric doc-comments, example of resulting generated DI class - Removed Russian/duplicate comments for full clarity and maintainability - Ensured that new and existing contributors can easily extend and maintain DI code generation logic BREAKING CHANGE: All documentation now English-only; comments include usage examples for each principal structure or routine See #docs, #generator, #cherrypick
This commit is contained in:
@@ -12,57 +12,59 @@
|
||||
//
|
||||
|
||||
/// ----------------------------------------------------------------------------
|
||||
/// BindParameterSpec - describes a single method parameter and how to resolve it.
|
||||
/// BindParameterSpec
|
||||
///
|
||||
/// ENGLISH
|
||||
/// Describes a single parameter for a provider/binding method in the DI system.
|
||||
/// Stores the parameter type, its optional `@named` key for named resolution,
|
||||
/// and whether it is a runtime "params" argument. Used to generate code that
|
||||
/// resolves dependencies from the DI scope:
|
||||
/// - If the parameter is a dependency type (e.g. SomeDep), emits:
|
||||
/// currentScope.resolve<SomeDep>()
|
||||
/// - If the parameter is named, emits:
|
||||
/// currentScope.resolve<SomeDep>(named: 'yourName')
|
||||
/// - If it's a runtime parameter (e.g. via @params()), emits:
|
||||
/// args
|
||||
/// Describes a single parameter for a DI provider/factory/binding method,
|
||||
/// specifying how that parameter is to be resolved in generated code.
|
||||
///
|
||||
/// RUSSIAN
|
||||
/// Описывает один параметр метода в DI, и его способ разрешения из контейнера.
|
||||
/// Сохраняет имя типа, дополнительное имя (если параметр аннотирован через @named),
|
||||
/// и признак runtime-параметра (@params).
|
||||
/// Для обычной зависимости типа (например, SomeDep) генерирует строку вида:
|
||||
/// currentScope.resolve<SomeDep>()
|
||||
/// Для зависимости с именем:
|
||||
/// currentScope.resolve<SomeDep>(named: 'имя')
|
||||
/// Для runtime-параметра:
|
||||
/// args
|
||||
/// Stores the parameter's type name, optional `@named` identifier (for named DI resolution),
|
||||
/// and a flag for runtime (@params) arguments. Used in CherryPick generator
|
||||
/// for creating argument lists when invoking factories or provider methods.
|
||||
///
|
||||
/// ## Example usage
|
||||
/// ```dart
|
||||
/// // Binding method: @provide() Logger provideLogger(@named('debug') Config config, @params Map<String, dynamic> args)
|
||||
/// final namedParam = BindParameterSpec('Config', 'debug');
|
||||
/// final runtimeParam = BindParameterSpec('Map<String, dynamic>', null, isParams: true);
|
||||
/// print(namedParam.generateArg()); // prints: currentScope.resolve<Config>(named: 'debug')
|
||||
/// print(runtimeParam.generateArg()); // prints: args
|
||||
/// ```
|
||||
///
|
||||
/// ## Code generation logic
|
||||
/// - Injected: currentScope.resolve<Service>()
|
||||
/// - Named: currentScope.resolve<Service>(named: 'name')
|
||||
/// - @params: args
|
||||
/// ----------------------------------------------------------------------------
|
||||
class BindParameterSpec {
|
||||
/// Type name of the parameter (e.g. SomeService)
|
||||
/// Имя типа параметра (например, SomeService)
|
||||
/// The type name of the parameter (e.g., 'UserRepository')
|
||||
final String typeName;
|
||||
|
||||
/// Optional name for named resolution (from @named)
|
||||
/// Необязательное имя для разрешения по имени (если аннотировано через @named)
|
||||
/// If non-null, this is the named-key for DI resolution (from @named).
|
||||
final String? named;
|
||||
|
||||
/// True if this parameter uses @params and should be provided from runtime args
|
||||
/// Признак, что параметр — runtime (через @params)
|
||||
/// True if this parameter is a runtime param (annotated with @params and
|
||||
/// filled by a runtime argument map).
|
||||
final bool isParams;
|
||||
|
||||
BindParameterSpec(this.typeName, this.named, {this.isParams = false});
|
||||
|
||||
/// --------------------------------------------------------------------------
|
||||
/// generateArg
|
||||
/// Generates Dart code to resolve this parameter in the DI container.
|
||||
///
|
||||
/// ENGLISH
|
||||
/// Generates Dart code for resolving the dependency from the DI scope,
|
||||
/// considering type, named, and param-argument.
|
||||
/// - For normal dependencies: resolves by type
|
||||
/// - For named dependencies: resolves by type and name
|
||||
/// - For @params: uses the supplied params variable (default 'args')
|
||||
///
|
||||
/// RUSSIAN
|
||||
/// Генерирует строку для получения зависимости из DI scope (с учётом имени
|
||||
/// и типа параметра или runtime-режима @params).
|
||||
/// --------------------------------------------------------------------------
|
||||
/// ## Example
|
||||
/// ```dart
|
||||
/// final a = BindParameterSpec('Api', null); // normal
|
||||
/// print(a.generateArg()); // currentScope.resolve<Api>()
|
||||
///
|
||||
/// final b = BindParameterSpec('Api', 'prod'); // named
|
||||
/// print(b.generateArg()); // currentScope.resolve<Api>(named: 'prod')
|
||||
///
|
||||
/// final c = BindParameterSpec('Map<String,dynamic>', null, isParams: true); // params
|
||||
/// print(c.generateArg()); // args
|
||||
/// ```
|
||||
String generateArg([String paramsVar = 'args']) {
|
||||
if (isParams) {
|
||||
return paramsVar;
|
||||
|
||||
Reference in New Issue
Block a user