Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit e544325

Browse files
author
Mark Hall
committed
fix pr feedback and package map
1 parent b0bb5f1 commit e544325

22 files changed

+307
-578
lines changed

src/EpiSourceUpdater/Common/NullableAttributes.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ internal sealed class MaybeNullWhenAttribute : Attribute
5353
/// <param name="returnValue">
5454
/// The return value condition. If the method returns this value, the associated parameter may be null.
5555
/// </param>
56-
public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
56+
public MaybeNullWhenAttribute(bool returnValue)
57+
{
58+
ReturnValue = returnValue;
59+
}
5760

5861
/// <summary>Gets a value indicating whether the return value condition.</summary>
5962
public bool ReturnValue { get; }
@@ -69,7 +72,10 @@ internal sealed class NotNullWhenAttribute : Attribute
6972
/// <param name="returnValue">
7073
/// The return value condition. If the method returns this value, the associated parameter will not be null.
7174
/// </param>
72-
public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
75+
public NotNullWhenAttribute(bool returnValue)
76+
{
77+
ReturnValue = returnValue;
78+
}
7379

7480
/// <summary>Gets a value indicating whether the return value condition.</summary>
7581
public bool ReturnValue { get; }
@@ -85,7 +91,10 @@ internal sealed class NotNullIfNotNullAttribute : Attribute
8591
/// <param name="parameterName">
8692
/// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null.
8793
/// </param>
88-
public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName;
94+
public NotNullIfNotNullAttribute(string parameterName)
95+
{
96+
ParameterName = parameterName;
97+
}
8998

9099
/// <summary>Gets the associated parameter name.</summary>
91100
public string ParameterName { get; }
@@ -110,7 +119,10 @@ internal sealed class DoesNotReturnIfAttribute : Attribute
110119
/// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
111120
/// the associated parameter matches this value.
112121
/// </param>
113-
public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue;
122+
public DoesNotReturnIfAttribute(bool parameterValue)
123+
{
124+
ParameterValue = parameterValue;
125+
}
114126

115127
/// <summary>Gets a value indicating whether the condition parameter value.</summary>
116128
public bool ParameterValue { get; }
@@ -126,13 +138,19 @@ internal sealed class MemberNotNullAttribute : Attribute
126138
/// <param name="member">
127139
/// The field or property member that is promised to be not-null.
128140
/// </param>
129-
public MemberNotNullAttribute(string member) => Members = new[] { member };
141+
public MemberNotNullAttribute(string member)
142+
{
143+
Members = new[] { member };
144+
}
130145

131146
/// <summary>Initializes the attribute with the list of field and property members.</summary>
132147
/// <param name="members">
133148
/// The list of field and property members that are promised to be not-null.
134149
/// </param>
135-
public MemberNotNullAttribute(params string[] members) => Members = members;
150+
public MemberNotNullAttribute(params string[] members)
151+
{
152+
Members = members;
153+
}
136154

137155
/// <summary>Gets field or property member names.</summary>
138156
public string[] Members { get; }

src/EpiSourceUpdater/Epi.Source.Updater.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<AssemblyName>Epi.Source.Updater</AssemblyName>
66
<LangVersion>latest</LangVersion>
7+
<AssemblyVersion>1.0.1.0</AssemblyVersion>
8+
<FileVersion>1.0.1.0</FileVersion>
9+
<Version>1.0.1</Version>
710
</PropertyGroup>
811

912
<ItemGroup>
@@ -40,7 +43,7 @@
4043
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" />
4144
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
4245
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0" />
43-
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Abstractions" Version="0.2.236301" />
46+
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Abstractions" Version="0.3.246501" />
4447
</ItemGroup>
4548

4649
<ItemGroup>

src/EpiSourceUpdater/EpiAttributeRemoverAnalyzer.cs

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Collections.Immutable;
7-
using System.Linq;
84
using Microsoft.CodeAnalysis;
95
using Microsoft.CodeAnalysis.Diagnostics;
6+
using System;
7+
using System.Collections.Immutable;
108
using CS = Microsoft.CodeAnalysis.CSharp;
119
using CSSyntax = Microsoft.CodeAnalysis.CSharp.Syntax;
1210

