Skip to content

Commit afbc1c2

Browse files
committed
Resolving comments
1 parent c3f749f commit afbc1c2

File tree

3 files changed

+70
-71
lines changed

3 files changed

+70
-71
lines changed

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/UCIParseTreeValueVisitor.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,14 @@ private bool TryGetLExprValue(VBAParser.LExprContext lExprContext, out string ex
257257
&& idRef.Declaration.DeclarationType.HasFlag(DeclarationType.EnumerationMember)
258258
&& idRef.Declaration.Context is VBAParser.EnumerationStmt_ConstantContext)
259259
{
260-
var dec = idRef.Declaration;
261-
var theCtxt = dec.Context;
262-
expressionValue = GetConstantDeclarationValueToken(dec);
263-
declaredTypeName = dec.AsTypeIsBaseType ? dec.AsTypeName : dec.AsTypeDeclaration.AsTypeName;
260+
var declaration = idRef.Declaration;
261+
var theCtxt = declaration.Context;
262+
expressionValue = GetConstantDeclarationValueToken(declaration);
263+
declaredTypeName = declaration.AsTypeIsBaseType ? declaration.AsTypeName : declaration.AsTypeDeclaration.AsTypeName;
264264
return true;
265265
}
266-
return false;
267266
}
268-
269-
if (isSimpleName)
267+
else if (isSimpleName)
270268
{
271269
if (TryGetIdentifierReferenceForContext(smplName, out IdentifierReference rangeClauseIdentifierReference))
272270
{
@@ -295,14 +293,15 @@ private bool TryGetIdentifierReferenceForContext(ParserRuleContext context, out
295293
return false;
296294
}
297295

298-
private string GetConstantDeclarationValueToken(Declaration valueDeclaration)
296+
private string GetConstantDeclarationValueToken(Declaration constantDeclaration)
299297
{
298+
var declarationContextChildren = constantDeclaration.Context.children.ToList();
299+
var equalsSymbolIndex = declarationContextChildren.FindIndex(ch => ch.Equals(constantDeclaration.Context.GetToken(VBAParser.EQ, 0)));
300+
300301
var contextsOfInterest = new List<ParserRuleContext>();
301-
var contexts = valueDeclaration.Context.children.ToList();
302-
var eqIndex = contexts.FindIndex(ch => ch.GetText().Equals(LogicSymbols.EQ));
303-
for (int idx = eqIndex + 1; idx < contexts.Count(); idx++)
302+
for (int idx = equalsSymbolIndex + 1; idx < declarationContextChildren.Count(); idx++)
304303
{
305-
var childCtxt = contexts[idx];
304+
var childCtxt = declarationContextChildren[idx];
306305
if (!(childCtxt is VBAParser.WhiteSpaceContext))
307306
{
308307
contextsOfInterest.Add((ParserRuleContext)childCtxt);

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/UnreachableCaseInspectionRange.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public class UnreachableCaseInspectionRange : UnreachableCaseInspectionContext,
2828
public UnreachableCaseInspectionRange(VBAParser.RangeClauseContext context, IUCIValueResults inspValues, IUnreachableCaseInspectionFactoryFactory factoryFactory)
2929
: base(context, inspValues, factoryFactory)
3030
{
31-
_isValueRange = Context.HasChildToken(Tokens.To);
32-
_isLTorGT = Context.HasChildToken(Tokens.Is);
31+
_isValueRange = !(context.TO() is null);
32+
_isLTorGT = !(context.IS() is null);
3333
_isRelationalOp = Context.TryGetChildContext<VBAParser.RelationalOpContext>(out _);
3434
_isSingleValue = !(_isValueRange || _isLTorGT || _isRelationalOp);
3535
_evalTypeName = string.Empty;
@@ -40,8 +40,8 @@ public UnreachableCaseInspectionRange(VBAParser.RangeClauseContext context, IUCI
4040
public UnreachableCaseInspectionRange(VBAParser.RangeClauseContext context, string evalTypeName, IUCIValueResults inspValues, IUnreachableCaseInspectionFactoryFactory factoryFactory)
4141
: base(context, inspValues, factoryFactory)
4242
{
43-
_isValueRange = Context.HasChildToken(Tokens.To);
44-
_isLTorGT = Context.HasChildToken(Tokens.Is);
43+
_isValueRange = !(context.TO() is null);
44+
_isLTorGT = !(context.IS() is null);
4545
_isRelationalOp = Context.TryGetChildContext<VBAParser.RelationalOpContext>(out _);
4646
_isSingleValue = !(_isValueRange || _isLTorGT || _isRelationalOp);
4747
IsUnreachable = false;

Rubberduck.Parsing/ParserRuleContextExtensions.cs

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -164,66 +164,66 @@ 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-
}
167+
//public static IEnumerable<T> GetChildren<T>(this RuleContext context)
168+
//{
169+
// if (context == null)
170+
// {
171+
// yield break;
172+
// }
173173

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-
}
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+
//}
183183

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-
}
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+
//}
196196

197-
public static TContext FindChild<TContext>(this ParserRuleContext context) where TContext : ParserRuleContext
198-
{
199-
if (context == null)
200-
{
201-
return default;
202-
}
197+
//public static TContext FindChild<TContext>(this ParserRuleContext context) where TContext : ParserRuleContext
198+
//{
199+
// if (context == null)
200+
// {
201+
// return default;
202+
// }
203203

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-
}
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+
//}
214214

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-
}
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+
//}
227227

228228
public static T GetDescendent<T>(this IParseTree context)
229229
{

0 commit comments

Comments
 (0)