Refactor source generation and improve generated mapping support - #49
Merged
Conversation
- Hide generated configuration types from consumer APIs - Mark generated sources explicitly - Filter unrelated syntax candidates - Remove compiler objects from cached models - Scope generation to individual mappers - Preserve existing mapping behavior and packaging
- One-line source ternaries stay on one line. - Multi-line ternaries use aligned ? / : indentation. - Switch-expression lowering preserves whether the original switch was one or multi-line. - Multi-line rewritten branches still expand cleanly. - Added direct and switch formatting coverage. Verified: dotnet test AlephMapper.slnx --no-restore --verbosity quiet — 86 passed.
- source/AlephMapper.csproj rebuilds with 0 warnings. - Generated AdaptAttribute.Name now defaults to string.Empty, eliminating CS8618 in consumer-generated attribute code. - Fixed nullable contracts in the inliner and property collector. - Added analyzer release tracking and corrected diagnostic-message metadata. - Fixed analyzer package dependency metadata. Verified: - dotnet build source\AlephMapper.csproj --no-restore -t:Rebuild — 0 warnings - dotnet test AlephMapper.slnx --no-restore --verbosity quiet — 86 passed Remaining warnings are nullable-flow warnings from generated mapping bodies in integration/experiment fixtures, not generated attributes.
- Preserved formatted diagnostic messages during round-trip.
- Rebound diagnostics to original SyntaxTree instances at output time, restoring #pragma warning disable AM0018
suppression.
- Corrected the crash-report link from IMP005 to AM0004.
- Added regression coverage for message formatting, syntax-tree location, pragma suppression, and crash-link ID.
- source/AlephSourceGenerator.cs
- Split mapper output into source-only and diagnostics branches.
- Removed misleading Candidates tracking name.
- CompilationProvider is now used only by diagnostics.
- source/Generation/MapperSourceOutput.cs
- Replaced mixed Emit with EmitSource and EmitDiagnostics.
- tests/AlephMapper.Tests/SourceGeneratorTests.cs
- Updated incremental tracking coverage to assert the real source-output branch stays Unchanged after an unrelated
compilation edit. This is not described as a cache hit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor source generation and improve generated mapping support
Summary
This PR refactors AlephMapper's Roslyn generator around mapper-scoped incremental outputs, strengthens generated-code diagnostics and nullable handling, and expands support for complex expression and generic mapping scenarios. It also updates generated attributes, documentation, samples, and test coverage.
Breaking change
[Expressive]has been renamed to[Projectable]with no compatibility attribute. Replace every[Expressive]use with[Projectable].Generated mappings now include the assembly revision in their
GeneratedCodeversion metadata. Local builds emit0.7.0.0; CI-packaged analyzers emit0.7.0.<run-number>. Consumers that inspect this attribute using an exact version string must account for the revision component.Highlights
Incremental generator architecture
AddSource.AddSource.Generated API and diagnostics
AM0018:[Adapt]on a generic mapping method is skipped because the generic mapper already provides the polymorphic behavior.Mapping and expression generation
Projectableexpression companions andUpdatableoverloads with the original type parameters andwhereconstraints.#nullablestate only around each generated member.!operators.#pragma warning disable.AM0004crash-report help link.global::-qualified type references in generated declarations, expressions, object creation, casts, and constraints while retaining C# keyword types and generic parameters, and omits the redundantSystem.CodeDom.Compilerusing.Tests, samples, and documentation
0.7.0.CI and packaging
main, and manual dispatch.[Projectable]mapper through the packaged analyzer.Generator reliability
Validation
dotnet build AlephMapper.slnx --configuration Release --no-restore— succeeded with 0 warnings and 0 errorsdotnet run --project tests/AlephMapper.Tests/AlephMapper.Tests.csproj -c Release --no-restore— 58 passeddotnet test AlephMapper.slnx --configuration Release --no-build --no-restore -- --report-trx --results-directory artifacts/test-results— 95 passeddotnet pack source/AlephMapper.csproj --configuration Release --no-build --no-restore --output artifacts/nuget— producedAlephMapper.0.7.0.nupkgdotnet test AlephMapper.slnx --no-restore— 96 passed