1311
namespace Epi.Source.Updater
1412
{
1513
/// <summary>
1614
/// Analyzer for identifying usage of types that should be replaced with other types.
17-
/// Diagnostics are created based on mapping configurations.
18-
/// <see href="https://github.com/episerver/upgrade-assistant-extensions/issues/1">Related issue</see>.
1915
/// </summary>
2016
[DiagnosticAnalyzer(LanguageNames.CSharp)]
2117
public class EpiAttributeRemoverAnalyzer : DiagnosticAnalyzer
@@ -58,45 +54,15 @@ public override void Initialize(AnalysisContext context)
5854

5955
context.EnableConcurrentExecution();
6056
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
61-
62-
context.RegisterCompilationStartAction(context =>
63-
{
64-
// Load analyzer configuration defining the types that should be mapped.
65-
var mappings = EpiClassMapLoader.LoadMappings(context.Options.AdditionalFiles);
66-
67-
// If type maps are present, register syntax node actions to analyze for those types
68-
if (mappings.Any())
69-
{
70-
// Register actions for handling both C# and VB identifiers
71-
context.RegisterSyntaxNodeAction(context => AnalyzeCSharpIdentifier(context, mappings), CS.SyntaxKind.ClassDeclaration);
72-
}
73-
});
74-
}
75-
76-
/// <summary>
77-
/// Creates a type upgrade diagnsotic.
78-
/// </summary>
79-
/// <param name="location">The location the diagnostic occurs at.</param>
80-
/// <param name="properties">Properties (including the name of the new identifier that code fix providers should substitute in) that should be included in the diagnostic.</param>
81-
/// <param name="messageArgs">Arguments (the simple name of the identifier to be replaced and the full name of the identifier to replace it) to be used in diagnotic messages.</param>
82-
/// <returns>A diagnostic to be shown to the user.</returns>
83-
private static Diagnostic CreateDiagnostic(Location location, ImmutableDictionary<string, string?> properties, params object[] messageArgs)
84-
=> Diagnostic.Create(Rule, location, properties, messageArgs);
85-
86-
private static void AnalyzeCSharpIdentifier(SyntaxNodeAnalysisContext context, IEnumerable<TypeMapping> mappings)
87-
{
88-
var identifier = (CSSyntax.ClassDeclarationSyntax)context.Node;
89-
AnalyzeIdentifier(context, mappings, identifier.Identifier.ValueText);
57+
context.RegisterSyntaxNodeAction(context => AnalyzeIdentifier(context), CS.SyntaxKind.ClassDeclaration);
9058
}
9159

