5
5
using Rubberduck . Inspections . CodePathAnalysis ;
6
6
using Rubberduck . Parsing . Symbols ;
7
7
using Rubberduck . Inspections . CodePathAnalysis . Nodes ;
8
+ using Rubberduck . Inspections . CodePathAnalysis . Extensions ;
8
9
using System . Linq ;
9
10
using Rubberduck . Inspections . Results ;
10
11
@@ -28,23 +29,23 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
28
29
{
29
30
var tree = _walker . GenerateTree ( variable . ParentScopeDeclaration . Context , variable ) ;
30
31
31
- nodes . AddRange ( GetReferences ( tree , variable ) ) ;
32
+ nodes . AddRange ( GetIdentifierReferences ( tree , variable ) ) ;
32
33
}
33
34
34
35
return nodes
35
36
. Select ( issue => new IdentifierReferenceInspectionResult ( this , Description , State , issue ) )
36
37
. ToList ( ) ;
37
38
}
38
39
39
- private List < IdentifierReference > GetReferences ( INode node , Declaration declaration )
40
+ private List < IdentifierReference > GetIdentifierReferences ( INode node , Declaration declaration )
40
41
{
41
42
var nodes = new List < IdentifierReference > ( ) ;
42
43
43
- var blockNodes = GetBlocks ( node ) ;
44
+ var blockNodes = node . GetNodes ( new [ ] { typeof ( BlockNode ) } ) ;
44
45
foreach ( var block in blockNodes )
45
46
{
46
47
INode lastNode = default ;
47
- foreach ( var flattenedNode in GetFlattenedNodes ( block ) )
48
+ foreach ( var flattenedNode in block . GetFlattenedNodes ( new [ ] { typeof ( GenericNode ) , typeof ( BlockNode ) } ) )
48
49
{
49
50
if ( flattenedNode is AssignmentNode &&
50
51
lastNode is AssignmentNode )
@@ -56,59 +57,13 @@ private List<IdentifierReference> GetReferences(INode node, Declaration declarat
56
57
}
57
58
58
59
if ( lastNode is AssignmentNode &&
59
- GetFirstNonGenericNode ( block . Children [ 0 ] ) is DeclarationNode )
60
+ block . Children [ 0 ] . GetFirstNode ( new [ ] { typeof ( GenericNode ) } ) is DeclarationNode )
60
61
{
61
62
nodes . Add ( lastNode . Reference ) ;
62
63
}
63
64
}
64
65
65
66
return nodes ;
66
67
}
67
-
68
- private IEnumerable < INode > GetFlattenedNodes ( INode node )
69
- {
70
- foreach ( var child in node . Children )
71
- {
72
- switch ( child )
73
- {
74
- case GenericNode _:
75
- case BlockNode _:
76
- foreach ( var nextChild in GetFlattenedNodes ( child ) )
77
- {
78
- yield return nextChild ;
79
- }
80
- break ;
81
- default :
82
- yield return child ;
83
- break ;
84
- }
85
- }
86
- }
87
-
88
- private IEnumerable < INode > GetBlocks ( INode node )
89
- {
90
- if ( node is BlockNode )
91
- {
92
- yield return node ;
93
- }
94
-
95
- foreach ( var child in node . Children )
96
- {
97
- foreach ( var block in GetBlocks ( child ) )
98
- {
99
- yield return block ;
100
- }
101
- }
102
- }
103
-
104
- private INode GetFirstNonGenericNode ( INode parent )
105
- {
106
- if ( ! ( parent is GenericNode ) )
107
- {
108
- return parent ;
109
- }
110
-
111
- return GetFirstNonGenericNode ( parent . Children [ 0 ] ) ;
112
- }
113
68
}
114
69
}
0 commit comments