Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions Semantics.SourceGenerators/Generators/DimensionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,19 @@ protected override void Generate(SourceProductionContext context, DimensionsMeta

// Emit per-dimension marker interfaces (I{Dim}Unit : IUnit) so generated
// quantity types can accept dimensionally-compatible units only.
foreach (PhysicalDimension dimension in sortedDimensions)
sourceFileTemplate.Classes.AddRange(sortedDimensions.Select(dimension => new ClassTemplate()
{
sourceFileTemplate.Classes.Add(new ClassTemplate()
{
Comments =
[
Emit.SummaryOpen,
$"/// Marker interface implemented by every unit of the <c>{dimension.Name}</c> dimension.",
"/// Generated quantities use this to make <c>In(...)</c> dimensionally type-safe at compile time.",
Emit.SummaryClose,
],
Keywords = [Emit.Public, "interface"],
Name = $"I{dimension.Name}Unit",
Interfaces = ["IUnit"],
});
}
Comments =
[
Emit.SummaryOpen,
$"/// Marker interface implemented by every unit of the <c>{dimension.Name}</c> dimension.",
"/// Generated quantities use this to make <c>In(...)</c> dimensionally type-safe at compile time.",
Emit.SummaryClose,
],
Keywords = [Emit.Public, "interface"],
Name = $"I{dimension.Name}Unit",
Interfaces = ["IUnit"],
}));

WriteSourceFileTo(codeBlocker, sourceFileTemplate);
GeneratedSource.Add(context, sourceFileTemplate.FileName, codeBlocker.ToString());
Expand Down
9 changes: 5 additions & 4 deletions Semantics.SourceGenerators/Models/DimensionsMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/// performed in the generator (#56 / SEM001) because they need the full
/// dimension map.
/// </remarks>
public List<string> Validate()

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

Check warning on line 26 in Semantics.SourceGenerators/Models/DimensionsMetadata.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Release

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.
{
List<string> issues = [];

Expand Down Expand Up @@ -96,17 +96,18 @@
issues.Add($"Type name '{form.Base}' (dimension '{label}' vector{i}) collides with another base or overload.");
}

foreach (OverloadDefinition overload in form.Overloads)
// Only the name is inspected, so iterate the names directly.
foreach (string overloadName in form.Overloads.Select(overload => overload.Name))
{
if (string.IsNullOrEmpty(overload.Name))
if (string.IsNullOrEmpty(overloadName))
{
issues.Add($"Dimension '{label}' vector{i} has an overload missing 'name'.");
continue;
}

if (!seenTypeNames.Add(overload.Name))
if (!seenTypeNames.Add(overloadName))
{
issues.Add($"Overload type name '{overload.Name}' (dimension '{label}' vector{i}) collides with another base or overload.");
issues.Add($"Overload type name '{overloadName}' (dimension '{label}' vector{i}) collides with another base or overload.");
}
}
}
Expand Down
Loading