Skip to content

Commit 6bc683d

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 796d00e + 311fffe commit 6bc683d

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

System.IO.Abstractions.Analyzers.Tests/TestData/CodeFix/FileCodeFix/AfterFix.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ namespace SomeNameSpace
44
{
55
public class WithOutFileSystem
66
{
7-
private readonly IFileSystem _fileSystem;
7+
private readonly IFileSystem _fSystem;
88

99
public WithOutFileSystem(IFileSystem fileSystem)
1010
{
11-
_fileSystem = fileSystem;
11+
_fSystem = fileSystem;
1212
}
1313

1414
public void SomeMethod()
1515
{
1616
const string filePath = "C:\\temp.txt";
1717

18-
_fileSystem.File.Delete(filePath);
18+
_fSystem.File.Delete(filePath);
1919
}
2020
}
2121
}

System.IO.Abstractions.Analyzers.Tests/TestData/CodeFix/FileCodeFix/BeforeFix.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace SomeNameSpace
44
{
55
public class WithOutFileSystem
66
{
7-
private readonly IFileSystem _fileSystem;
7+
private readonly IFileSystem _fSystem;
88

99
public WithOutFileSystem(IFileSystem fileSystem)
1010
{
11-
_fileSystem = fileSystem;
11+
_fSystem = fileSystem;
1212
}
1313

1414
public void SomeMethod()

System.IO.Abstractions.Analyzers/CodeActions/FileSystemInvokeCodeAction.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,28 @@ public class FileSystemInvokeCodeAction : CodeAction
1414

1515
private readonly InvocationExpressionSyntax _invocation;
1616

17+
private readonly FieldDeclarationSyntax _field;
18+
1719
public override string Title { get; }
1820

1921
public override string EquivalenceKey => Title;
2022

21-
public FileSystemInvokeCodeAction(string title, Document document, InvocationExpressionSyntax invocation)
23+
public FileSystemInvokeCodeAction(string title, Document document, InvocationExpressionSyntax invocation,
24+
FieldDeclarationSyntax field)
2225
{
2326
Title = title;
2427
_document = document;
2528
_invocation = invocation;
29+
_field = field;
2630
}
2731

2832
protected override async Task<Document> GetChangedDocumentAsync(CancellationToken cancellationToken)
2933
{
3034
var editor = await DocumentEditor.CreateAsync(_document, cancellationToken).ConfigureAwait(false);
3135

3236
editor.ReplaceNode(_invocation,
33-
SF.ParseExpression($"{Constants.FieldFileSystemName}.{_invocation.NormalizeWhitespace().ToFullString()}"));
37+
SF.ParseExpression(
38+
$"{_field.Declaration.Variables.FirstOrDefault().Identifier.Text}.{_invocation.NormalizeWhitespace().ToFullString()}"));
3439

3540
return editor.GetChangedDocument();
3641
}

System.IO.Abstractions.Analyzers/CodeFixes/BaseInvokeCodeFix.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO.Abstractions.Analyzers.RoslynToken;
44
using System.Linq;
55
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.CodeFixes;
78
using Microsoft.CodeAnalysis.CSharp.Syntax;
89

@@ -26,9 +27,15 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
2627
{
2728
var invocation = root.FindNode(context.Span).FirstAncestorOrSelf<InvocationExpressionSyntax>();
2829

30+
var @class = root.FindNode(context.Span)
31+
.FirstAncestorOrSelf<ClassDeclarationSyntax>();
32+
33+
var field = RoslynClassFileSystem.GetFileSystemFieldFromClass(@class);
34+
2935
context.RegisterCodeFix(new FileSystemInvokeCodeAction(Title,
3036
context.Document,
31-
invocation),
37+
invocation,
38+
field),
3239
context.Diagnostics);
3340
}
3441
}

0 commit comments

Comments
 (0)