Skip to content

Commit

Permalink
Merge pull request rubberduck-vba#3573 from IvenBach/Rubberdeck.Inspe…
Browse files Browse the repository at this point in the history
…ctions_C#6&7_Update

C#6/C#7 technical debt payment
  • Loading branch information
retailcoder committed Dec 14, 2017
2 parents 8657b1c + a60871b commit 7d8cfd9
Show file tree
Hide file tree
Showing 105 changed files with 223 additions and 422 deletions.
12 changes: 6 additions & 6 deletions Rubberduck.Inspections/Abstract/InspectionBase.cs
Expand Up @@ -36,7 +36,7 @@ protected InspectionBase(RubberduckParserState state, CodeInspectionSeverity def
/// <summary>
/// Gets a localized string representing a short name/description for the inspection.
/// </summary>
public virtual string Description => InspectionsUI.ResourceManager.GetString(Name + "Name", CultureInfo.CurrentUICulture);
public virtual string Description => InspectionsUI.ResourceManager.GetString($"{Name}Name", CultureInfo.CurrentUICulture);

/// <summary>
/// Gets the type of inspection; used for regrouping inspections.
Expand All @@ -56,13 +56,13 @@ protected InspectionBase(RubberduckParserState state, CodeInspectionSeverity def
/// <summary>
/// Meta-information about why an inspection exists.
/// </summary>
public virtual string Meta => InspectionsUI.ResourceManager.GetString(Name + "Meta", CultureInfo.CurrentUICulture);
public virtual string Meta => InspectionsUI.ResourceManager.GetString($"{Name}Meta", CultureInfo.CurrentUICulture);

/// <summary>
/// Gets a localized string representing the type of inspection.
/// <see cref="InspectionType"/>
/// </summary>
public virtual string InspectionTypeName => InspectionsUI.ResourceManager.GetString("CodeInspectionSettings_" + InspectionType.ToString(), CultureInfo.CurrentUICulture);
public virtual string InspectionTypeName => InspectionsUI.ResourceManager.GetString($"CodeInspectionSettings_{InspectionType.ToString()}", CultureInfo.CurrentUICulture);

/// <summary>
/// Gets a string representing the text that must be present in an
Expand Down Expand Up @@ -112,9 +112,9 @@ protected bool IsIgnoringInspectionResultFor(QualifiedModuleName module, int lin
return true;
}

if (ignoreModuleAnnotation != null &&
(ignoreModuleAnnotation.InspectionNames.Contains(AnnotationName) ||
!ignoreModuleAnnotation.InspectionNames.Any()))
if (ignoreModuleAnnotation != null
&& (ignoreModuleAnnotation.InspectionNames.Contains(AnnotationName)
|| !ignoreModuleAnnotation.InspectionNames.Any()))
{
return true;
}
Expand Down
15 changes: 11 additions & 4 deletions Rubberduck.Inspections/Abstract/InspectionResultBase.cs
Expand Up @@ -57,11 +57,15 @@ public int CompareTo(IInspectionResult other)
public string ToClipboardString()
{
var module = QualifiedSelection.QualifiedName;
var documentName = Target != null ? Target.ProjectDisplayName : string.Empty;
var documentName = Target != null
? Target.ProjectDisplayName
: string.Empty;
if (string.IsNullOrEmpty(documentName))
{
var component = module.Component;
documentName = component != null ? component.ParentProject.ProjectDisplayName : string.Empty;
documentName = component != null
? component.ParentProject.ProjectDisplayName
: string.Empty;
}
if (string.IsNullOrEmpty(documentName))
{
Expand All @@ -72,7 +76,7 @@ public string ToClipboardString()
InspectionsUI.QualifiedSelectionInspection,
Inspection.Severity,
Description,
"(" + documentName + ")",
$"({documentName})",
module.ProjectName,
module.ComponentName,
QualifiedSelection.Selection.StartLine);
Expand All @@ -81,7 +85,10 @@ public string ToClipboardString()
private NavigateCodeEventArgs _navigationArgs;
public NavigateCodeEventArgs GetNavigationArgs()
{
if (_navigationArgs != null) { return _navigationArgs; }
if (_navigationArgs != null)
{
return _navigationArgs;
}

_navigationArgs = new NavigateCodeEventArgs(QualifiedSelection);
return _navigationArgs;
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Results;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
using Rubberduck.Inspections.Abstract;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Results;
Expand Down
Expand Up @@ -35,16 +35,15 @@ public void AddResult(QualifiedContext<ParserRuleContext> qualifiedContext)

private bool BlockContainsExecutableStatements(VBAParser.BlockContext block)
{
return block != null && block.children != null && ContainsExecutableStatements(block);
return block?.children != null && ContainsExecutableStatements(block);
}

private bool ContainsExecutableStatements(VBAParser.BlockContext block)
{
foreach (var child in block.children)
{
if (child is VBAParser.BlockStmtContext)
if (child is VBAParser.BlockStmtContext blockStmt)
{
var blockStmt = (VBAParser.BlockStmtContext)child;
var mainBlockStmt = blockStmt.mainBlockStmt();

if (mainBlockStmt == null)
Expand Down
Expand Up @@ -5,7 +5,6 @@
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.Inspections.Resources;
using Rubberduck.Parsing.VBA;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down
Expand Up @@ -5,7 +5,6 @@
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.Inspections.Resources;
using Rubberduck.Parsing.VBA;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down
Expand Up @@ -5,7 +5,6 @@
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.Inspections.Resources;
using Rubberduck.Parsing.VBA;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down
Expand Up @@ -5,7 +5,6 @@
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.Inspections.Resources;
using Rubberduck.Parsing.VBA;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down
Expand Up @@ -5,7 +5,6 @@
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.Inspections.Resources;
using Rubberduck.Parsing.VBA;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down
1 change: 0 additions & 1 deletion Rubberduck.Inspections/Concrete/EmptyIfBlockInspection.cs
Expand Up @@ -7,7 +7,6 @@
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.Inspections.Resources;
using Rubberduck.Parsing.VBA;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down
3 changes: 1 addition & 2 deletions Rubberduck.Inspections/Concrete/EmptyModuleInspection.cs
Expand Up @@ -7,15 +7,14 @@
using Rubberduck.Parsing.Inspections.Resources;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.SafeComWrappers;

namespace Rubberduck.Inspections.Concrete
{

public sealed class EmptyModuleInspection : InspectionBase
{
private EmptyModuleVisitor _emptyModuleVisitor;
private readonly EmptyModuleVisitor _emptyModuleVisitor;

public EmptyModuleInspection(RubberduckParserState state,
CodeInspectionSeverity defaultSeverity = CodeInspectionSeverity.Hint)
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
using Rubberduck.Inspections.Abstract;
Expand Down
Expand Up @@ -5,7 +5,6 @@
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.Inspections.Resources;
using Rubberduck.Parsing.VBA;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Results;
Expand Down
Expand Up @@ -77,35 +77,13 @@ private bool IsRecursive(Declaration function)

private bool IsReturnValueUsed(Declaration function)
{
foreach (var usage in function.References)
{
if (IsAddressOfCall(usage))
{
continue;
}
if (IsTypeOfExpression(usage))
{
continue;
}
if (IsCallStmt(usage)) // IsIndexExprOrCallStmt(usage))
{
continue;
}
if (IsLet(usage))
{
continue;
}
if (IsSet(usage))
{
continue;
}
if (IsReturnStatement(function, usage))
{
continue;
}
return true;
}
return false;
return (from usage in function.References
where !IsAddressOfCall(usage)
where !IsTypeOfExpression(usage)
where !IsCallStmt(usage)
where !IsLet(usage)
where !IsSet(usage)
select usage).Any(usage => !IsReturnStatement(function, usage));
}

private bool IsAddressOfCall(IdentifierReference usage)
Expand Down Expand Up @@ -161,23 +139,15 @@ private bool IsIndexExprContext(IdentifierReference usage)
private bool IsLet(IdentifierReference usage)
{
var letStmt = ParserRuleContextHelper.GetParent<VBAParser.LetStmtContext>(usage.Context);
if (letStmt == null)
{
return false;
}
bool isLetAssignmentTarget = letStmt == usage.Context;
return isLetAssignmentTarget;

return letStmt != null && letStmt == usage.Context;
}

private bool IsSet(IdentifierReference usage)
{
var setStmt = ParserRuleContextHelper.GetParent<VBAParser.SetStmtContext>(usage.Context);
if (setStmt == null)
{
return false;
}
bool isSetAssignmentTarget = setStmt == usage.Context;
return isSetAssignmentTarget;

return setStmt != null && setStmt == usage.Context;
}
}
}
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -119,7 +118,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
HungarianIdentifierRegex.IsMatch(declaration.IdentifierName))
.Select(issue => new DeclarationInspectionResult(this,
string.Format(InspectionsUI.IdentifierNameInspectionResultFormat,
RubberduckUI.ResourceManager.GetString("DeclarationType_" + issue.DeclarationType, CultureInfo.CurrentUICulture),
RubberduckUI.ResourceManager.GetString($"DeclarationType_{issue.DeclarationType}", CultureInfo.CurrentUICulture),
issue.IdentifierName),
issue));

Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Results;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
Expand Down
7 changes: 3 additions & 4 deletions Rubberduck.Inspections/Concrete/IntegerDataTypeInspection.cs
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Rubberduck.Common;
Expand All @@ -20,7 +19,7 @@ public IntegerDataTypeInspection(RubberduckParserState state) : base(state, Code
{
}

public override CodeInspectionType InspectionType { get; } = CodeInspectionType.CodeQualityIssues;
public override CodeInspectionType InspectionType => CodeInspectionType.CodeQualityIssues;

protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
{
Expand All @@ -38,7 +37,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
.Select(issue =>
new DeclarationInspectionResult(this,
string.Format(InspectionsUI.IntegerDataTypeInspectionResultFormat,
RubberduckUI.ResourceManager.GetString("DeclarationType_" + issue.DeclarationType, CultureInfo.CurrentUICulture), issue.IdentifierName),
RubberduckUI.ResourceManager.GetString($"DeclarationType_{issue.DeclarationType}", CultureInfo.CurrentUICulture), issue.IdentifierName),
issue));

return result;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Results;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
Expand Down
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Antlr4.Runtime;
using Rubberduck.Inspections.Abstract;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
Expand Down

0 comments on commit 7d8cfd9

Please sign in to comment.