Skip to content

Commit fad69be

Browse files
committed
Update code for API changes between CTP 5 and CTP 6
1 parent 77b93c7 commit fad69be

9 files changed

Lines changed: 26 additions & 83 deletions

OpenStackNetAnalyzers/OpenStackNetAnalyzers.Test/Helpers/DiagnosticVerifier.Helper.cs

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ protected static async Task<ImmutableArray<Diagnostic>> GetSortedDiagnosticsFrom
7070
foreach (var project in projects)
7171
{
7272
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
73-
var driver = AnalyzerDriver.Create(compilation, ImmutableArray.Create(analyzer), null, out compilation, cancellationToken);
74-
var discarded = compilation.GetDiagnostics(cancellationToken);
75-
var diags = await driver.GetDiagnosticsAsync().ConfigureAwait(false);
73+
var compilationWithAnalyzers = compilation.WithAnalyzers(ImmutableArray.Create(analyzer), null, cancellationToken);
74+
var diags = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().ConfigureAwait(false);
7675
foreach (var diag in diags)
7776
{
7877
if (diag.Location == Location.None || diag.Location.IsInMetadata)
@@ -106,7 +105,7 @@ protected static async Task<ImmutableArray<Diagnostic>> GetSortedDiagnosticsFrom
106105
/// <see cref="Diagnostic.Location"/>.</returns>
107106
private static Diagnostic[] SortDistinctDiagnostics(IEnumerable<Diagnostic> diagnostics)
108107
{
109-
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).Distinct(default(DiagnosticEqualityComparer)).ToArray();
108+
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
110109
}
111110

112111
#endregion
@@ -170,7 +169,7 @@ private static Project CreateProject(string[] sources, string language = Languag
170169

171170
var projectId = ProjectId.CreateNewId(debugName: TestProjectName);
172171

173-
var solution = new CustomWorkspace()
172+
var solution = new AdhocWorkspace()
174173
.CurrentSolution
175174
.AddProject(projectId, TestProjectName, TestProjectName, language)
176175
.AddMetadataReference(projectId, CorlibReference)
@@ -190,43 +189,5 @@ private static Project CreateProject(string[] sources, string language = Languag
190189
return solution.GetProject(projectId);
191190
}
192191
#endregion
193-
194-
/// <summary>
195-
/// A little helper to be able to use Enumerable.Distinct. Currently Roslyn does have a bug so that Diagnostic.GetHashCode()
196-
/// is not implemented correctly. <see href="https://github.com/dotnet/roslyn/issues/57"/>.
197-
/// </summary>
198-
struct DiagnosticEqualityComparer : IEqualityComparer<Diagnostic>
199-
{
200-
public bool Equals(Diagnostic x, Diagnostic y)
201-
{
202-
return (x == null && y == null)
203-
|| x.Equals(y);
204-
}
205-
206-
public int GetHashCode(Diagnostic obj)
207-
{
208-
return Combine(obj.Descriptor,
209-
Combine(obj.Location.GetHashCode(),
210-
Combine(obj.Severity.GetHashCode(), obj.WarningLevel)
211-
));
212-
}
213-
214-
int Combine<T>(T newKeyPart, int currentKey) where T : class
215-
{
216-
int hash = unchecked(currentKey * (int)0xA5555529);
217-
218-
if (newKeyPart != null)
219-
{
220-
return unchecked(hash + newKeyPart.GetHashCode());
221-
}
222-
223-
return hash;
224-
}
225-
int Combine(int newKey, int currentKey)
226-
{
227-
return unchecked((currentKey * (int)0xA5555529) + newKey);
228-
}
229-
}
230192
}
231193
}
232-

OpenStackNetAnalyzers/OpenStackNetAnalyzers.Test/Verifiers/CodeFixVerifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private async Task VerifyFixAsync(string language, DiagnosticAnalyzer analyzer,
9393
{
9494
var actions = new List<CodeAction>();
9595
var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), cancellationToken);
96-
await codeFixProvider.ComputeFixesAsync(context).ConfigureAwait(false);
96+
await codeFixProvider.RegisterCodeFixesAsync(context).ConfigureAwait(false);
9797

