Skip to content

Commit 248e82a

Browse files
committed
Prune out uneeded types
1 parent 5bbd091 commit 248e82a

File tree

6 files changed

+11
-58
lines changed

6 files changed

+11
-58
lines changed

src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Extensions/IncrementalValuesProviderExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ public static IncrementalValuesProvider<TSource> Distinct<TSource>(this Incremen
3838
}
3939

4040
public static IncrementalValuesProvider<T> Concat<T>(
41-
this IncrementalValuesProvider<T> first,
41+
this IncrementalValuesProvider<ImmutableArray<T>> first,
4242
IncrementalValuesProvider<ImmutableArray<T>> second)
4343
{
4444
return first
45-
.Collect()
4645
.Combine(second.Collect())
4746
.SelectMany((tuple, _) =>
4847
{

src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Models/ValidatableEndpoint.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Models/ValidatableParameter.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Parsers/ValidationsGenerator.EndpointsParser.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Collections.Immutable;
76
using System.Linq;
87
using System.Threading;
@@ -39,11 +38,10 @@ internal bool FindEndpoints(SyntaxNode syntaxNode, CancellationToken cancellatio
3938
: null;
4039
}
4140

42-
internal ValidatableEndpoint ExtractValidatableEndpoint((IInvocationOperation? Operation, RequiredSymbols RequiredSymbols) input, CancellationToken cancellationToken)
41+
internal ImmutableArray<ValidatableType> ExtractValidatableEndpoint((IInvocationOperation? Operation, RequiredSymbols RequiredSymbols) input, CancellationToken cancellationToken)
4342
{
4443
AnalyzerDebug.Assert(input.Operation != null, "Operation should not be null.");
45-
var validatableTypes = new HashSet<ValidatableType>(ValidatableTypeComparer.Instance);
46-
var parameters = ExtractParameters(input.Operation, input.RequiredSymbols, ref validatableTypes);
47-
return new ValidatableEndpoint(parameters, [.. validatableTypes]);
44+
var validatableTypes = ExtractValidatableTypes(input.Operation, input.RequiredSymbols);
45+
return validatableTypes;
4846
}
4947
}

src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Parsers/ValidationsGenerator.TypesParser.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,19 @@ public sealed partial class ValidationsGenerator : IIncrementalGenerator
1919
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included,
2020
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces);
2121

22-
internal ImmutableArray<ValidatableParameter> ExtractParameters(IInvocationOperation operation, RequiredSymbols requiredSymbols, ref HashSet<ValidatableType> validatableTypes)
22+
internal ImmutableArray<ValidatableType> ExtractValidatableTypes(IInvocationOperation operation, RequiredSymbols requiredSymbols)
2323
{
2424
AnalyzerDebug.Assert(operation.SemanticModel != null, "SemanticModel should not be null.");
2525
var parameters = operation.TryGetRouteHandlerMethod(operation.SemanticModel, out var method)
2626
? method.Parameters
2727
: [];
28-
var validatableParameters = ImmutableArray.CreateBuilder<ValidatableParameter>(parameters.Length);
28+
var validatableTypes = new HashSet<ValidatableType>(ValidatableTypeComparer.Instance);
2929
List<ITypeSymbol> visitedTypes = [];
3030
foreach (var parameter in parameters)
3131
{
32-
var hasValidatableType = TryExtractValidatableType(parameter.Type.UnwrapType(requiredSymbols.IEnumerable), requiredSymbols, ref validatableTypes, ref visitedTypes);
33-
var validatableAttributes = ExtractValidationAttributes(parameter, requiredSymbols, out var isRequired);
34-
validatableParameters.Add(new ValidatableParameter(
35-
Type: parameter.Type.UnwrapType(requiredSymbols.IEnumerable),
36-
OriginalType: parameter.Type,
37-
Name: parameter.Name,
38-
DisplayName: parameter.GetDisplayName(requiredSymbols.DisplayAttribute),
39-
Index: parameter.Ordinal,
40-
IsNullable: parameter.Type.IsNullable(),
41-
IsRequired: isRequired,
42-
IsEnumerable: parameter.Type.IsEnumerable(requiredSymbols.IEnumerable),
43-
Attributes: validatableAttributes,
44-
HasValidatableType: hasValidatableType));
32+
_ = TryExtractValidatableType(parameter.Type.UnwrapType(requiredSymbols.IEnumerable), requiredSymbols, ref validatableTypes, ref visitedTypes);
4533
}
46-
return validatableParameters.ToImmutable();
34+
return [.. validatableTypes];
4735
}
4836

4937
internal bool TryExtractValidatableType(ITypeSymbol typeSymbol, RequiredSymbols requiredSymbols, ref HashSet<ValidatableType> validatableTypes, ref List<ITypeSymbol> visitedTypes)

src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/ValidationsGenerator.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3131
predicate: FindEndpoints,
3232
transform: TransformEndpoints)
3333
.Where(endpoint => endpoint is not null);
34-
// Extract all validatable endpoints encountered in the type graph.
35-
var validatableEndpoints = endpoints
34+
// Extract validatable types from all endpoints.
35+
var validatableTypesFromEndpoints = endpoints
3636
.Combine(requiredSymbols)
3737
.Select(ExtractValidatableEndpoint);
3838
// Extract all validatable types encountered in the type graph.
39-
var validatableTypes = validatableEndpoints
40-
.SelectMany((endpoint, ct) => endpoint.ValidatableTypes)
39+
var validatableTypes = validatableTypesFromEndpoints
4140
.Concat(validatableTypesWithAttribute)
4241
.Distinct(ValidatableTypeComparer.Instance)
4342
.Collect();

0 commit comments

Comments
 (0)