feat(generators): Add Adapter pattern generator#108
Conversation
Implements the Adapter pattern generator per issue #33: ## Features - Object adapter generation via [GenerateAdapter] attribute - Explicit member mapping via [AdapterMap] attribute - Support for interface and abstract class targets - Support for properties and methods (including async) - Override keyword for abstract class members - ThrowingStub policy for incremental development - Multiple adapters from single host class ## Diagnostics (PKADP001-008) - PKADP001: Host must be static partial - PKADP002: Target must be interface or abstract class - PKADP003: Missing mapping for target member - PKADP004: Duplicate mapping for target member - PKADP005: Signature mismatch - PKADP006: Type name conflict - PKADP007: Invalid adaptee type - PKADP008: Mapping method must be static ## Tests - 14 generator unit tests - 20 demo integration tests - All pass on net8.0, net9.0, net10.0 ## Documentation - Full docs at docs/generators/adapter.md - Real-world demos: Clock, Payment Gateway, Logger adapters Closes #33
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results372 tests 372 ✅ 1m 36s ⏱️ Results for commit bb51007. ♻️ 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 #108 +/- ##
==========================================
+ Coverage 82.72% 87.74% +5.01%
==========================================
Files 180 185 +5
Lines 17018 17793 +775
Branches 2407 2536 +129
==========================================
+ Hits 14078 15612 +1534
+ Misses 2304 2181 -123
+ Partials 636 0 -636
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 Adapter pattern source generator to PatternKit, including attributes, diagnostics, documentation, and example/demo coverage to support explicit member-to-member mapping via a static host class.
Changes:
- Introduces
AdapterGenerator(incremental generator) and adapter-specific attributes ([GenerateAdapter],[AdapterMap],AdapterMissingMapPolicy). - Adds unit tests for generator behavior/diagnostics and integration-style demo tests using generated adapters.
- Documents the generator usage and adds adapter demo scenarios (clock, payments, logger).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
src/PatternKit.Generators/Adapter/AdapterGenerator.cs |
Implements adapter codegen + diagnostics for mapping-based object adapters. |
src/PatternKit.Generators.Abstractions/Adapter/AdapterAttributes.cs |
Adds public attribute surface area for consumers. |
src/PatternKit.Generators/AnalyzerReleases.Unshipped.md |
Registers new analyzer/generator diagnostic IDs (PKADP001–008). |
test/PatternKit.Generators.Tests/AdapterGeneratorTests.cs |
Adds generator unit tests for key generation paths and diagnostics. |
src/PatternKit.Examples/AdapterGeneratorDemo/ClockAdapter.cs |
Demonstrates adapting a legacy clock API to IClock. |
src/PatternKit.Examples/AdapterGeneratorDemo/PaymentAdapter.cs |
Demonstrates adapting Stripe/PayPal-shaped APIs to a unified gateway interface. |
src/PatternKit.Examples/AdapterGeneratorDemo/LoggerAdapter.cs |
Demonstrates adapting a legacy console logger to a structured logger interface. |
test/PatternKit.Examples.Tests/AdapterGeneratorDemo/AdapterGeneratorDemoTests.cs |
Validates demo adapters behave as expected at runtime. |
docs/generators/adapter.md |
Adds end-user documentation and usage guidance for the new generator. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Filter mapping methods by adaptee type (fixes multiple adapters from same host) - Exclude events from target members (not supported) - For abstract class targets, only collect abstract members - Handle struct adaptee constructor (no null check for value types) Addresses feedback from GitHub Copilot review on PR #108.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use SymbolDisplay.FormatPrimitive for default value formatting - Add setter stub for mapped properties with setters - Validate ref/out/in parameter modifiers in signature check - De-duplicate members from interface diamond inheritance - Add tests for PKADP007 (invalid adaptee), PKADP008 (non-static map) - Add test for overlapping member names across adapters - Add test for interface diamond de-duplication - Add test for ref parameter validation - Fix docs: Charge -> ChargeAsync in example
- Add PKADP006 type name conflict check before generating adapter - Add PKADP009 for events not supported in target contract - Add PKADP010 for generic methods not supported - Add PKADP011 for overloaded methods not supported - Add PKADP012 for abstract class without parameterless constructor - Add tests for all new diagnostics (events, generics, overloads, ctor) - Add test for struct adaptee (no null check) - Add test for type name conflict - Update AnalyzerReleases.Unshipped.md with new diagnostic IDs
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 12 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix parameterless ctor check to include protected internal and internal - Fix overload detection to compare full signatures (not just name count) - Diamond inheritance (same signature from multiple paths) no longer falsely triggers PKADP011 - Add PKADP013 diagnostic for settable properties (not supported) - Remove setter stub generation (now a compile-time error) - Add SymbolDisplayFormat for consistent type output with global:: prefix - Fix interface diamond test to use actual diamond (IBase1, IBase2) - Add tests for settable property diagnostic - Update test assertions to match global:: prefixed types
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/PatternKit.Generators.Abstractions/Adapter/AdapterAttributes.cs
Outdated
Show resolved
Hide resolved
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@JerrettDavis I've opened a new pull request, #110, to work on those changes. Once the pull request is ready, I'll request review from you. |
…diagnostic improvements (#110) * Initial plan * fix(adapter): address review feedback - fully-qualified types, member ordering, and code style Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
|
@JerrettDavis I've opened a new pull request, #113, to work on those changes. Once the pull request is ready, I'll request review from you. |
… tests (#113) * Initial plan * fix(adapter): Remove redundant type checks and add missing diagnostic tests Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 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 all the fixes in this thread. |
|
@JerrettDavis I've opened a new pull request, #114, to work on those changes. Once the pull request is ready, I'll request review from you. |
…te internal constructor accessibility (#114) * Initial plan * fix(adapter): Address review feedback - duplicate adapter detection, indexers, and internal ctor accessibility Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> * docs(adapter): Add PKADP018 indexer diagnostic to documentation Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> * fix(adapter): Improve variable naming and remove redundant indexer check in ref-return validation Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> * refactor(adapter): Improve code readability in constructor and property validation Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> * refactor(adapter): Use ContainsKey instead of TryGetValue for duplicate adapter check Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@JerrettDavis I've opened a new pull request, #115, to work on those changes. Once the pull request is ready, I'll request review from you. |
…nd declaration order (#115) * Initial plan * fix(adapter): Add tests and fix cross-host collision detection, member locations, and declaration order Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@JerrettDavis I've opened a new pull request, #116, to work on those changes. Once the pull request is ready, I'll request review from you. |
… filtering (#116) * Initial plan * fix(adapter): Apply PR review fixes - enum defaults, partial types, ordering, accessibility, interface DIMs Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> * refactor(adapter): Combine internal accessibility checks and clarify ordering comment Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> * refactor(adapter): Simplify conflict detection and filtering logic with LINQ Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Code Coverage |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Implements the Adapter pattern generator per issue #33.
The generator creates object adapters that implement a target contract (interface or abstract class) by delegating to an adaptee through explicit mapping methods.
Features
ameof() for type safety
Diagnostics (PKADP001-008)
Tests
Documentation
Usage Example
\\csharp
[GenerateAdapter(Target = typeof(IClock), Adaptee = typeof(LegacyClock))]
public static partial class ClockAdapters
{
[AdapterMap(TargetMember = nameof(IClock.Now))]
public static DateTimeOffset MapNow(LegacyClock adaptee)
=> adaptee.GetCurrentTime();
}
// Generated: LegacyClockToIClockAdapter : IClock
\\
Closes #33