Skip to content

Commit c409f6c

Browse files
committed
Merge branch 'next' into CommandHierarchyCanExecuteConditions
2 parents 778d916 + b5942fb commit c409f6c

File tree

69 files changed

+232
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+232
-145
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ along with this program. If not, see http://www.gnu.org/licenses/.
5959

6060
[![JetBrains ReSharper logo](https://cloud.githubusercontent.com/assets/5751684/20271309/616bb740-aa58-11e6-91c9-65287b740985.png)](https://www.jetbrains.com/resharper/)
6161

62-
Since the project's early days, JetBrains' Open-Source team has been supporting Rubberduck - and we deeply thank them for that. ReSharper has been not only a tool we couldn't do without; it's been an inspiration, the ultimate level of polished perfection to strive for in our own IDE add-in project. So just like you're missing out if you write VBA and you're not using Rubberduck, you're missing out if you write C# and aren't using ReSharper.
62+
Since the project's early days, JetBrains' Open-Source team has been supporting Rubberduck with free OSS licenses for all core contributors - and we deeply thank them for that. ReSharper has been not only a tool we couldn't do without; it's been an inspiration, the ultimate level of polished perfection to strive for in our own IDE add-in project. So just like you're missing out if you write VBA and you're not using Rubberduck, you're missing out if you write C# and aren't using ReSharper.
6363

6464
<sub>Note: Rubberduck is not a JetBrains product. JetBrains does not contribute and is not affiliated to the Rubberduck project in any way.</sub>

Rubberduck.CodeAnalysis/Inspections/Abstract/InspectionBase.cs

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Threading;
1212
using NLog;
1313
using Rubberduck.Parsing.Inspections;
14+
using Rubberduck.Inspections.Inspections.Extensions;
1415

1516
namespace Rubberduck.Inspections.Abstract
1617
{
@@ -68,78 +69,22 @@ protected InspectionBase(RubberduckParserState state)
6869
/// </summary>
6970
protected virtual IEnumerable<Declaration> Declarations
7071
{
71-
get { return State.AllDeclarations.Where(declaration => !IsIgnoringInspectionResultFor(declaration, AnnotationName)); }
72+
get { return State.AllDeclarations.Where(declaration => !declaration.IsIgnoringInspectionResultFor(AnnotationName)); }
7273
}
7374

7475
/// <summary>
7576
/// Gets all user declarations in the parser state without an @Ignore annotation for this inspection.
7677
/// </summary>
7778
protected virtual IEnumerable<Declaration> UserDeclarations
7879
{
79-
get { return State.AllUserDeclarations.Where(declaration => !IsIgnoringInspectionResultFor(declaration, AnnotationName)); }
80+
get { return State.AllUserDeclarations.Where(declaration => !declaration.IsIgnoringInspectionResultFor(AnnotationName)); }
8081
}
8182

8283
protected virtual IEnumerable<Declaration> BuiltInDeclarations
8384
{
8485
get { return State.AllDeclarations.Where(declaration => !declaration.IsUserDefined); }
8586
}
8687

87-
protected bool IsIgnoringInspectionResultFor(QualifiedModuleName module, int line)
88-
{
89-
var lineScopedAnnotations = State.DeclarationFinder.FindAnnotations(module, line);
90-
foreach (var ignoreAnnotation in lineScopedAnnotations.OfType<IgnoreAnnotation>())
91-
{
92-
if (ignoreAnnotation.InspectionNames.Contains(AnnotationName))
93-
{
94-
return true;
95-
}
96-
}
97-
98-
var moduleDeclaration = State.DeclarationFinder.Members(module)
99-
.First(decl => decl.DeclarationType.HasFlag(DeclarationType.Module));
100-
101-
foreach (var ignoreModuleAnnotation in moduleDeclaration.Annotations.OfType<IgnoreModuleAnnotation>())
102-
{
103-
if (ignoreModuleAnnotation.InspectionNames.Contains(AnnotationName)
104-
|| !ignoreModuleAnnotation.InspectionNames.Any())
105-
{
106-
return true;
107-
}
108-
}
109-
110-
return false;
111-
}
112-
113-
protected bool IsIgnoringInspectionResultFor(Declaration declaration, string inspectionName)
114-
{
115-
var module = Declaration.GetModuleParent(declaration);
116-
if (module == null)
117-
{
118-
return false;
119-
}
120-
121-
var isIgnoredAtModuleLevel = module.Annotations
122-
.Any(annotation => annotation.AnnotationType == AnnotationType.IgnoreModule
123-
&& ((IgnoreModuleAnnotation) annotation).IsIgnored(inspectionName));
124-
125-
126-
if (declaration.DeclarationType == DeclarationType.Parameter)
127-
{
128-
return isIgnoredAtModuleLevel || declaration.ParentDeclaration.Annotations.Any(annotation =>
129-
annotation.AnnotationType == AnnotationType.Ignore
130-
&& ((IgnoreAnnotation)annotation).IsIgnored(inspectionName));
131-
}
132-
133-
return isIgnoredAtModuleLevel || declaration.Annotations.Any(annotation =>
134-
annotation.AnnotationType == AnnotationType.Ignore
135-
&& ((IgnoreAnnotation)annotation).IsIgnored(inspectionName));
136-
}
137-
138-
protected bool IsIgnoringInspectionResultFor(IdentifierReference reference, string inspectionName)
139-
{
140-
return reference != null && reference.IsIgnoringInspectionResultFor(inspectionName);
141-
}
142-
14388
public int CompareTo(IInspection other)
14489
{
14590
return string.Compare(InspectionType + Name, other.InspectionType + other.Name, StringComparison.Ordinal);

Rubberduck.CodeAnalysis/Inspections/Abstract/MemberAccessMayReturnNothingInspectionBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Antlr4.Runtime.Tree;
44
using Rubberduck.Inspections.CodePathAnalysis;
55
using Rubberduck.Inspections.CodePathAnalysis.Nodes;
6+
using Rubberduck.Inspections.Inspections.Extensions;
67
using Rubberduck.Inspections.Results;
78
using Rubberduck.Parsing;
89
using Rubberduck.Parsing.Grammar;
@@ -28,7 +29,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2829
}
2930

3031
var output = new List<IInspectionResult>();
31-
foreach (var reference in interesting.Where(use => !IsIgnoringInspectionResultFor(use, AnnotationName)))
32+
foreach (var reference in interesting.Where(use => !use.IsIgnoringInspectionResultFor(AnnotationName)))
3233
{
3334
var access = reference.Context.GetAncestor<VBAParser.MemberAccessExprContext>();
3435
var usageContext = access.Parent is VBAParser.IndexExprContext

Rubberduck.CodeAnalysis/Inspections/Concrete/ApplicationWorksheetFunctionInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Rubberduck.Parsing.Symbols;
99
using Rubberduck.Parsing.VBA;
1010
using Rubberduck.VBEditor;
11+
using Rubberduck.Inspections.Inspections.Extensions;
1112

1213
namespace Rubberduck.Inspections.Concrete
1314
{
@@ -33,7 +34,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3334
members.Contains(decl.IdentifierName));
3435

3536
return from usage in usages
36-
from reference in usage.References.Where(use => !IsIgnoringInspectionResultFor(use, AnnotationName))
37+
from reference in usage.References.Where(use => !use.IsIgnoringInspectionResultFor(AnnotationName))
3738
let qualifiedSelection = new QualifiedSelection(reference.QualifiedModuleName, reference.Selection)
3839
select new IdentifierReferenceInspectionResult(this,
3940
string.Format(InspectionResults.ApplicationWorksheetFunctionInspection, usage.IdentifierName),

Rubberduck.CodeAnalysis/Inspections/Concrete/AssignedByValParameterInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Rubberduck.Resources.Inspections;
77
using Rubberduck.Parsing.Symbols;
88
using Rubberduck.Parsing.VBA;
9+
using Rubberduck.Inspections.Inspections.Extensions;
910

1011
namespace Rubberduck.Inspections.Concrete
1112
{
@@ -20,7 +21,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2021
var parameters = State.DeclarationFinder.UserDeclarations(DeclarationType.Parameter)
2122
.Cast<ParameterDeclaration>()
2223
.Where(item => !item.IsByRef
23-
&& !IsIgnoringInspectionResultFor(item, AnnotationName)
24+
&& !item.IsIgnoringInspectionResultFor(AnnotationName)
2425
&& item.References.Any(reference => reference.IsAssignment));
2526

2627
return parameters

Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using Rubberduck.Inspections.Results;
1010
using Rubberduck.Parsing.Grammar;
11+
using Rubberduck.Inspections.Inspections.Extensions;
1112

1213
namespace Rubberduck.Inspections.Concrete
1314
{
@@ -46,6 +47,9 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
4647
}
4748

4849
return nodes
50+
.Where(issue => !issue.IsIgnoringInspectionResultFor(AnnotationName)
51+
// Ignoring the Declaration disqualifies all assignments
52+
&& !issue.Declaration.IsIgnoringInspectionResultFor(AnnotationName))
4953
.Select(issue => new IdentifierReferenceInspectionResult(this, Description, State, issue))
5054
.ToList();
5155
}

Rubberduck.CodeAnalysis/Inspections/Concrete/BooleanAssignedInIfElseInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Rubberduck.Resources.Inspections;
1010
using Rubberduck.Parsing.VBA;
1111
using Rubberduck.VBEditor;
12+
using Rubberduck.Inspections.Inspections.Extensions;
1213

1314
namespace Rubberduck.Inspections.Concrete
1415
{
@@ -23,7 +24,7 @@ public BooleanAssignedInIfElseInspection(RubberduckParserState state)
2324
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2425
{
2526
return Listener.Contexts
26-
.Where(result => !IsIgnoringInspectionResultFor(result.ModuleName, result.Context.Start.Line))
27+
.Where(result => !result.IsIgnoringInspectionResultFor(State.DeclarationFinder, AnnotationName))
2728
.Select(result => new QualifiedContextInspectionResult(this,
2829
string.Format(InspectionResults.BooleanAssignedInIfElseInspection,
2930
(((VBAParser.IfStmtContext)result.Context).block().GetDescendent<VBAParser.LetStmtContext>()).lExpression().GetText().Trim()),

Rubberduck.CodeAnalysis/Inspections/Concrete/ConstantNotUsedInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Rubberduck.Resources.Inspections;
1010
using Rubberduck.Parsing.Symbols;
1111
using Rubberduck.Parsing.VBA;
12+
using Rubberduck.Inspections.Inspections.Extensions;
1213

1314
namespace Rubberduck.Inspections.Concrete
1415
{
@@ -22,7 +23,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2223
var results = State.DeclarationFinder.UserDeclarations(DeclarationType.Constant)
2324
.Where(declaration => declaration.Context != null
2425
&& !declaration.References.Any()
25-
&& !IsIgnoringInspectionResultFor(declaration, AnnotationName))
26+
&& !declaration.IsIgnoringInspectionResultFor(AnnotationName))
2627
.ToList();
2728

2829
return results.Select(issue =>

Rubberduck.CodeAnalysis/Inspections/Concrete/DefTypeStatementInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Rubberduck.VBEditor;
1111
using Antlr4.Runtime.Misc;
1212
using Rubberduck.Inspections.Results;
13+
using Rubberduck.Inspections.Inspections.Extensions;
1314

1415
namespace Rubberduck.Inspections.Concrete
1516
{
@@ -25,7 +26,7 @@ public DefTypeStatementInspection(RubberduckParserState state)
2526

2627
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2728
{
28-
var results = Listener.Contexts.Where(context => !IsIgnoringInspectionResultFor(context.ModuleName, context.Context.Start.Line))
29+
var results = Listener.Contexts.Where(context => !context.IsIgnoringInspectionResultFor(State.DeclarationFinder, AnnotationName))
2930
.Select(context => new QualifiedContextInspectionResult(this,
3031
string.Format(InspectionResults.DefTypeStatementInspection,
3132
GetTypeOfDefType(context.Context.start.Text),

Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyCaseBlockInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Collections.Generic;
1010
using System.Linq;
1111
using Rubberduck.Resources.Experimentals;
12+
using Rubberduck.Inspections.Inspections.Extensions;
1213

1314
namespace Rubberduck.Inspections.Concrete
1415
{
@@ -24,7 +25,7 @@ public EmptyCaseBlockInspection(RubberduckParserState state)
2425
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2526
{
2627
return Listener.Contexts
27-
.Where(result => !IsIgnoringInspectionResultFor(result.ModuleName, result.Context.Start.Line))
28+
.Where(result => !result.IsIgnoringInspectionResultFor(State.DeclarationFinder, AnnotationName))
2829
.Select(result => new QualifiedContextInspectionResult(this,
2930
InspectionResults.EmptyCaseBlockInspection,
3031
result));

0 commit comments

Comments
 (0)