9898
if (!actions.Any())
9999
{

OpenStackNetAnalyzers/OpenStackNetAnalyzers/DocumentDelegatingApiCallCodeFix.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ public class DocumentDelegatingApiCallCodeFix : CodeFixProvider
2020
private static readonly ImmutableArray<string> _fixableDiagnostics =
2121
ImmutableArray.Create(DocumentDelegatingApiCallAnalyzer.DiagnosticId);
2222

23-
public sealed override ImmutableArray<string> GetFixableDiagnosticIds()
24-
{
25-
return _fixableDiagnostics;
26-
}
23+
public sealed override ImmutableArray<string> FixableDiagnosticIds => _fixableDiagnostics;
2724

2825
public override FixAllProvider GetFixAllProvider()
2926
{
3027
return WellKnownFixAllProviders.BatchFixer;
3128
}
3229

33-
public override async Task ComputeFixesAsync(CodeFixContext context)
30+
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3431
{
3532
foreach (var diagnostic in context.Diagnostics)
3633
{
@@ -47,7 +44,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
4744
continue;
4845

4946
string description = "Add documentation for delegating HTTP API call";
50-
context.RegisterFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, classDeclarationSyntax, cancellationToken)), diagnostic);
47+
context.RegisterCodeFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, classDeclarationSyntax, cancellationToken)), diagnostic);
5148
}
5249
}
5350

OpenStackNetAnalyzers/OpenStackNetAnalyzers/DocumentValueFromSummaryCodeFix.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ public class DocumentValueFromSummaryCodeFix : CodeFixProvider
1919
private static readonly ImmutableArray<string> _fixableDiagnostics =
2020
ImmutableArray.Create(DocumentValueFromSummaryAnalyzer.DiagnosticId);
2121

22-
public sealed override ImmutableArray<string> GetFixableDiagnosticIds()
23-
{
24-
return _fixableDiagnostics;
25-
}
22+
public sealed override ImmutableArray<string> FixableDiagnosticIds => _fixableDiagnostics;
2623

2724
public override FixAllProvider GetFixAllProvider()
2825
{
2926
return WellKnownFixAllProviders.BatchFixer;
3027
}
3128

32-
public override async Task ComputeFixesAsync(CodeFixContext context)
29+
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3330
{
3431
foreach (var diagnostic in context.Diagnostics)
3532
{
@@ -46,7 +43,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
4643
continue;
4744

4845
string description = "Document value from summary";
49-
context.RegisterFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, propertyDeclarationSyntax, cancellationToken)), diagnostic);
46+
context.RegisterCodeFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, propertyDeclarationSyntax, cancellationToken)), diagnostic);
5047
}
5148
}
5249

@@ -99,7 +96,7 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Prope
9996
if (index >= 0)
10097
valueText = valueText.Remove(index, 5);
10198

102-
SyntaxToken replaced = SyntaxFactory.Token(getsToken.LeadingTrivia, getsToken.CSharpKind(), text, valueText, getsToken.TrailingTrivia);
99+
SyntaxToken replaced = SyntaxFactory.Token(getsToken.LeadingTrivia, getsToken.Kind(), text, valueText, getsToken.TrailingTrivia);
103100
summaryContent = summaryContent.Replace(firstText, firstText.ReplaceToken(getsToken, replaced));
104101
}
105102
}
@@ -148,7 +145,7 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Prope
148145

