2025-05-21 15:50:24 +03:00
|
|
|
//
|
|
|
|
|
// Copyright 2021 Sergey Penkovsky (sergey.penkovsky@gmail.com)
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
2025-08-08 23:24:05 +03:00
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2025-05-21 15:50:24 +03:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
|
2025-05-22 16:05:09 +03: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
2025-08-13 08:57:06 +03:00
|
|
|
/// BindParameterSpec
|
2025-05-21 15:50:24 +03: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
2025-08-13 08:57:06 +03:00
|
|
|
/// Describes a single parameter for a DI provider/factory/binding method,
|
|
|
|
|
/// specifying how that parameter is to be resolved in generated code.
|
2025-05-21 15:50:24 +03: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
2025-08-13 08:57:06 +03:00
|
|
|
/// 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
|
2025-05-22 16:05:09 +03:00
|
|
|
/// ----------------------------------------------------------------------------
|
2025-05-21 15:50:24 +03:00
|
|
|
class BindParameterSpec {
|
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
2025-08-13 08:57:06 +03:00
|
|
|
/// The type name of the parameter (e.g., 'UserRepository')
|
2025-05-21 15:50:24 +03:00
|
|
|
final String typeName;
|
|
|
|
|
|
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
2025-08-13 08:57:06 +03:00
|
|
|
/// If non-null, this is the named-key for DI resolution (from @named).
|
2025-05-21 15:50:24 +03:00
|
|
|
final String? named;
|
|
|
|
|
|
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
2025-08-13 08:57:06 +03:00
|
|
|
/// True if this parameter is a runtime param (annotated with @params and
|
|
|
|
|
/// filled by a runtime argument map).
|
2025-05-21 15:50:24 +03:00
|
|
|
final bool isParams;
|
|
|
|
|
|
|
|
|
|
BindParameterSpec(this.typeName, this.named, {this.isParams = false});
|
|
|
|
|
|
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
2025-08-13 08:57:06 +03:00
|
|
|
/// Generates Dart code to resolve this parameter in the DI container.
|
|
|
|
|
///
|
|
|
|
|
/// - For normal dependencies: resolves by type
|
|
|
|
|
/// - For named dependencies: resolves by type and name
|
|
|
|
|
/// - For @params: uses the supplied params variable (default 'args')
|
|
|
|
|
///
|
|
|
|
|
/// ## Example
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// final a = BindParameterSpec('Api', null); // normal
|
|
|
|
|
/// print(a.generateArg()); // currentScope.resolve<Api>()
|
2025-05-22 16:05:09 +03: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
2025-08-13 08:57:06 +03:00
|
|
|
/// final b = BindParameterSpec('Api', 'prod'); // named
|
|
|
|
|
/// print(b.generateArg()); // currentScope.resolve<Api>(named: 'prod')
|
2025-05-22 16:05:09 +03: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
2025-08-13 08:57:06 +03:00
|
|
|
/// final c = BindParameterSpec('Map<String,dynamic>', null, isParams: true); // params
|
|
|
|
|
/// print(c.generateArg()); // args
|
|
|
|
|
/// ```
|
2025-05-21 15:50:24 +03:00
|
|
|
String generateArg([String paramsVar = 'args']) {
|
|
|
|
|
if (isParams) {
|
|
|
|
|
return paramsVar;
|
|
|
|
|
}
|
|
|
|
|
if (named != null) {
|
|
|
|
|
return "currentScope.resolve<$typeName>(named: '$named')";
|
|
|
|
|
}
|
|
|
|
|
return "currentScope.resolve<$typeName>()";
|
|
|
|
|
}
|
|
|
|
|
}
|