-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
104 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
using Analyzer.Utilities; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CodeFixes; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Microsoft.NetCore.Analyzers.Performance | ||
{ | ||
|
@@ -33,11 +32,10 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) | |
} | ||
|
||
var diagnostic = context.Diagnostics.FirstOrDefault(); | ||
|
||
if (!TryParseLocationInfo(diagnostic, DoNotGuardDictionaryRemoveByContainsKey.ConditionalOperation, out var conditionalOperationSpan) || | ||
!TryParseLocationInfo(diagnostic, DoNotGuardDictionaryRemoveByContainsKey.ChildStatementOperation, out var childStatementOperationSpan) || | ||
root.FindNode(conditionalOperationSpan) is not SyntaxNode conditionalSyntax || | ||
root.FindNode(childStatementOperationSpan) is not SyntaxNode childStatementSyntax) | ||
var conditionalOperationSpan = diagnostic.AdditionalLocations[0]; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
buyaa-n
Author
Contributor
|
||
var childLocation = diagnostic.AdditionalLocations[1]; | ||
if (root.FindNode(conditionalOperationSpan.SourceSpan) is not SyntaxNode conditionalSyntax || | ||
root.FindNode(childLocation.SourceSpan) is not SyntaxNode childStatementSyntax) | ||
{ | ||
return; | ||
} | ||
|
@@ -57,25 +55,6 @@ protected abstract Document ReplaceConditionWithChild(Document document, SyntaxN | |
SyntaxNode conditionalOperationNode, | ||
SyntaxNode childOperationNode); | ||
|
||
private static bool TryParseLocationInfo(Diagnostic diagnostic, string propertyKey, out TextSpan span) | ||
{ | ||
span = default; | ||
|
||
if (!diagnostic.Properties.TryGetValue(propertyKey, out var locationInfo)) | ||
return false; | ||
|
||
var parts = locationInfo.Split(DoNotGuardDictionaryRemoveByContainsKey.AdditionalDocumentLocationInfoSeparatorArray, StringSplitOptions.None); | ||
if (parts.Length != 2 || | ||
!int.TryParse(parts[0], out var spanStart) || | ||
!int.TryParse(parts[1], out var spanLength)) | ||
{ | ||
return false; | ||
} | ||
|
||
span = new TextSpan(spanStart, spanLength); | ||
return true; | ||
} | ||
|
||
private class DoNotGuardDictionaryRemoveByContainsKeyCodeAction : DocumentChangeAction | ||
{ | ||
public DoNotGuardDictionaryRemoveByContainsKeyCodeAction(Func<CancellationToken, Task<Document>> action) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Should we have a defensive check to verify there are 2 additional locations on the diagnostic?