2025-07-25 11:58:56 +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-07-25 11:58:56 +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.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import 'package:analyzer/dart/element/element.dart';
|
|
|
|
|
import 'package:source_gen/source_gen.dart';
|
|
|
|
|
|
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
|
|
|
/// ---------------------------------------------------------------------------
|
|
|
|
|
/// CherryPickGeneratorException
|
|
|
|
|
///
|
|
|
|
|
/// The base exception for all CherryPick code generation and annotation
|
|
|
|
|
/// validation errors. This exception provides enhanced diagnostics including
|
|
|
|
|
/// the error category, helpful suggestions, and additional debugging context.
|
|
|
|
|
///
|
|
|
|
|
/// All errors are structured to be as helpful as possible for users
|
|
|
|
|
/// running build_runner and for CherryPick contributors debugging generators.
|
|
|
|
|
///
|
|
|
|
|
/// ## Example usage:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// if (someErrorCondition) {
|
|
|
|
|
/// throw AnnotationValidationException(
|
|
|
|
|
/// 'Custom message about what went wrong',
|
|
|
|
|
/// element: methodElement,
|
|
|
|
|
/// suggestion: 'Add @provide() or @instance() annotation',
|
|
|
|
|
/// context: {'found_annotations': annotations},
|
|
|
|
|
/// );
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
/// ---------------------------------------------------------------------------
|
2025-07-25 11:58:56 +03:00
|
|
|
class CherryPickGeneratorException extends InvalidGenerationSourceError {
|
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
|
|
|
/// A string describing the error category (for grouping).
|
2025-07-25 11:58:56 +03:00
|
|
|
final String category;
|
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
|
|
|
|
|
|
|
|
/// An optional suggestion string for resolving the error.
|
2025-07-25 11:58:56 +03:00
|
|
|
final String? suggestion;
|
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
|
|
|
|
|
|
|
|
/// Arbitrary key-value map for additional debugging information.
|
2025-07-25 11:58:56 +03:00
|
|
|
final Map<String, dynamic>? context;
|
|
|
|
|
|
|
|
|
|
CherryPickGeneratorException(
|
|
|
|
|
String message, {
|
|
|
|
|
required Element element,
|
|
|
|
|
required this.category,
|
|
|
|
|
this.suggestion,
|
|
|
|
|
this.context,
|
|
|
|
|
}) : super(
|
|
|
|
|
_formatMessage(message, category, suggestion, context, element),
|
|
|
|
|
element: element,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
static String _formatMessage(
|
|
|
|
|
String message,
|
|
|
|
|
String category,
|
|
|
|
|
String? suggestion,
|
|
|
|
|
Map<String, dynamic>? context,
|
|
|
|
|
Element element,
|
|
|
|
|
) {
|
|
|
|
|
final buffer = StringBuffer();
|
|
|
|
|
|
|
|
|
|
// Header with category
|
|
|
|
|
buffer.writeln('[$category] $message');
|
|
|
|
|
|
|
|
|
|
// Element context
|
|
|
|
|
buffer.writeln('');
|
|
|
|
|
buffer.writeln('Context:');
|
|
|
|
|
buffer.writeln(' Element: ${element.displayName}');
|
|
|
|
|
buffer.writeln(' Type: ${element.runtimeType}');
|
|
|
|
|
buffer.writeln(' Location: ${element.source?.fullName ?? 'unknown'}');
|
|
|
|
|
|
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
|
|
|
// Try to show enclosing element info for extra context
|
2025-07-25 11:58:56 +03:00
|
|
|
try {
|
|
|
|
|
final enclosing = (element as dynamic).enclosingElement;
|
|
|
|
|
if (enclosing != null) {
|
|
|
|
|
buffer.writeln(' Enclosing: ${enclosing.displayName}');
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// Ignore if enclosingElement is not available
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// Arbitrary user context
|
2025-07-25 11:58:56 +03:00
|
|
|
if (context != null && context.isNotEmpty) {
|
|
|
|
|
buffer.writeln('');
|
|
|
|
|
buffer.writeln('Additional Context:');
|
|
|
|
|
context.forEach((key, value) {
|
|
|
|
|
buffer.writeln(' $key: $value');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// Hint/suggestion if present
|
2025-07-25 11:58:56 +03:00
|
|
|
if (suggestion != null) {
|
|
|
|
|
buffer.writeln('');
|
|
|
|
|
buffer.writeln('💡 Suggestion: $suggestion');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffer.toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// ---------------------------------------------------------------------------
|
|
|
|
|
/// AnnotationValidationException
|
|
|
|
|
///
|
|
|
|
|
/// Thrown when annotation usage is invalid (e.g., missing required annotation,
|
|
|
|
|
/// mutually exclusive annotations, or incorrect @named format).
|
|
|
|
|
///
|
|
|
|
|
/// Grouped as category "ANNOTATION_VALIDATION".
|
|
|
|
|
///
|
|
|
|
|
/// ## Example:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// throw AnnotationValidationException(
|
|
|
|
|
/// '@instance and @provide cannot be used together',
|
|
|
|
|
/// element: method,
|
|
|
|
|
/// suggestion: 'Use only one of @instance or @provide.',
|
|
|
|
|
/// context: {'method_name': method.displayName},
|
|
|
|
|
/// );
|
|
|
|
|
/// ```
|
|
|
|
|
/// ---------------------------------------------------------------------------
|
2025-07-25 11:58:56 +03:00
|
|
|
class AnnotationValidationException extends CherryPickGeneratorException {
|
|
|
|
|
AnnotationValidationException(
|
|
|
|
|
super.message, {
|
|
|
|
|
required super.element,
|
|
|
|
|
super.suggestion,
|
|
|
|
|
super.context,
|
|
|
|
|
}) : super(category: 'ANNOTATION_VALIDATION');
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// ---------------------------------------------------------------------------
|
|
|
|
|
/// TypeParsingException
|
|
|
|
|
///
|
|
|
|
|
/// Thrown when a Dart type cannot be interpreted/parsed for DI,
|
|
|
|
|
/// or if it's not compatible (void, raw Future, etc).
|
|
|
|
|
///
|
|
|
|
|
/// Grouped as category "TYPE_PARSING".
|
|
|
|
|
///
|
|
|
|
|
/// ## Example:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// throw TypeParsingException(
|
|
|
|
|
/// 'Cannot parse injected type',
|
|
|
|
|
/// element: field,
|
|
|
|
|
/// suggestion: 'Specify a concrete type. Avoid dynamic and raw Future.',
|
|
|
|
|
/// context: {'type': field.type.getDisplayString()},
|
|
|
|
|
/// );
|
|
|
|
|
/// ```
|
|
|
|
|
/// ---------------------------------------------------------------------------
|
2025-07-25 11:58:56 +03:00
|
|
|
class TypeParsingException extends CherryPickGeneratorException {
|
|
|
|
|
TypeParsingException(
|
|
|
|
|
super.message, {
|
|
|
|
|
required super.element,
|
|
|
|
|
super.suggestion,
|
|
|
|
|
super.context,
|
|
|
|
|
}) : super(category: 'TYPE_PARSING');
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// ---------------------------------------------------------------------------
|
|
|
|
|
/// CodeGenerationException
|
|
|
|
|
///
|
|
|
|
|
/// Thrown on unexpected code generation or formatting failures
|
|
|
|
|
/// during generator execution.
|
|
|
|
|
///
|
|
|
|
|
/// Grouped as category "CODE_GENERATION".
|
|
|
|
|
///
|
|
|
|
|
/// ## Example:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// throw CodeGenerationException(
|
|
|
|
|
/// 'Could not generate module binding',
|
|
|
|
|
/// element: classElement,
|
|
|
|
|
/// suggestion: 'Check module class methods and signatures.',
|
|
|
|
|
/// );
|
|
|
|
|
/// ```
|
|
|
|
|
/// ---------------------------------------------------------------------------
|
2025-07-25 11:58:56 +03:00
|
|
|
class CodeGenerationException extends CherryPickGeneratorException {
|
|
|
|
|
CodeGenerationException(
|
|
|
|
|
super.message, {
|
|
|
|
|
required super.element,
|
|
|
|
|
super.suggestion,
|
|
|
|
|
super.context,
|
|
|
|
|
}) : super(category: 'CODE_GENERATION');
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// ---------------------------------------------------------------------------
|
|
|
|
|
/// DependencyResolutionException
|
|
|
|
|
///
|
|
|
|
|
/// Thrown if dependency information (for example, types or names)
|
|
|
|
|
/// cannot be resolved during code generation analysis.
|
|
|
|
|
///
|
|
|
|
|
/// Grouped as category "DEPENDENCY_RESOLUTION".
|
|
|
|
|
///
|
|
|
|
|
/// ## Example:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// throw DependencyResolutionException(
|
|
|
|
|
/// 'Dependency type not found in scope',
|
|
|
|
|
/// element: someElement,
|
|
|
|
|
/// suggestion: 'Check CherryPick registration for this type.',
|
|
|
|
|
/// );
|
|
|
|
|
/// ```
|
|
|
|
|
/// ---------------------------------------------------------------------------
|
2025-07-25 11:58:56 +03:00
|
|
|
class DependencyResolutionException extends CherryPickGeneratorException {
|
|
|
|
|
DependencyResolutionException(
|
|
|
|
|
super.message, {
|
|
|
|
|
required super.element,
|
|
|
|
|
super.suggestion,
|
|
|
|
|
super.context,
|
|
|
|
|
}) : super(category: 'DEPENDENCY_RESOLUTION');
|
|
|
|
|
}
|