Skip to content

Comments

fix(adapter): Address enum defaults, partial types, ordering, and DIM filtering#116

Merged
JerrettDavis merged 4 commits intofeat/adapter-generatorfrom
copilot/sub-pr-108-yet-again
Feb 13, 2026
Merged

fix(adapter): Address enum defaults, partial types, ordering, and DIM filtering#116
JerrettDavis merged 4 commits intofeat/adapter-generatorfrom
copilot/sub-pr-108-yet-again

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

Fixes 6 issues identified in PR #108 review affecting code generation correctness and determinism.

Changes

  • Enum default parameters: Emit MyEnum.Value syntax instead of numeric literals (0), preventing invalid C# like MyEnum x = 0
  • Partial type conflicts: Allow user-defined partial declarations to extend generated adapters; only error on non-partial conflicts
  • Member ordering: Remove file paths from ordering logic to ensure deterministic output across build environments
  • Constructor accessibility: Handle ProtectedAndInternal (private protected) constructors when validating abstract class targets
  • Default interface members: Filter out C# 8.0+ default implementations from required member list (they don't need adapter implementations)
  • Code clarity: Simplify LINQ filtering and combine duplicate accessibility checks

Example

Before, enum parameters generated invalid code:

void Method(MyEnum option = 0)  // ❌ Invalid C#

After, proper enum syntax is emitted:

void Method(MyEnum option = global::MyNamespace.MyEnum.Default)  // ✅ Valid

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 13, 2026 17:57
…rdering, accessibility, interface DIMs

Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
…ordering comment

Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
…th LINQ

Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Copilot AI changed the title [WIP] Add adapter pattern generator fix(adapter): Address enum defaults, partial types, ordering, and DIM filtering Feb 13, 2026
Copilot AI requested a review from JerrettDavis February 13, 2026 18:05
@JerrettDavis JerrettDavis marked this pull request as ready for review February 13, 2026 18:08
@JerrettDavis JerrettDavis requested a review from Copilot February 13, 2026 18:08
@JerrettDavis JerrettDavis merged commit bb51007 into feat/adapter-generator Feb 13, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses six correctness and determinism issues identified in PR #108 review, improving the reliability and quality of the Adapter pattern generator's code output.

Changes:

  • Fixed enum default parameter generation to emit proper C# syntax (MyEnum.Value instead of numeric literals)
  • Enhanced type name conflict detection to allow user-defined partial type declarations
  • Removed file paths from member ordering logic to ensure deterministic builds across different environments
  • Extended constructor accessibility validation to handle private protected (ProtectedAndInternal) constructors
  • Filtered out C# 8.0+ default interface member implementations from the required member list
  • Simplified LINQ filtering for better code readability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

JerrettDavis added a commit that referenced this pull request Feb 13, 2026
* feat(generators): Add Adapter pattern generator

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

* fix(adapter): Address Copilot review feedback

- 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.

* fix(adapter): address PR review comments

- 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

* fix(adapter): address all remaining PR review comments

- 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

* fix(adapter): address latest PR review feedback

- 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

* Address review feedback: fully-qualified types, member ordering, and 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>

* fix(adapter): Add missing diagnostics, validation, and deterministic ordering (#111)

* Initial plan

* fix(adapter): Address PR review feedback - diagnostics, validation, and docs

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>

* fix(adapter): Add parameter validation and nullability-aware type comparison (#112)

* Initial plan

* fix(adapter): Address review feedback - add parameter validation and improve type comparison

Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>

* fix(adapter): Only reject unbound generic types, allow closed generics

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>

* fix(adapter): Remove redundant type checks and add missing diagnostic 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>

* fix(adapter): Detect duplicate adapter names, reject indexers, validate 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>

* fix(adapter): Cross-host collision detection, diagnostic locations, and 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>

* fix(adapter): Address enum defaults, partial types, ordering, and DIM 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>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants