Skip to content

Commit 5c081d7

Browse files
committed
Removed unused/redundant PRCExtension methods
1 parent afbc1c2 commit 5c081d7

File tree

2 files changed

+10
-110
lines changed

2 files changed

+10
-110
lines changed

Rubberduck.Parsing/ParserRuleContextExtensions.cs

Lines changed: 6 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -164,109 +164,13 @@ public static IEnumerable<TContext> GetDescendents<TContext>(this ParserRuleCont
164164
return listener.Matches;
165165
}
166166

167-
//public static IEnumerable<T> GetChildren<T>(this RuleContext context)
168-
//{
169-
// if (context == null)
170-
// {
171-
// yield break;
172-
// }
173-
174-
// for (var index = 0; index < context.ChildCount; index++)
175-
// {
176-
// var child = context.GetChild(index);
177-
// if (child is T)
178-
// {
179-
// yield return (T)child;
180-
// }
181-
// }
182-
//}
183-
184-
//public static bool HasParent(this RuleContext context, RuleContext parent)
185-
//{
186-
// if (context == null)
187-
// {
188-
// return false;
189-
// }
190-
// if (context == parent)
191-
// {
192-
// return true;
193-
// }
194-
// return HasParent(context.Parent, parent);
195-
//}
196-
197-
//public static TContext FindChild<TContext>(this ParserRuleContext context) where TContext : ParserRuleContext
198-
//{
199-
// if (context == null)
200-
// {
201-
// return default;
202-
// }
203-
204-
// for (var index = 0; index < context.ChildCount; index++)
205-
// {
206-
// var child = context.GetChild(index);
207-
// if (context.GetChild(index) is TContext)
208-
// {
209-
// return (TContext)child;
210-
// }
211-
// }
212-
// return default;
213-
//}
214-
215-
//public static bool HasChildToken(this IParseTree context, string token)
216-
//{
217-
// for (var index = 0; index < context.ChildCount; index++)
218-
// {
219-
// var child = context.GetChild(index);
220-
// if (context.GetChild(index).GetText().Equals(token))
221-
// {
222-
// return true;
223-
// }
224-
// }
225-
// return false;
226-
//}
227-
228-
public static T GetDescendent<T>(this IParseTree context)
229-
{
230-
if (context == null)
231-
{
232-
return default;
233-
}
234-
235-
for (var index = 0; index < context.ChildCount; index++)
236-
{
237-
var child = context.GetChild(index);
238-
if (context.GetChild(index) is T)
239-
{
240-
return (T)child;
241-
}
242-
243-
var descendent = child.GetDescendent<T>();
244-
if (descendent != null)
245-
{
246-
return descendent;
247-
}
248-
}
249-
250-
return default;
251-
}
252-
253-
public static IEnumerable<IParseTree> GetDescendents(this IParseTree context)
167+
/// <summary>
168+
/// Try to get the first child of the generic context type.
169+
/// </summary>
170+
public static bool TryGetChildContext<TContext>(this ParserRuleContext ctxt, out TContext opCtxt) where TContext : ParserRuleContext
254171
{
255-
if (context == null)
256-
{
257-
yield break;
258-
}
259-
260-
for (var index = 0; index < context.ChildCount; index++)
261-
{
262-
var child = context.GetChild(index);
263-
yield return child;
264-
265-
foreach (var node in child.GetDescendents())
266-
{
267-
yield return node;
268-
}
269-
}
172+
opCtxt = ctxt.GetChild<TContext>();
173+
return opCtxt != null;
270174
}
271175

272176
private class ChildNodeListener<TContext> : VBAParserBaseListener where TContext : ParserRuleContext
@@ -283,11 +187,5 @@ public override void EnterEveryRule(ParserRuleContext context)
283187
}
284188
}
285189
}
286-
287-
public static bool TryGetChildContext<TContext>(this ParserRuleContext ctxt, out TContext opCtxt) where TContext : ParserRuleContext
288-
{
289-
opCtxt = ctxt.GetChild<TContext>();
290-
return opCtxt != null;
291-
}
292190
}
293191
}

RubberduckTests/Inspections/UnreachableCaseInspectionTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using Antlr4.Runtime;
2+
using NUnit.Framework;
23
using Rubberduck.Inspections.Concrete.UnreachableCaseInspection;
34
using Rubberduck.Parsing;
45
using Rubberduck.Parsing.Grammar;
@@ -2187,7 +2188,8 @@ private IUCIValueResults GetParseTreeValueResults(string inputCode, out VBAParse
21872188
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var _);
21882189
using (var state = MockParser.CreateAndParse(vbe.Object))
21892190
{
2190-
selectStmt = state.ParseTrees.First().Value.GetDescendent<VBAParser.SelectCaseStmtContext>();
2191+
var firstParserRuleContext = (ParserRuleContext)state.ParseTrees.Where(pt => pt.Value is ParserRuleContext).First().Value;
2192+
selectStmt = firstParserRuleContext.GetDescendent<VBAParser.SelectCaseStmtContext>();
21912193
var visitor = ValueVisitorFactory.Create(state, ValueFactory);
21922194
valueResults = selectStmt.Accept(visitor);
21932195
}

0 commit comments

Comments
 (0)