Skip to content

Commit 143deca

Browse files
committed
Resharper code cleanup
1 parent cb70531 commit 143deca

18 files changed

+93
-66
lines changed

System.IO.Abstractions.Analyzers/Analyzers/BaseFileSystemAnalyzer.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ public override void Initialize(AnalysisContext context)
2929
/// <summary>
3030
/// Analysis
3131
/// </summary>
32-
/// <param name="compilationStartContext">Compilation Start Analysis Context</param>
33-
/// <param name="fileSystemContext">FileSystem Context</param>
32+
/// <param name="compilationStartContext"> Compilation Start Analysis Context </param>
33+
/// <param name="fileSystemContext"> FileSystem Context </param>
3434
protected abstract void AnalyzeCompilation(CompilationStartAnalysisContext compilationStartContext,
3535
FileSystemContext fileSystemContext);
3636

37-
private static bool ShouldAnalyze(FileSystemContext fileSystemContext) => fileSystemContext.HasReference;
37+
private static bool ShouldAnalyze(FileSystemContext fileSystemContext)
38+
{
39+
return fileSystemContext.HasReference;
40+
}
3841
}
3942
}

System.IO.Abstractions.Analyzers/Analyzers/BaseFileSystemNodeAnalyzer.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,22 @@ protected override void AnalyzeCompilation(CompilationStartAnalysisContext compi
4242

4343
protected abstract Type GetFileSystemType();
4444

45-
private bool IsNotUsedSystemIo() => typeof(Path).Namespace != GetFileSystemType().Namespace;
45+
private bool IsNotUsedSystemIo()
46+
{
47+
return typeof(Path).Namespace != GetFileSystemType().Namespace;
48+
}
4649

47-
private bool IsTypesEquals(TypeSyntax type) => type.NormalizeWhitespace().ToFullString() == GetFileSystemType().Name;
50+
private bool IsTypesEquals(TypeSyntax type)
51+
{
52+
return type.NormalizeWhitespace().ToFullString() == GetFileSystemType().Name;
53+
}
4854

49-
private bool IsStaticInvocationStartWith(InvocationExpressionSyntax invocation) =>
50-
invocation.IsKind(SyntaxKind.InvocationExpression)
51-
&& invocation.Expression.NormalizeWhitespace()
52-
.ToFullString()
53-
.StartsWith(GetFileSystemType().Name + ".", StringComparison.CurrentCultureIgnoreCase);
55+
private bool IsStaticInvocationStartWith(InvocationExpressionSyntax invocation)
56+
{
57+
return invocation.IsKind(SyntaxKind.InvocationExpression)
58+
&& invocation.Expression.NormalizeWhitespace()
59+
.ToFullString()
60+
.StartsWith(GetFileSystemType().Name + ".", StringComparison.CurrentCultureIgnoreCase);
61+
}
5462
}
5563
}

