Skip to content

Fix/contract keys and register constant#303

Closed
glennawatson wants to merge 13 commits intomainfrom
fix/contract-keys-and-register-constant
Closed

Fix/contract keys and register constant#303
glennawatson wants to merge 13 commits intomainfrom
fix/contract-keys-and-register-constant

Conversation

@glennawatson
Copy link
Contributor

What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior?

What might this PR break?

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

…issues

- Contract keys from different namespaces are now fully qualified in generated code, preventing CS0103 errors
- RegisterConstant no longer triggers constructor analysis since it takes pre-instantiated objects

fixed #292
fixed #295
…alyzer

Replace hardcoded string literals with named constants for method names,
parameter names, type patterns, file names, metadata names, and code fix
titles. Also rename claude.md to CLAUDE.md.
…bute and type comparisons

Replace string-based comparisons with pre-resolved symbol comparisons
in MetadataExtractor to eliminate string allocations during the generator
transform phase. String comparison is retained as a fallback when symbol
resolution fails. Adds unit tests for the new helper methods.
- Add comprehensive XML documentation across all non-test source files
- Make key methods internal for direct testability: CodeGenerator
  (GetConstructorArguments, GetPropertyInitializer, GetResolutionString),
  ConstructorCodeFixProvider (AddAttributeAsync), PropertyCodeFixProvider
  (AddSetterAsync split into BuildSetterModifiers,
  ConvertExpressionBodiedProperty, AddSetterToGetterOnlyProperty,
  UpdateExistingSetterModifiers)
- Extract testable helpers in AnalyzerHelpers (IsContainedInSplatRegistrations,
  ReportDiagnostics, GetFirstLocation) and MetadataExtractor
  (ExtractRegisterMetadataFromSymbol, ExtractLazySingletonMetadataFromSymbol,
  GetFirstLocation)
- Add 66 new unit tests (939 → 1005) covering all newly internal methods,
  fallback paths, and edge cases
…eakTable

The 4 GetTypeByMetadataName lookups were repeated per syntax node transform.
Use a ConditionalWeakTable<Compilation, WellKnownSymbolsBox> so they resolve
once per compilation instance. Pass WellKnownSymbols explicitly into the inner
extract methods to make the dependency clear and testable.
Use argument NameColon syntax to resolve parameters by name instead of
relying solely on positional index, which breaks when callers pass named
arguments out of order.
Extract GetFullyQualifiedMethodInvocation as a testable internal method
that fully qualifies the containing type of method invocations used as
contract keys. Previously, calls like ContractHelper.GetContractKey()
were emitted unqualified in generated code within namespace Splat,
causing compilation errors when the method's type was in a different
namespace.

Also add a bounds check in ResolveParameterForArgument to return null
when the positional index exceeds the parameter count, preventing
IndexOutOfRangeException on malformed code.
The code generator was using sb.Append (no trailing newline) for both
transient and lazy singleton registrations, causing the closing brace
of SetupIOCInternal to appear on the same line as the last registration.
Changed to sb.AppendLine in both GenerateTransientRegistration and
GenerateLazySingletonRegistration to ensure proper formatting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant