Skip to content

Commit 2b4a094

Browse files
author
glowingrunes
authored
Merge branch 'next' into 5237-CodeInspectionScrollbarFix
2 parents f1d3be4 + 347c603 commit 2b4a094

File tree

151 files changed

+3946
-4072
lines changed

Some content is hidden

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

151 files changed

+3946
-4072
lines changed

Rubberduck.CodeAnalysis/Inspections/Abstract/QuickFixBase.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq;
45
using NLog;
56
using Rubberduck.Parsing.Inspections.Abstract;
@@ -24,17 +25,28 @@ public void RegisterInspections(params Type[] inspections)
2425
{
2526
if (!inspections.All(s => s.GetInterfaces().Any(a => a == typeof(IInspection))))
2627
{
27-
#if DEBUG
28-
throw new ArgumentException($"Parameters must implement {nameof(IInspection)}", nameof(inspections));
29-
#else
28+
var dieNow = false;
29+
MustThrowException(ref dieNow);
30+
if (dieNow)
31+
{
32+
throw new ArgumentException($"Parameters must implement {nameof(IInspection)}",
33+
nameof(inspections));
34+
}
35+
3036
inspections.Where(s => s.GetInterfaces().All(i => i != typeof(IInspection))).ToList()
3137
.ForEach(i => Logger.Error($"Type {i.Name} does not implement {nameof(IInspection)}"));
32-
#endif
3338
}
3439

3540
_supportedInspections = inspections.ToHashSet();
3641
}
3742

43+
// ReSharper disable once RedundantAssignment : conditional must be void but we can use ref
44+
[Conditional("DEBUG")]
45+
private static void MustThrowException(ref bool dieNow)
46+
{
47+
dieNow = true;
48+
}
49+
3850
public void RemoveInspections(params Type[] inspections)
3951
{
4052
_supportedInspections = _supportedInspections.Except(inspections).ToHashSet();

Rubberduck.CodeAnalysis/Inspections/Concrete/ArgumentWithIncompatibleObjectTypeInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
2121
/// <why>
2222
/// The VBA compiler does not check whether different object types are compatible. Instead there is a runtime error whenever the types are incompatible.
2323
/// </why>
24-
/// <example hasResult="true">
24+
/// <example hasresult="true">
2525
/// <![CDATA[
2626
/// IInterface:
2727
///
@@ -49,7 +49,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
4949
/// End Sub
5050
/// ]]>
5151
/// </example>
52-
/// <example hasResult="false">
52+
/// <example hasresult="false">
5353
/// <![CDATA[
5454
/// IInterface:
5555
///

Rubberduck.CodeAnalysis/Inspections/Concrete/DefaultMemberRequiredInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
1515
/// <why>
1616
/// The VBA compiler does not check whether the necessary default member is present. Instead there is a runtime error whenever the runtime type fails to have the default member.
1717
/// </why>
18-
/// <example hasResult="true">
18+
/// <example hasresult="true">
1919
/// <![CDATA[
2020
/// Class1:
2121
///
@@ -34,7 +34,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
3434
/// End Sub
3535
/// ]]>
3636
/// </example>
37-
/// <example hasResult="false">
37+
/// <example hasresult="false">
3838
/// <![CDATA[
3939
/// Class1:
4040
///

Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyMethodInspection.cs

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using Rubberduck.Parsing.Symbols;
9-
using Rubberduck.Inspections.Inspections.Extensions;
109
using Rubberduck.Common;
10+
using Rubberduck.Inspections.Inspections.Extensions;
11+
using Rubberduck.Parsing.VBA.DeclarationCaching;
12+
using Rubberduck.Parsing.VBA.Extensions;
13+
using Rubberduck.VBEditor;
1114

1215
namespace Rubberduck.Inspections.Concrete
1316
{
@@ -39,19 +42,48 @@ public EmptyMethodInspection(RubberduckParserState state)
3942

4043
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
4144
{
42-
var allInterfaces = new HashSet<ClassModuleDeclaration>(State.DeclarationFinder.FindAllUserInterfaces());
43-
44-
return State.DeclarationFinder.UserDeclarations(DeclarationType.Member)
45-
.Where(member => !allInterfaces.Any(userInterface => userInterface.QualifiedModuleName == member.QualifiedModuleName)
46-
&& !((ModuleBodyElementDeclaration)member).Block.ContainsExecutableStatements())
47-
48-
.Select(result => new DeclarationInspectionResult(this,
49-
string.Format(InspectionResults.EmptyMethodInspection,
50-
Resources.RubberduckUI.ResourceManager
51-
.GetString("DeclarationType_" + result.DeclarationType)
52-
.Capitalize(),
53-
result.IdentifierName),
54-
result));
45+
var finder = State.DeclarationFinder;
46+
47+
var userInterfaces = UserInterfaces(finder);
48+
var emptyMethods = EmptyNonInterfaceMethods(finder, userInterfaces);
49+
50+
return emptyMethods.Select(Result);
51+
}
52+
53+
private static ICollection<QualifiedModuleName> UserInterfaces(DeclarationFinder finder)
54+
{
55+
return finder
56+
.FindAllUserInterfaces()
57+
.Select(decl => decl.QualifiedModuleName)
58+
.ToHashSet();
59+
}
60+
61+
private static IEnumerable<Declaration> EmptyNonInterfaceMethods(DeclarationFinder finder, ICollection<QualifiedModuleName> userInterfaces)
62+
{
63+
return finder
64+
.UserDeclarations(DeclarationType.Member)
65+
.Where(member => !userInterfaces.Contains(member.QualifiedModuleName)
66+
&& member is ModuleBodyElementDeclaration moduleBodyElement
67+
&& !moduleBodyElement.Block.ContainsExecutableStatements());
68+
}
69+
70+
private IInspectionResult Result(Declaration member)
71+
{
72+
return new DeclarationInspectionResult(
73+
this,
74+
ResultDescription(member),
75+
member);
76+
}
77+
78+
private static string ResultDescription(Declaration member)
79+
{
80+
var identifierName = member.IdentifierName;
81+
var declarationType = member.DeclarationType.ToLocalizedString();
82+
83+
return string.Format(
84+
InspectionResults.EmptyMethodInspection,
85+
declarationType,
86+
identifierName);
5587
}
5688
}
5789
}

Rubberduck.CodeAnalysis/Inspections/Concrete/EncapsulatePublicFieldInspection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
4040
{
4141
// we're creating a public field for every control on a form, needs to be ignored.
4242
var fields = State.DeclarationFinder.UserDeclarations(DeclarationType.Variable)
43-
.Where(item => item.Accessibility == Accessibility.Public
44-
&& (item.DeclarationType != DeclarationType.Control))
43+
.Where(item => item.DeclarationType != DeclarationType.Control
44+
&& (item.Accessibility == Accessibility.Public ||
45+
item.Accessibility == Accessibility.Global))
4546
.ToList();
4647

4748
return fields

Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitDefaultMemberAccessInspection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@ namespace Rubberduck.Inspections.Concrete
1414
/// Default member accesses hide away the actually called member. This is especially misleading if there is no indication in the expression that such a call is made
1515
/// and can cause errors in which a member was forgotten to be called to go unnoticed.
1616
/// </why>
17-
/// <example hasResult="true">
17+
/// <example hasresult="true">
1818
/// <![CDATA[
1919
/// Public Sub DoSomething(ByVal arg As ADODB.Field)
2020
/// Dim bar As Variant
2121
/// bar = arg
2222
/// End Sub
2323
/// ]]>
2424
/// </example>
25-
/// <example hasResult="true">
25+
/// <example hasresult="true">
2626
/// <![CDATA[
2727
/// Public Sub DoSomething(ByVal arg As ADODB.Connection)
2828
/// Dim bar As String
2929
/// arg = bar
3030
/// End Sub
3131
/// ]]>
3232
/// </example>
33-
/// <example hasResult="false">
33+
/// <example hasresult="false">
3434
/// <![CDATA[
3535
/// Public Sub DoSomething(ByVal arg As ADODB.Field)
3636
/// Dim bar As Variant
3737
/// bar = arg.Value
3838
/// End Sub
3939
/// ]]>
4040
/// </example>
41-
/// <example hasResult="false">
41+
/// <example hasresult="false">
4242
/// <![CDATA[
4343
/// Public Sub DoSomething(ByVal arg As ADODB.Connection)
4444
/// Dim bar As String

Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitRecursiveDefaultMemberAccessInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Rubberduck.Inspections.Concrete
1414
/// Default member accesses hide away the actually called member. This is especially misleading if there is no indication in the expression that such a call is made
1515
/// and the final default member is not on the interface of the object itself. In particular, this can cause errors in which a member was forgotten to be called to go unnoticed.
1616
/// </why>
17-
/// <example hasResult="true">
17+
/// <example hasresult="true">
1818
/// <module name="Class1" type="Class Module">
1919
/// <![CDATA[
2020
/// Public Function Foo() As Class2
@@ -40,7 +40,7 @@ namespace Rubberduck.Inspections.Concrete
4040
/// ]]>
4141
/// </module>
4242
/// </example>
43-
/// <example hasResult="false">
43+
/// <example hasresult="false">
4444
/// <module name="Class1" type="Class Module">
4545
/// <![CDATA[
4646
/// Public Function Foo() As Class2

Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitUnboundDefaultMemberAccessInspection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ namespace Rubberduck.Inspections.Concrete
1717
/// and if the default member cannot be determined from the declared type of the object. As a consequence, errors in which a member was forgotten to be called can go unnoticed
1818
/// and should there not be a suitable default member at runtime, an error 438 'Object doesn't support this property or method' will be raised.
1919
/// </why>
20-
/// <example hasResult="true">
20+
/// <example hasresult="true">
2121
/// <![CDATA[
2222
/// Public Sub DoSomething(ByVal arg As Object)
2323
/// Dim bar As Variant
2424
/// bar = arg
2525
/// End Sub
2626
/// ]]>
27-
/// <example hasResult="true">
27+
/// <example hasresult="true">
2828
/// <![CDATA[
2929
/// Public Sub DoSomething(ByVal arg As Object)
3030
/// Dim bar As Variant
3131
/// arg = bar
3232
/// End Sub
3333
/// ]]>
3434
/// </example>
35-
/// <example hasResult="false">
35+
/// <example hasresult="false">
3636
/// <![CDATA[
3737
/// Public Sub DoSomething(ByVal arg As Object)
3838
/// Dim bar As Variant
3939
/// bar = arg.SomeValueReturningMember
4040
/// End Sub
4141
/// ]]>
42-
/// <example hasResult="false">
42+
/// <example hasresult="false">
4343
/// <![CDATA[
4444
/// Public Sub DoSomething(ByVal arg As Object)
4545
/// Dim bar As Variant

Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedDefaultMemberAccessInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ namespace Rubberduck.Inspections.Concrete
1414
/// <why>
1515
/// An indexed default member access hides away the actually called member.
1616
/// </why>
17-
/// <example hasResult="true">
17+
/// <example hasresult="true">
1818
/// <![CDATA[
1919
/// Public Sub DoSomething(ByVal coll As Collection)
2020
/// Dim bar As Variant
2121
/// bar = coll(23)
2222
/// End Sub
2323
/// ]]>
2424
/// </example>
25-
/// <example hasResult="false">
25+
/// <example hasresult="false">
2626
/// <![CDATA[
2727
/// Public Sub DoSomething(ByVal coll As Collection)
2828
/// Dim bar As Variant

Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedRecursiveDefaultMemberAccessInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ namespace Rubberduck.Inspections.Concrete
1414
/// <why>
1515
/// An indexed default member access hides away the actually called member. This is especially problematic if the corresponding parameterized default member is not on the interface of the object itself.
1616
/// </why>
17-
/// <example hasResult="true">
17+
/// <example hasresult="true">
1818
/// <![CDATA[
1919
/// Public Sub DoSomething(ByVal rst As ADODB.Recordset)
2020
/// Dim bar As Variant
2121
/// bar = rst("MyField")
2222
/// End Sub
2323
/// ]]>
2424
/// </example>
25-
/// <example hasResult="false">
25+
/// <example hasresult="false">
2626
/// <![CDATA[
2727
/// Public Sub DoSomething(ByVal rst As ADODB.Recordset)
2828
/// Dim bar As Variant

Rubberduck.CodeAnalysis/Inspections/Concrete/IndexedUnboundDefaultMemberAccessInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ namespace Rubberduck.Inspections.Concrete
1717
/// An indexed default member access hides away the actually called member. This is especially problematic if the default member cannot be determined from the declared type of the object.
1818
/// Should there not be a suitable default member at runtime, an error 438 'Object doesn't support this property or method' will be raised.
1919
/// </why>
20-
/// <example hasResult="true">
20+
/// <example hasresult="true">
2121
/// <![CDATA[
2222
/// Public Sub DoSomething(ByVal rst As Object)
2323
/// Dim bar As Variant
2424
/// bar = rst("MyField")
2525
/// End Sub
2626
/// ]]>
2727
/// </example>
28-
/// <example hasResult="false">
28+
/// <example hasresult="false">
2929
/// <![CDATA[
3030
/// Public Sub DoSomething(ByVal rst As Object)
3131
/// Dim bar As Variant

Rubberduck.CodeAnalysis/Inspections/Concrete/ObjectWhereProcedureIsRequiredInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Rubberduck.Inspections.Concrete
2020
/// Providing an object where a procedure is required leads to an implicit call to the object's default member.
2121
/// This behavior is not obvious, and most likely unintended.
2222
/// </why>
23-
/// <example hasResult="true">
23+
/// <example hasresult="true">
2424
/// <module name="Class1" type="Class Module">
2525
/// <![CDATA[
2626
/// Public Function Foo() As Long
@@ -37,7 +37,7 @@ namespace Rubberduck.Inspections.Concrete
3737
/// ]]>
3838
/// </module>
3939
/// </example>
40-
/// <example hasResult="false">
40+
/// <example hasresult="false">
4141
/// <module name="Class1" type="Class Module">
4242
/// <![CDATA[
4343
/// Public Function Foo() As Long

Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteWhileWendStatementInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
2020
/// 'While...Wend' loops were made obsolete when 'Do While...Loop' statements were introduced.
2121
/// 'While...Wend' loops cannot be exited early without a GoTo jump; 'Do...Loop' statements can be conditionally exited with 'Exit Do'.
2222
/// </why>
23-
/// <example hasResults="true">
23+
/// <example hasresult="true">
2424
/// <![CDATA[
2525
/// Public Sub DoSomething()
2626
/// While True
@@ -29,7 +29,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
2929
/// End Sub
3030
/// ]]>
3131
/// </example>
32-
/// <example hasResults="false">
32+
/// <example hasresult="false">
3333
/// <![CDATA[
3434
/// Public Sub DoSomething()
3535
/// Do While True

Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureRequiredInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
1515
/// <why>
1616
/// The VBA compiler does not check whether the necessary default member is present. Instead there is a runtime error whenever the runtime type fails to have the default member.
1717
/// </why>
18-
/// <example hasResult="true">
18+
/// <example hasresult="true">
1919
/// <![CDATA[
2020
/// Class1:
2121
///
@@ -33,7 +33,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
3333
/// End Sub
3434
/// ]]>
3535
/// </example>
36-
/// <example hasResult="false">
36+
/// <example hasresult="false">
3737
/// <![CDATA[
3838
/// Class1:
3939
///

Rubberduck.CodeAnalysis/Inspections/Concrete/SetAssignmentWithIncompatibleObjectTypeInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
2222
/// <why>
2323
/// The VBA compiler does not check whether different object types are compatible. Instead there is a runtime error whenever the types are incompatible.
2424
/// </why>
25-
/// <example hasResult="true">
25+
/// <example hasresult="true">
2626
/// <![CDATA[
2727
/// IInterface:
2828
///
@@ -49,7 +49,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
4949
/// End Sub
5050
/// ]]>
5151
/// </example>
52-
/// <example hasResult="false">
52+
/// <example hasresult="false">
5353
/// <![CDATA[
5454
/// IInterface:
5555
///

0 commit comments

Comments
 (0)