149146
private bool IsContentElement(XmlNodeSyntax syntax)
150147
{
151-
switch (syntax.CSharpKind())
148+
switch (syntax.Kind())
152149
{
153150
case SyntaxKind.XmlCDataSection:
154151
case SyntaxKind.XmlElement:

OpenStackNetAnalyzers/OpenStackNetAnalyzers/DocumentationSyntaxExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static SyntaxList<XmlNodeSyntax> WithoutFirstAndLastNewlines(this SyntaxL
163163
{
164164
SyntaxToken newFirstToken = SyntaxFactory.Token(
165165
firstTextToken.LeadingTrivia,
166-
firstTextToken.CSharpKind(),
166+
firstTextToken.Kind(),
167167
trimmed,
168168
firstTextToken.ValueText.TrimStart(),
169169
firstTextToken.TrailingTrivia);

OpenStackNetAnalyzers/OpenStackNetAnalyzers/ImplementBuilderPatternCodeFix.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@ public class ImplementBuilderPatternCodeFix : CodeFixProvider
2020
private static readonly ImmutableArray<string> _fixableDiagnostics =
2121
ImmutableArray.Create(ImplementBuilderPatternAnalyzer.DiagnosticId);
2222

23-
public sealed override ImmutableArray<string> GetFixableDiagnosticIds()
24-
{
25-
return _fixableDiagnostics;
26-
}
23+
public sealed override ImmutableArray<string> FixableDiagnosticIds => _fixableDiagnostics;
2724

2825
public override FixAllProvider GetFixAllProvider()
2926
{
3027
// This code fix can only be applied to one property at a time
3128
return null;
3229
}
3330

34-
public override async Task ComputeFixesAsync(CodeFixContext context)
31+
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3532
{
3633
foreach (var diagnostic in context.Diagnostics)
3734
{
@@ -52,7 +49,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
5249
continue;
5350

5451
string description = string.Format("Implement builder method 'With{0}'", propertyDeclaration.Identifier.ValueText);
55-
context.RegisterFix(CodeAction.Create(description, cancellationToken => CreateChangedSolution(context, classDeclarationSyntax, propertyDeclaration, cancellationToken)), diagnostic);
52+
context.RegisterCodeFix(CodeAction.Create(description, cancellationToken => CreateChangedSolution(context, classDeclarationSyntax, propertyDeclaration, cancellationToken)), diagnostic);
5653
}
5754
}
5855

OpenStackNetAnalyzers/OpenStackNetAnalyzers/JsonObjectOptInCodeFix.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ public class JsonObjectOptInCodeFix : CodeFixProvider
2020
private static readonly ImmutableArray<string> _fixableDiagnostics =
2121
ImmutableArray.Create(JsonObjectOptInAnalyzer.DiagnosticId);
2222

23-
public sealed override ImmutableArray<string> GetFixableDiagnosticIds()
24-
{
25-
return _fixableDiagnostics;
26-
}
23+
public sealed override ImmutableArray<string> FixableDiagnosticIds => _fixableDiagnostics;
2724

2825
public override FixAllProvider GetFixAllProvider()
2926
{
3027
return WellKnownFixAllProviders.BatchFixer;
3128
}
3229

33-
public override async Task ComputeFixesAsync(CodeFixContext context)
30+
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3431
{
3532
foreach (var diagnostic in context.Diagnostics)
3633
{
@@ -120,7 +117,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
120117

121118
SyntaxNode newRoot = documentRoot.ReplaceNode(syntax, newAttribute);
122119
Document newDocument = context.Document.WithSyntaxRoot(newRoot);
123-
context.RegisterFix(CodeAction.Create("Add MemberSerialization.OptIn", newDocument), diagnostic);
120+
context.RegisterCodeFix(CodeAction.Create("Add MemberSerialization.OptIn", _ => Task.FromResult(newDocument)), diagnostic);
124121
}
125122
}
126123

OpenStackNetAnalyzers/OpenStackNetAnalyzers/JsonPropertyDefaultValueHandlingCodeFix.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ public class JsonPropertyDefaultValueHandlingCodeFix : CodeFixProvider
1818
private static readonly ImmutableArray<string> _fixableDiagnostics =
1919
ImmutableArray.Create(JsonPropertyDefaultValueHandlingAnalyzer.DiagnosticId);
2020

21-
public sealed override ImmutableArray<string> GetFixableDiagnosticIds()
22-
{
23-
return _fixableDiagnostics;
24-
}
21+
public sealed override ImmutableArray<string> FixableDiagnosticIds => _fixableDiagnostics;
2522

2623
public override FixAllProvider GetFixAllProvider()
2724
{
2825
return WellKnownFixAllProviders.BatchFixer;
2926
}
3027

31-
public override async Task ComputeFixesAsync(CodeFixContext context)
28+
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3229
{
3330
foreach (var diagnostic in context.Diagnostics)
3431
{
@@ -86,7 +83,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
8683

8784
SyntaxNode newRoot = documentRoot.ReplaceNode(syntax, newAttribute);
8885
Document newDocument = context.Document.WithSyntaxRoot(newRoot);
89-
context.RegisterFix(CodeAction.Create("Add DefaultValueHandling.Ignore", newDocument), diagnostic);
86+
context.RegisterCodeFix(CodeAction.Create("Add DefaultValueHandling.Ignore", _ => Task.FromResult(newDocument)), diagnostic);
9087
}
9188
}
9289
}

OpenStackNetAnalyzers/OpenStackNetAnalyzers/PlaceholderDocumentationCodeFix.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@ public class PlaceholderDocumentationCodeFix : CodeFixProvider
1717
private static readonly ImmutableArray<string> _fixableDiagnostics =
1818
ImmutableArray.Create(PlaceholderDocumentationAnalyzer.DiagnosticId);
1919

20-
public sealed override ImmutableArray<string> GetFixableDiagnosticIds()
21-
{
22-
return _fixableDiagnostics;
23-
}
20+
public sealed override ImmutableArray<string> FixableDiagnosticIds => _fixableDiagnostics;
2421

2522
public override FixAllProvider GetFixAllProvider()
2623
{
2724
// Require users review each removal of placeholder tags.
2825
return null;
2926
}
3027

31-
public override async Task ComputeFixesAsync(CodeFixContext context)
28+
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3229
{
3330
foreach (var diagnostic in context.Diagnostics)
3431
{
@@ -54,7 +51,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
5451
}
5552

5653
string description = "Finalize placeholder text";
57-
context.RegisterFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, xmlElementSyntax, cancellationToken)), diagnostic);
54+
context.RegisterCodeFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, xmlElementSyntax, cancellationToken)), diagnostic);
5855
}
5956
}
6057

0 commit comments

Comments
 (0)