1
+ using System . Collections . Generic ;
1
2
using System . Linq ;
2
3
using Rubberduck . CodeAnalysis . Inspections . Abstract ;
3
4
using Rubberduck . CodeAnalysis . Inspections . Extensions ;
@@ -14,8 +15,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
14
15
/// </summary>
15
16
/// <why>
16
17
/// Unused procedures are dead code that should probably be removed. Note, a procedure may be effectively "not used" in code, but attached to some
17
- /// Shape object in the host document: in such cases the inspection result should be ignored. An event handler procedure that isn't being
18
- /// resolved as such, may also wrongly trigger this inspection.
18
+ /// Shape object in the host document: in such cases the inspection result should be ignored.
19
19
/// </why>
20
20
/// <remarks>
21
21
/// Not all unused procedures can/should be removed: ignore any inspection results for
@@ -24,34 +24,81 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
24
24
/// the presence or absence of user code references.
25
25
/// </remarks>
26
26
/// <example hasResult="true">
27
- /// <module name="MyModule" type="Standard Module">
27
+ /// <module name="Module1" type="Standard Module">
28
+ /// <![CDATA[
29
+ /// Option Explicit
30
+ ///
31
+ /// Private Sub DoSomething()
32
+ /// End Sub
33
+ /// ]]>
34
+ /// </module>
35
+ /// </example>
36
+ /// <example hasResult="false">
37
+ /// <module name="Module1" type="Standard Module">
38
+ /// <![CDATA[
39
+ /// Option Explicit
40
+ ///
41
+ /// '@Ignore ProcedureNotUsed
42
+ /// Private Sub DoSomething()
43
+ /// End Sub
44
+ /// ]]>
45
+ /// </module>
46
+ /// </example>
47
+ /// <example hasResult="false">
48
+ /// <module name="Module1" type="Standard Module">
49
+ /// <![CDATA[
50
+ /// Option Explicit
51
+ ///
52
+ /// Public Sub DoSomething()
53
+ /// End Sub
54
+ /// ]]>
55
+ /// </module>
56
+ /// </example>
57
+ /// <example hasResult="true">
58
+ /// <module name="Class1" type="Class Module">
28
59
/// <![CDATA[
29
60
/// Option Explicit
30
61
///
31
- /// 'No inspection result
32
62
/// Public Sub DoSomething()
33
- /// ' macro is attached to a worksheet Shape.
34
63
/// End Sub
35
64
///
36
- /// 'Flagged by inspection
37
- /// Private Sub DoSomethingElse()
38
- /// ' macro is attached to a worksheet Shape.
65
+ /// Public Sub DoSomethingElse()
66
+ /// End Sub
67
+ /// ]]>
68
+ /// </module>
69
+ /// <module name="Module1" type="Standard Module">
70
+ /// <![CDATA[
71
+ /// Option Explicit
72
+ ///
73
+ /// Public Sub ReferenceOneClass1Procedure()
74
+ /// Dim target As Class1
75
+ /// Set target = new Class1
76
+ /// target.DoSomething
39
77
/// End Sub
40
78
/// ]]>
41
79
/// </module>
42
80
/// </example>
43
81
/// <example hasResult="false">
44
- /// <module name="MyModule " type="Standard Module">
82
+ /// <module name="Class1 " type="Class Module">
45
83
/// <![CDATA[
46
84
/// Option Explicit
47
85
///
48
86
/// Public Sub DoSomething()
49
- /// ' macro is attached to a worksheet Shape.
50
87
/// End Sub
51
- ///
52
- /// '@Ignore ProcedureNotUsed
53
- /// Private Sub DoSomethingElse()
54
- /// ' macro is attached to a worksheet Shape.
88
+ ///
89
+ /// Public Sub DoSomethingElse()
90
+ /// End Sub
91
+ /// ]]>
92
+ /// </module>
93
+ /// <module name="Module1" type="Standard Module">
94
+ /// <![CDATA[
95
+ /// Option Explicit
96
+ ///
97
+ /// Public Sub ReferenceAllClass1Procedures()
98
+ /// Dim target As Class1
99
+ /// Set target = new Class1
100
+ /// target.DoSomething
101
+ /// target.DoSomethingElse
55
102
/// End Sub
56
103
/// ]]>
57
104
/// </module>
@@ -90,7 +137,7 @@ public ProcedureNotUsedInspection(IDeclarationFinderProvider declarationFinderPr
90
137
protected override bool IsResultDeclaration ( Declaration declaration , DeclarationFinder finder )
91
138
{
92
139
return ! declaration . References
93
- . Any ( reference => ! reference . ParentScoping . Equals ( declaration ) ) // recursive calls don't count
140
+ . Any ( reference => ! reference . ParentScoping . Equals ( declaration ) ) // ignore recursive/self-referential calls
94
141
&& ! finder . FindEventHandlers ( ) . Contains ( declaration )
95
142
&& ! IsPublicModuleMember ( declaration )
96
143
&& ! IsClassLifeCycleHandler ( declaration )
0 commit comments