System.IO.Abstractions.Analyzers/Analyzers/FileSystemTypeAnalyzers/DirectoryAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace System.IO.Abstractions.Analyzers.Analyzers.FileSystemTypeAnalyzers
88
{
9-
[DiagnosticAnalyzer(LanguageNames.CSharp)]
10-
public class DirectoryAnalyzer : BaseFileSystemNodeAnalyzer
9+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
10+
public class DirectoryAnalyzer : BaseFileSystemNodeAnalyzer
1111
{
1212
/// <summary>
1313
/// Diagnostic Identifier

System.IO.Abstractions.Analyzers/Analyzers/FileSystemTypeAnalyzers/DirectoryInfoAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace System.IO.Abstractions.Analyzers.Analyzers.FileSystemTypeAnalyzers
88
{
9-
[DiagnosticAnalyzer(LanguageNames.CSharp)]
10-
public class DirectoryInfoAnalyzer: BaseFileSystemNodeAnalyzer
9+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
10+
public class DirectoryInfoAnalyzer : BaseFileSystemNodeAnalyzer
1111
{
1212
/// <summary>
1313
/// Diagnostic Identifier

System.IO.Abstractions.Analyzers/Analyzers/FileSystemTypeAnalyzers/FileAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace System.IO.Abstractions.Analyzers.Analyzers.FileSystemTypeAnalyzers
88
{
9-
[DiagnosticAnalyzer(LanguageNames.CSharp)]
10-
public class FileAnalyzer : BaseFileSystemNodeAnalyzer
9+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
10+
public class FileAnalyzer : BaseFileSystemNodeAnalyzer
1111
{
1212
/// <summary>
1313
/// Diagnostic Identifier

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ namespace System.IO.Abstractions.Analyzers.CodeActions
1212
{
1313
public class DirectoryInfoCodeAction : CodeAction
1414
{
15-
private readonly Document _document;
16-
1715
private readonly ObjectCreationExpressionSyntax _creationExpressionSyntax;
1816

19-
private readonly FieldDeclarationSyntax _field;
20-
21-
public override string Title { get; }
17+
private readonly Document _document;
2218

23-
public override string EquivalenceKey => Title;
19+
private readonly FieldDeclarationSyntax _field;
2420

2521
public DirectoryInfoCodeAction(string title, Document document, ObjectCreationExpressionSyntax creationExpressionSyntax,
2622
FieldDeclarationSyntax field)
@@ -31,6 +27,10 @@ public DirectoryInfoCodeAction(string title, Document document, ObjectCreationEx
3127
_field = field;
3228
}
3329

30+
public override string Title { get; }
31+
32+
public override string EquivalenceKey => Title;
33+
3434
protected override async Task<Document> GetChangedDocumentAsync(CancellationToken cancellationToken)
3535
{
3636
var editor = await DocumentEditor.CreateAsync(_document, cancellationToken).ConfigureAwait(false);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ namespace System.IO.Abstractions.Analyzers.CodeActions
1212
{
1313
public class FileInfoCodeAction : CodeAction
1414
{
15-
private readonly Document _document;
16-
1715
private readonly ObjectCreationExpressionSyntax _creationExpressionSyntax;
1816

19-
private readonly FieldDeclarationSyntax _field;
20-
21-
public override string Title { get; }
17+
private readonly Document _document;
2218

23-
public override string EquivalenceKey => Title;
19+
private readonly FieldDeclarationSyntax _field;
2420

2521
public FileInfoCodeAction(string title, Document document, ObjectCreationExpressionSyntax creationExpressionSyntax,
26-
FieldDeclarationSyntax field)
22+
FieldDeclarationSyntax field)
2723
{
2824
Title = title;
2925
_document = document;
3026
_creationExpressionSyntax = creationExpressionSyntax;
3127
_field = field;
3228
}
3329

30+
public override string Title { get; }
31+
32+
public override string EquivalenceKey => Title;
33+
3434
protected override async Task<Document> GetChangedDocumentAsync(CancellationToken cancellationToken)
3535
{
3636
var editor = await DocumentEditor.CreateAsync(_document, cancellationToken).ConfigureAwait(false);

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.CodeAnalysis.Editing;
99
using Microsoft.CodeAnalysis.Formatting;
1010
using Microsoft.CodeAnalysis.Simplification;
11-
using SyntaxNode = Microsoft.CodeAnalysis.SyntaxNode;
1211
using SF = Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
1312

1413
namespace System.IO.Abstractions.Analyzers.CodeActions
@@ -76,35 +75,34 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
7675

7776
private static ExpressionStatementSyntax CreateAssignmentExpression(string field = Constants.FieldFileSystemName)
7877
{
79-
return SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
80-
SyntaxFactory.IdentifierName(field),
81-
SyntaxFactory.ObjectCreationExpression(SyntaxFactory.IdentifierName(Constants.FileSystemClassName))
82-
.WithArgumentList(SyntaxFactory.ArgumentList())));
78+
return SF.ExpressionStatement(SF.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
79+
SF.IdentifierName(field),
80+
SF.ObjectCreationExpression(SF.IdentifierName(Constants.FileSystemClassName))
81+
.WithArgumentList(SF.ArgumentList())));
8382
}
8483

8584
private static void ConstructorAddParameter(ClassDeclarationSyntax classDeclaration, SyntaxEditor editor)
8685
{
8786
var constructor = RoslynClassFileSystem.HasConstructor(classDeclaration)
8887
? RoslynClassFileSystem.GetConstructor(classDeclaration)
8988
: SF.ConstructorDeclaration(classDeclaration.Identifier)
90-
.WithModifiers(SyntaxTokenList.Create(SyntaxFactory.Token(SyntaxKind.PublicKeyword)));
89+
.WithModifiers(SyntaxTokenList.Create(SF.Token(SyntaxKind.PublicKeyword)));
9190

9291
var newConstructor = constructor.WithAdditionalAnnotations(Formatter.Annotation, Simplifier.Annotation)
9392
.NormalizeWhitespace();
9493

9594
if (!RoslynClassFileSystem.ConstructorHasAssignmentExpression(newConstructor))
9695
{
96+
var statementSyntax = CreateAssignmentExpression();
97+
9798
if (RoslynClassFileSystem.HasFileSystemField(classDeclaration))
9899
{
99100
var fileSystem = RoslynClassFileSystem.GetFileSystemFieldFromClass(classDeclaration);
100-
101-
newConstructor =
102-
newConstructor.AddBodyStatements(CreateAssignmentExpression(fileSystem.Declaration.Variables.ToFullString()));
103-
} else
104-
{
105-
newConstructor =
106-
newConstructor.AddBodyStatements(CreateAssignmentExpression());
101+
statementSyntax = CreateAssignmentExpression(fileSystem.Declaration.Variables.ToFullString());
107102
}
103+
104+
newConstructor =
105+
newConstructor.AddBodyStatements(statementSyntax);
108106
}
109107

110108
if (RoslynClassFileSystem.HasConstructor(classDeclaration))

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ namespace System.IO.Abstractions.Analyzers.CodeActions
1212
{
1313
public class FileStreamCodeAction : CodeAction
1414
{
15-
private readonly Document _document;
16-
1715
private readonly ObjectCreationExpressionSyntax _creationExpressionSyntax;
1816

19-
private readonly FieldDeclarationSyntax _field;
20-
21-
public override string Title { get; }
17+
private readonly Document _document;
2218

23-
public override string EquivalenceKey => Title;
19+
private readonly FieldDeclarationSyntax _field;
2420

2521
public FileStreamCodeAction(string title, Document document, ObjectCreationExpressionSyntax creationExpressionSyntax,
2622
FieldDeclarationSyntax field)
@@ -31,6 +27,10 @@ public FileStreamCodeAction(string title, Document document, ObjectCreationExpre
3127
_field = field;
3228
}
3329

30+
public override string Title { get; }
31+
32+
public override string EquivalenceKey => Title;
33+
3434
protected override async Task<Document> GetChangedDocumentAsync(CancellationToken cancellationToken)
3535
{
3636
var editor = await DocumentEditor.CreateAsync(_document, cancellationToken).ConfigureAwait(false);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@ public class FileSystemInvokeCodeAction : CodeAction
1313
{
1414
private readonly Document _document;
1515

16-
private readonly InvocationExpressionSyntax _invocation;
17-
1816
private readonly FieldDeclarationSyntax _field;
1917

20-
public override string Title { get; }
21-
22-
public override string EquivalenceKey => Title;
18+
private readonly InvocationExpressionSyntax _invocation;
2319

2420
public FileSystemInvokeCodeAction(string title, Document document, InvocationExpressionSyntax invocation,
2521
FieldDeclarationSyntax field)
@@ -30,6 +26,10 @@ public FileSystemInvokeCodeAction(string title, Document document, InvocationExp
3026
_field = field;
3127
}
3228

29+
public override string Title { get; }
30+
31+
public override string EquivalenceKey => Title;
32+
3333
protected override async Task<Document> GetChangedDocumentAsync(CancellationToken cancellationToken)
3434
{
3535
var editor = await DocumentEditor.CreateAsync(_document, cancellationToken).ConfigureAwait(false);

0 commit comments

Comments
 (0)