9260
/// <summary>
9361
/// Analyzes an identifier syntax node to determine if it likely represents any of the types present
9462
/// in <see cref="IdentifierMappings"/>.
9563
/// </summary>
9664
/// <param name="context">The syntax node analysis context including the identifier node to analyze.</param>
97-
/// <param name="mappings">Type mappings to use when upgrading types.</param>
98-
/// <param name="simpleName">The simple name of the identifier being analyzed.</param>
99-
private static void AnalyzeIdentifier(SyntaxNodeAnalysisContext context, IEnumerable<TypeMapping> mappings, string simpleName)
65+
private static void AnalyzeIdentifier(SyntaxNodeAnalysisContext context)
10066
{
10167
var classDirective = (CSSyntax.ClassDeclarationSyntax)context.Node;
10268
if (classDirective is null)
@@ -109,15 +75,15 @@ private static void AnalyzeIdentifier(SyntaxNodeAnalysisContext context, IEnumer
10975
return;
11076
}
11177

112-
foreach (var attib in classDirective.AttributeLists)
78+
foreach (var attrib in classDirective.AttributeLists)
11379
{
114-
if (attib.Attributes[0].Name.ToString() == "TemplateDescriptor")
80+
if (attrib.Attributes[0].Name.ToString() == "TemplateDescriptor")
11581
{
116-
foreach (var arg in attib.Attributes[0].ArgumentList.Arguments)
82+
foreach (var arg in attrib.Attributes[0].ArgumentList.Arguments)
11783
{
11884
if (arg.NameEquals.Name.Identifier.Text == "Default")
11985
{
120-
var diagnostic = Diagnostic.Create(Rule, classDirective.GetLocation(), attib.Attributes[0].Name.ToString());
86+
var diagnostic = Diagnostic.Create(Rule, attrib.Attributes[0].GetLocation(), attrib.Attributes[0].Name.ToString());
12187
context.ReportDiagnostic(diagnostic);
12288
}
12389
}

src/EpiSourceUpdater/EpiAttributeRemoverCodeFixProvider.cs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Collections.Immutable;
5-
using System.Linq;
6-
using System.Threading;
7-
using System.Threading.Tasks;
84
using Microsoft.CodeAnalysis;
95
using Microsoft.CodeAnalysis.CodeActions;
106
using Microsoft.CodeAnalysis.CodeFixes;
11-
using Microsoft.CodeAnalysis.CSharp;
127
using Microsoft.CodeAnalysis.CSharp.Syntax;
13-
using Microsoft.CodeAnalysis.Editing;
14-
using Microsoft.CodeAnalysis.Formatting;
8+
using System.Collections.Immutable;
9+
using System.Linq;
10+
using System.Threading;
11+
using System.Threading.Tasks;
1512

1613
namespace Epi.Source.Updater
1714
{
@@ -27,11 +24,9 @@ public class EpiAttributeRemoverCodeFixProvider : CodeFixProvider
2724
// the analyzer's ID in the code fix provider's FixableDiagnosticIds array.
2825
public sealed override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(EpiAttributeRemoverAnalyzer.DiagnosticId);
2926

30-
public sealed override FixAllProvider GetFixAllProvider()
31-
{
27+
public sealed override FixAllProvider GetFixAllProvider() =>
3228
// See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/FixAllProvider.md for more information on Fix All Providers
33-
return WellKnownFixAllProviders.BatchFixer;
34-
}
29+
WellKnownFixAllProviders.BatchFixer;
3530

3631
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
3732
{
@@ -45,40 +40,34 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
4540
var diagnostic = context.Diagnostics.First();
4641
var diagnosticSpan = diagnostic.Location.SourceSpan;
4742

48-
var declaration = root.FindToken(diagnosticSpan.Start).Parent?.AncestorsAndSelf().OfType<ClassDeclarationSyntax>().First();
43+
var declaration = root.FindNode(diagnosticSpan);
4944

5045
if (declaration is null)
5146
{
5247
return;
5348
}
5449

50+
5551
// Register a code action that will invoke the fix.
5652
context.RegisterCodeFix(
5753
CodeAction.Create(
5854
Resources.EpiAttributeRemoverTitle,
59-
c => ReplaceClassesAsync(context.Document, declaration, c),
55+
c => RemoveDefaultPropertyAsync(context.Document, (AttributeSyntax)declaration, new CancellationToken()),
6056
nameof(Resources.EpiAttributeRemoverTitle)),
6157
diagnostic);
6258
}
6359

64-
private static async Task<Document> ReplaceClassesAsync(Document document, ClassDeclarationSyntax localDeclaration, CancellationToken cancellationToken)
60+
private static async Task<Document> RemoveDefaultPropertyAsync(Document document, AttributeSyntax localDeclaration, CancellationToken cancellationToken)
6561
{
6662
// Remove the leading trivia from the local declaration.
6763
var oldRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
6864
var newNode = localDeclaration;
6965

70-
foreach (var attrib in localDeclaration.AttributeLists)
66+
foreach (var arg in localDeclaration.ArgumentList.Arguments)
7167
{
72-
if (attrib.Attributes[0].Name.ToString() == "TemplateDescriptor")
68+
if (arg.NameEquals.Name.Identifier.Text == "Default")
7369
{
74-
foreach (var arg in attrib.Attributes[0].ArgumentList.Arguments)
75-
{
76-
if (arg.NameEquals.Name.Identifier.Text == "Default")
77-
{
78-
var removedArg = attrib.Attributes[0].ArgumentList.RemoveNode(arg, SyntaxRemoveOptions.AddElasticMarker);
79-
newNode = localDeclaration.RemoveNode(arg, SyntaxRemoveOptions.KeepNoTrivia);
80-
}
81-
}
70+
newNode = localDeclaration.RemoveNode(arg, SyntaxRemoveOptions.KeepNoTrivia);
8271
}
8372
}
8473

src/EpiSourceUpdater/EpiClassMapLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Microsoft.CodeAnalysis;
5+
using Microsoft.CodeAnalysis.Text;
46
using System;
57
using System.Collections.Generic;
68
using System.Collections.Immutable;
79
using System.Linq;
8-
using Microsoft.CodeAnalysis;
9-
using Microsoft.CodeAnalysis.Text;
1010

1111
namespace Epi.Source.Updater
1212
{

src/EpiSourceUpdater/EpiClassReplacementsAnalyzer.cs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Microsoft.CodeAnalysis;
5+
using Microsoft.CodeAnalysis.Diagnostics;
46
using System;
57
using System.Collections.Generic;
68
using System.Collections.Immutable;
79
using System.Linq;
8-
using Microsoft.CodeAnalysis;
9-
using Microsoft.CodeAnalysis.Diagnostics;
1010
using CS = Microsoft.CodeAnalysis.CSharp;
1111
using CSSyntax = Microsoft.CodeAnalysis.CSharp.Syntax;
1212

@@ -69,35 +69,12 @@ public override void Initialize(AnalysisContext context)
6969
if (mappings.Any())
7070
{
7171
// Register actions for handling both C# and VB identifiers
72-
context.RegisterSyntaxNodeAction(context => AnalyzeCSharpIdentifier(context, mappings), CS.SyntaxKind.ClassDeclaration);
72+
context.RegisterSyntaxNodeAction(context => AnalyzeIdentifier(context, mappings), CS.SyntaxKind.ClassDeclaration);
7373
}
7474
});
7575
}
7676

77-
/// <summary>
78-
/// Creates a type upgrade diagnsotic.
79-
/// </summary>
80-
/// <param name="location">The location the diagnostic occurs at.</param>
81-
/// <param name="properties">Properties (including the name of the new identifier that code fix providers should substitute in) that should be included in the diagnostic.</param>
82-
/// <param name="messageArgs">Arguments (the simple name of the identifier to be replaced and the full name of the identifier to replace it) to be used in diagnotic messages.</param>
83-
/// <returns>A diagnostic to be shown to the user.</returns>
84-
private static Diagnostic CreateDiagnostic(Location location, ImmutableDictionary<string, string?> properties, params object[] messageArgs)
85-
=> Diagnostic.Create(Rule, location, properties, messageArgs);
86-
87-
private static void AnalyzeCSharpIdentifier(SyntaxNodeAnalysisContext context, IEnumerable<TypeMapping> mappings)
88-
{
89-
var identifier = (CSSyntax.ClassDeclarationSyntax)context.Node;
90-
AnalyzeIdentifier(context, mappings, identifier.Identifier.ValueText);
91-
}
92-
93-
/// <summary>
94-
/// Analyzes an identifier syntax node to determine if it likely represents any of the types present
95-
/// in <see cref="IdentifierMappings"/>.
96-
/// </summary>
97-
/// <param name="context">The syntax node analysis context including the identifier node to analyze.</param>
98-
/// <param name="mappings">Type mappings to use when upgrading types.</param>
99-
/// <param name="simpleName">The simple name of the identifier being analyzed.</param>
100-
private static void AnalyzeIdentifier(SyntaxNodeAnalysisContext context, IEnumerable<TypeMapping> mappings, string simpleName)
77+
private static void AnalyzeIdentifier(SyntaxNodeAnalysisContext context, IEnumerable<TypeMapping> mappings)
10178
{
10279
var classDirective = (CSSyntax.ClassDeclarationSyntax)context.Node;
10380
if (classDirective is null)
@@ -112,7 +89,6 @@ private static void AnalyzeIdentifier(SyntaxNodeAnalysisContext context, IEnumer
11289

11390
foreach (var baseType in classDirective.BaseList.Types)
11491
{
115-
//var baseType = classDirective.BaseList.Types.FirstOrDefault();
11692
if (baseType is null)
11793
{
11894
return;

src/EpiSourceUpdater/EpiClassReplacementsCodeFixProvider.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Collections.Immutable;
5-
using System.Linq;
6-
using System.Threading;
7-
using System.Threading.Tasks;
84
using Microsoft.CodeAnalysis;
95
using Microsoft.CodeAnalysis.CodeActions;
106
using Microsoft.CodeAnalysis.CodeFixes;
117
using Microsoft.CodeAnalysis.CSharp;
128
using Microsoft.CodeAnalysis.CSharp.Syntax;
13-
using Microsoft.CodeAnalysis.Editing;
14-
using Microsoft.CodeAnalysis.Formatting;
9+
using System.Collections.Immutable;
10+
using System.Linq;
11+
using System.Threading;
12+
using System.Threading.Tasks;
1513

1614
namespace Epi.Source.Updater
1715
{
@@ -27,11 +25,9 @@ public class EpiClassReplacementsCodeFixProvider : CodeFixProvider
2725
// the analyzer's ID in the code fix provider's FixableDiagnosticIds array.
2826
public sealed override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(EpiClassReplacementsAnalyzer.DiagnosticId);
2927

30-
public sealed override FixAllProvider GetFixAllProvider()
31-
{
28+
public sealed override FixAllProvider GetFixAllProvider() =>
3229
// See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/FixAllProvider.md for more information on Fix All Providers
33-
return WellKnownFixAllProviders.BatchFixer;
34-
}
30+
WellKnownFixAllProviders.BatchFixer;
3531

3632
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
3733
{
@@ -67,13 +63,13 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
6763
private static async Task<Document> ReplaceClassesAsync(Document document, BaseTypeSyntax localDeclaration, string newIdentifier, CancellationToken cancellationToken)
6864
{
6965
var baseType = localDeclaration;
70-
SimpleNameSyntax genericName = (SimpleNameSyntax)baseType.Type;
66+
var genericName = (SimpleNameSyntax)baseType.Type;
7167

7268
var newnode = genericName.WithIdentifier(SyntaxFactory.Identifier(newIdentifier));
7369

7470
var syntaxTree = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
7571

76-
SyntaxNode newRoot = syntaxTree!.ReplaceNode(genericName, newnode);
72+
var newRoot = syntaxTree!.ReplaceNode(genericName, newnode);
7773
return document.WithSyntaxRoot(newRoot);
7874
}
7975
}

0 commit comments

Comments
 (0)