feat: Add Decorator pattern source generator#91
Conversation
Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results173 tests 173 ✅ 1m 27s ⏱️ Results for commit ed8fac9. ♻️ This comment has been updated with latest results. |
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #91 +/- ##
==========================================
- Coverage 85.83% 85.19% -0.65%
==========================================
Files 143 146 +3
Lines 12288 12957 +669
Branches 1641 1749 +108
==========================================
+ Hits 10548 11039 +491
- Misses 1329 1480 +151
- Partials 411 438 +27
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a new Decorator-pattern source generator to produce base decorator implementations (plus optional composition helpers) for interfaces and abstract classes, backed by new attributes, tests, and an example.
Changes:
- Introduces
[GenerateDecorator],[DecoratorIgnore], andDecoratorCompositionModein the abstractions package. - Adds
DecoratorGeneratorto emit forwarding base decorator types and (optionally) aComposehelper. - Adds a new test suite and an examples/demo file showcasing generated decorators.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
src/PatternKit.Generators/DecoratorGenerator.cs |
Implements the incremental source generator and code emission for decorators/helpers. |
src/PatternKit.Generators.Abstractions/Decorator/GenerateDecoratorAttribute.cs |
Adds public generator surface area (attribute + enum) to configure decorator generation. |
src/PatternKit.Generators.Abstractions/Decorator/DecoratorIgnoreAttribute.cs |
Adds attribute for per-member generation behavior control. |
src/PatternKit.Generators/AnalyzerReleases.Unshipped.md |
Registers new diagnostic IDs for the decorator generator. |
test/PatternKit.Generators.Tests/DecoratorGeneratorTests.cs |
Adds compilation-based tests for generated output. |
src/PatternKit.Examples/Decorators/StorageDecoratorExample.cs |
Adds a real-world example demonstrating decorator chaining and usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/PatternKit.Generators.Abstractions/Decorator/DecoratorIgnoreAttribute.cs
Outdated
Show resolved
Hide resolved
src/PatternKit.Generators.Abstractions/Decorator/GenerateDecoratorAttribute.cs
Outdated
Show resolved
Hide resolved
|
@copilot apply changes based on the comments in this thread |
…rwarding, and add comprehensive tests Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
…it on errors Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
…bers, fix hasErrors for warnings only, add generation skip assertions Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/PatternKit.Generators.Abstractions/Decorator/DecoratorIgnoreAttribute.cs
Outdated
Show resolved
Hide resolved
|
@copilot apply changes based on the comments in this thread |
…eading comments Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
1 similar comment
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Decorator Pattern Source Generator - PR Review Round 9 ✅
✅ All PR Review Comments Addressed (5/5)
1. DecoratorIgnoreAttribute Documentation (comment 2719557357)
sealed override2. Misleading Test Comment (comment 2719557371)
3. Unused Context Parameter in GenerateBaseDecorator (comment 2719557378)
contextparameter to_to indicate intentionally unused4. Unused Config Parameter in GenerateForwardingMethod (comment 2719557389)
configparameter to_to indicate intentionally unused5. Unused Config Parameter in GenerateForwardingProperty (comment 2719557397)
configparameter to_to indicate intentionally unused📊 Test Results
🔧 Code Quality Improvements
_naming)All feedback addressed with zero test failures and clean compilation!
Original prompt
This section details on the original issue you should resolve
<issue_title>Generator: Create Decorator Pattern</issue_title>
<issue_description>## Summary
Add a source generator that produces boilerplate-free, GoF-consistent Decorator pattern implementations for interfaces and abstract classes.
The generator lives in
PatternKit.Generatorsand emits self-contained, readable C# with no runtime PatternKit dependency.Primary goals:
ValueTaskfor generated hooks).Motivation / Problem
Decorator chains are frequently hand-written and drift:
Source generation can emit correct forwarding + consistent hooks once.
Supported Targets (must-have)
Decorator generation must support:
interfaceabstract class(virtual/abstract members only)Decorator generation is opt-in via attribute on the contract.
Proposed User Experience
A) Generate base decorator + optional pipeline builder
Generated (representative shape):
B) Typed decorators written by users
The generator ensures the base class always stays in sync with the contract.
Attributes / Surface Area
Namespace:
PatternKit.Generators.Decorator[GenerateDecorator]on contract typestring? BaseTypeName(default:<ContractName>DecoratorBase)string? HelpersTypeName(default:<ContractName>Decorators)DecoratorCompositionMode Composition(default:HelpersOnly)bool GenerateAsync(default: inferred)bool ForceAsync(default: false)Optional:
[DecoratorIgnore]for members to exclude.Enums:
DecoratorCompositionMode:None,HelpersOnly,PipelineNextStyle(v2)Semantics (must-have)
Forwarding correctness
Inner.Composition helper ordering
If helper
Composeis generated:decorators applied in array order.
ordering must be documented:
decorators[0]is outermost by default.Async
Diagnostics (must-have)
PKDEC001Type marked[GenerateDecorator]must bepartial.PKDEC002Unsupported member kind (e.g., event) for v1.PKDEC003Name conflict for generated base/helper types.PKDEC004Member not accessible for generation.Generated Code Layout
ContractName.Decorator.g.csDeterminism:
Testing Expectations
Acceptance Criteria
[GenerateDecorator]works for interfaces and abstract classes.</issue_description>
<agent_instructions>Ensure complete BDD code coverage, comprehensive realworld usage examples and demos, user guides, and congruence with our existing implementations.</agent_instructions>
Comments on the Issue (you are @copilot in this section)
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.