-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathInvalidPolySharpMSBuildOptionAnalyzer.Execute.cs
More file actions
98 lines (78 loc) · 4.77 KB
/
InvalidPolySharpMSBuildOptionAnalyzer.Execute.cs
File metadata and controls
98 lines (78 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using PolySharp.SourceGenerators.Constants;
using PolySharp.SourceGenerators.Extensions;
using PolySharp.SourceGenerators.Helpers;
using PolySharp.SourceGenerators.Models;
using static PolySharp.SourceGenerators.Diagnostics.DiagnosticDescriptors;
namespace PolySharp.SourceGenerators;
/// <inheritdoc/>
partial class InvalidPolySharpMSBuildOptionAnalyzer
{
/// <summary>
/// Extracts the <see cref="DiagnosticInfo"/> values for the current generation.
/// </summary>
/// <param name="options">The input <see cref="AnalyzerConfigOptionsProvider"/> instance.</param>
/// <param name="token">The cancellation token for the operation.</param>
/// <returns>The <see cref="DiagnosticInfo"/> values for the current generation.</returns>
private static ImmutableArray<DiagnosticInfo> GetOptionsDiagnostics(AnalyzerConfigOptionsProvider options, CancellationToken token)
{
using ImmutableArrayBuilder<DiagnosticInfo> builder = ImmutableArrayBuilder<DiagnosticInfo>.Rent();
// Validate "UsePublicAccessibilityForGeneratedTypes" is a valid MSBuild bool property (or none)
if (!options.IsValidMSBuildProperty(PolySharpMSBuildProperties.UsePublicAccessibilityForGeneratedTypes, out string? usePublicAccessibilityForGeneratedTypes))
{
builder.Add(InvalidBoolMSBuildProperty, usePublicAccessibilityForGeneratedTypes, PolySharpMSBuildProperties.UsePublicAccessibilityForGeneratedTypes);
}
token.ThrowIfCancellationRequested();
// Do the same for "IncludeRuntimeSupportedAttributes"
if (!options.IsValidMSBuildProperty(PolySharpMSBuildProperties.IncludeRuntimeSupportedAttributes, out string? includeRuntimeSupportedAttributes))
{
builder.Add(InvalidBoolMSBuildProperty, includeRuntimeSupportedAttributes, PolySharpMSBuildProperties.IncludeRuntimeSupportedAttributes);
}
token.ThrowIfCancellationRequested();
// And for "UseInteropServices2NamespaceForUnmanagedCallersOnlyAttribute" as well
if (!options.IsValidMSBuildProperty(PolySharpMSBuildProperties.UseInteropServices2NamespaceForUnmanagedCallersOnlyAttribute, out string? useInteropServices2NamespaceForUnmanagedCallersOnlyAttribute))
{
builder.Add(InvalidBoolMSBuildProperty, useInteropServices2NamespaceForUnmanagedCallersOnlyAttribute, PolySharpMSBuildProperties.UseInteropServices2NamespaceForUnmanagedCallersOnlyAttribute);
}
token.ThrowIfCancellationRequested();
// And for "ExcludeTypeForwardedToDeclarations" as well
if (!options.IsValidMSBuildProperty(PolySharpMSBuildProperties.ExcludeTypeForwardedToDeclarations, out string? excludeTypeForwardedToDeclarations))
{
builder.Add(InvalidBoolMSBuildProperty, excludeTypeForwardedToDeclarations, PolySharpMSBuildProperties.ExcludeTypeForwardedToDeclarations);
}
token.ThrowIfCancellationRequested();
// And for "AlwaysGeneratePolyfills" as well
if (!options.IsValidMSBuildProperty(PolySharpMSBuildProperties.AlwaysGeneratePolyfills, out string? alwaysGeneratePolyfills))
{
builder.Add(InvalidBoolMSBuildProperty, alwaysGeneratePolyfills, PolySharpMSBuildProperties.AlwaysGeneratePolyfills);
}
token.ThrowIfCancellationRequested();
ImmutableArray<string> excludeGeneratedTypes = options.GetStringArrayMSBuildProperty(PolySharpMSBuildProperties.ExcludeGeneratedTypes);
// Validate the fully qualified type names for "ExcludeGeneratedTypes"
foreach (string type in excludeGeneratedTypes)
{
if (!PolyfillsGenerator.FullyQualifiedTypeNamesToResourceNames.ContainsKey(type))
{
builder.Add(InvalidPolyfillFullyQualifiedMetadataName, type, PolySharpMSBuildProperties.ExcludeGeneratedTypes);
}
}
token.ThrowIfCancellationRequested();
ImmutableArray<string> includeGeneratedTypes = options.GetStringArrayMSBuildProperty(PolySharpMSBuildProperties.IncludeGeneratedTypes);
// Do the same for "IncludeGeneratedTypes"
foreach (string type in includeGeneratedTypes)
{
if (!PolyfillsGenerator.FullyQualifiedTypeNamesToResourceNames.ContainsKey(type))
{
builder.Add(InvalidPolyfillFullyQualifiedMetadataName, type, PolySharpMSBuildProperties.IncludeGeneratedTypes);
}
}
token.ThrowIfCancellationRequested();
return builder.ToImmutable();
}
}