Skip to content

Commit 51661be

Browse files
committed
New names for everyone!
1 parent 5c081d7 commit 51661be

24 files changed

+369
-333
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Antlr4.Runtime;
2+
using Rubberduck.Parsing;
3+
4+
namespace Rubberduck.Inspections.Concrete.UnreachableCaseInspection
5+
{
6+
public abstract class ContextWrapperBase
7+
{
8+
protected readonly ParserRuleContext _context;
9+
protected IParseTreeVisitorResults _inspValues;
10+
private readonly IRangeClauseFilterFactory _rangeFilterFactory;
11+
private readonly IParseTreeValueFactory _valueFactory;
12+
13+
public ContextWrapperBase(ParserRuleContext context, IParseTreeVisitorResults inspValues, IUnreachableCaseInspectionFactoryProvider factoryFactory)
14+
{
15+
_context = context;
16+
_rangeFilterFactory = factoryFactory.CreateIUCIRangeClauseFilterFactory();
17+
_valueFactory = factoryFactory.CreateIUCIValueFactory();
18+
_inspValues = inspValues;
19+
}
20+
21+
protected IParseTreeValueFactory ValueFactory => _valueFactory;
22+
23+
protected IRangeClauseFilterFactory FilterFactory => _rangeFilterFactory;
24+
25+
public ParserRuleContext Context => _context;
26+
27+
protected IParseTreeVisitorResults ParseTreeValueResults => _inspValues;
28+
}
29+
}

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/UCIValueExpressionEvaluator.cs renamed to Rubberduck.Inspections/Concrete/UnreachableCaseInspection/ParseTreeExpressionEvaluator.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
namespace Rubberduck.Inspections.Concrete.UnreachableCaseInspection
77
{
8-
public interface IUCIValueExpressionEvaluator
8+
public interface IParseTreeExpressionEvaluator
99
{
10-
IUCIValue Evaluate(IUCIValue LHS, IUCIValue RHS, string opSymbol);
11-
IUCIValue Evaluate(IUCIValue LHS, string opSymbol);
10+
IParseTreeValue Evaluate(IParseTreeValue LHS, IParseTreeValue RHS, string opSymbol);
11+
IParseTreeValue Evaluate(IParseTreeValue LHS, string opSymbol);
1212
}
1313

14-
public class UCIValueExpressionEvaluator : IUCIValueExpressionEvaluator
14+
public class ParseTreeExpressionEvaluator : IParseTreeExpressionEvaluator
1515
{
16-
private readonly IUCIValueFactory _valueFactory;
16+
private readonly IParseTreeValueFactory _valueFactory;
1717

1818
private static Dictionary<string, Func<double, double, double>> MathOpsBinary = new Dictionary<string, Func<double, double, double>>()
1919
{
@@ -59,12 +59,12 @@ public class UCIValueExpressionEvaluator : IUCIValueExpressionEvaluator
5959
Tokens.Boolean,
6060
};
6161

62-
public UCIValueExpressionEvaluator(IUCIValueFactory valueFactory)
62+
public ParseTreeExpressionEvaluator(IParseTreeValueFactory valueFactory)
6363
{
6464
_valueFactory = valueFactory;
6565
}
6666

67-
public IUCIValue Evaluate(IUCIValue LHS, IUCIValue RHS, string opSymbol)
67+
public IParseTreeValue Evaluate(IParseTreeValue LHS, IParseTreeValue RHS, string opSymbol)
6868
{
6969
var isMathOp = MathOpsBinary.ContainsKey(opSymbol);
7070
var isLogicOp = LogicOpsBinary.ContainsKey(opSymbol);
@@ -86,7 +86,7 @@ public IUCIValue Evaluate(IUCIValue LHS, IUCIValue RHS, string opSymbol)
8686
return _valueFactory.Create($"{LHS.ValueText} {opSymbol} {RHS.ValueText}", opResultTypeName);
8787
}
8888

89-
public IUCIValue Evaluate(IUCIValue value, string opSymbol)
89+
public IParseTreeValue Evaluate(IParseTreeValue value, string opSymbol)
9090
{
9191
var isMathOp = MathOpsUnary.ContainsKey(opSymbol);
9292
var isLogicOp = LogicOpsUnary.ContainsKey(opSymbol);
@@ -107,7 +107,7 @@ public IUCIValue Evaluate(IUCIValue value, string opSymbol)
107107
return _valueFactory.Create($"{opSymbol} {value.ValueText}", opResultTypeName);
108108
}
109109

110-
private static string DetermineMathResultType(IUCIValue LHS, IUCIValue RHS)
110+
private static string DetermineMathResultType(IParseTreeValue LHS, IParseTreeValue RHS)
111111
{
112112
var lhsTypeNameIndex = ResultTypeRanking.FindIndex(el => el.Equals(LHS.TypeName));
113113
var rhsTypeNameIndex = ResultTypeRanking.FindIndex(el => el.Equals(RHS.TypeName));

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/UCIValue.cs renamed to Rubberduck.Inspections/Concrete/UnreachableCaseInspection/ParseTreeValue.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55

66
namespace Rubberduck.Inspections.Concrete.UnreachableCaseInspection
77
{
8-
public interface IUCIValue
8+
public interface IParseTreeValue
99
{
1010
string ValueText { get; }
1111
string TypeName { get; }
1212
bool ParsesToConstantValue { get; set; }
1313
}
1414

15-
public class UCIValue : IUCIValue
15+
public class ParseTreeValue : IParseTreeValue
1616
{
1717
private string _valueText;
1818
private string _declaredType;
1919
private string _derivedType;
2020

21-
public UCIValue(string value, string declaredType = null)
21+
public ParseTreeValue(string value, string declaredType = null)
2222
{
2323
if (value is null)
2424
{
@@ -118,23 +118,23 @@ private void ConformValueTextToType(string conformTypeName)
118118

119119
if (conformTypeName.Equals(Tokens.Long) || conformTypeName.Equals(Tokens.Integer) || conformTypeName.Equals(Tokens.Byte))
120120
{
121-
if (UCIValueConverter.TryConvertValue(_valueText, out long newVal))
121+
if (ParseTreeValueConverter.TryConvertValue(_valueText, out long newVal))
122122
{
123123
_valueText = newVal.ToString();
124124
ParsesToConstantValue = true;
125125
}
126126
}
127127
else if (conformTypeName.Equals(Tokens.Double) || conformTypeName.Equals(Tokens.Single))
128128
{
129-
if (UCIValueConverter.TryConvertValue(_valueText, out double newVal))
129+
if (ParseTreeValueConverter.TryConvertValue(_valueText, out double newVal))
130130
{
131131
_valueText = newVal.ToString();
132132
ParsesToConstantValue = true;
133133
}
134134
}
135135
else if (conformTypeName.Equals(Tokens.Boolean))
136136
{
137-
if (UCIValueConverter.TryConvertValue(_valueText, out bool newVal))
137+
if (ParseTreeValueConverter.TryConvertValue(_valueText, out bool newVal))
138138
{
139139
_valueText = newVal.ToString();
140140
ParsesToConstantValue = true;
@@ -146,7 +146,7 @@ private void ConformValueTextToType(string conformTypeName)
146146
}
147147
else if (conformTypeName.Equals(Tokens.Currency))
148148
{
149-
if (UCIValueConverter.TryConvertValue(_valueText, out decimal newVal))
149+
if (ParseTreeValueConverter.TryConvertValue(_valueText, out decimal newVal))
150150
{
151151
_valueText = newVal.ToString();
152152
ParsesToConstantValue = true;

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/UCIValueConverter.cs renamed to Rubberduck.Inspections/Concrete/UnreachableCaseInspection/ParseTreeValueConverter.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33

44
namespace Rubberduck.Inspections.Concrete.UnreachableCaseInspection
55
{
6-
internal class UCIValueConverter
6+
public delegate bool TryConvertParseTreeValue<T>(IParseTreeValue value, out T result);
7+
8+
internal class ParseTreeValueConverter
79
{
8-
internal static long ConvertLong(IUCIValue value)
10+
internal static long ConvertLong(IParseTreeValue value)
911
{
1012
return ConvertLong(value.ValueText);
1113
}
1214

13-
internal static long ConvertLong(string value)
15+
//public static bool TryConvertValue(IParseTreeValue value, out long result)
16+
//{
17+
// return TryConvertValue(value.ValueText, out result);
18+
//}
19+
20+
private static long ConvertLong(string value)
1421
{
1522
if (TryConvertValue(value, out long result))
1623
{
@@ -19,12 +26,17 @@ internal static long ConvertLong(string value)
1926
throw new ArgumentException($"Unable to convert parameter (value = {value}) to {result.GetType()}");
2027
}
2128

22-
internal static double ConvertDouble(IUCIValue value)
29+
internal static double ConvertDouble(IParseTreeValue value)
2330
{
2431
return ConvertDouble(value.ValueText);
2532
}
2633

27-
internal static double ConvertDouble(string value)
34+
public static bool TryConvertValue(IParseTreeValue value, out double result)
35+
{
36+
return TryConvertValue(value.ValueText, out result);
37+
}
38+
39+
private static double ConvertDouble(string value)
2840
{
2941
if (TryConvertValue(value, out double result))
3042
{
@@ -33,12 +45,12 @@ internal static double ConvertDouble(string value)
3345
throw new ArgumentException($"Unable to convert parameter (value = {value}) to {result.GetType()}");
3446
}
3547

36-
internal static decimal ConvertDecimal(IUCIValue value)
48+
internal static decimal ConvertDecimal(IParseTreeValue value)
3749
{
3850
return ConvertDecimal(value.ValueText);
3951
}
4052

41-
internal static decimal ConvertDecimal(string value)
53+
private static decimal ConvertDecimal(string value)
4254
{
4355
if (TryConvertValue(value, out decimal result))
4456
{
@@ -47,12 +59,12 @@ internal static decimal ConvertDecimal(string value)
4759
throw new ArgumentException($"Unable to convert parameter (value = {value}) to {result.GetType()}");
4860
}
4961

50-
internal static bool ConvertBoolean(IUCIValue value)
62+
internal static bool ConvertBoolean(IParseTreeValue value)
5163
{
5264
return ConvertBoolean(value.ValueText);
5365
}
5466

55-
internal static bool ConvertBoolean(string value)
67+
private static bool ConvertBoolean(string value)
5668
{
5769
if (TryConvertValue(value, out bool result))
5870
{
@@ -61,7 +73,7 @@ internal static bool ConvertBoolean(string value)
6173
throw new ArgumentException($"Unable to convert parameter (value = {value}) to {result.GetType()}");
6274
}
6375

64-
internal static string ConvertString(IUCIValue value)
76+
internal static string ConvertString(IParseTreeValue value)
6577
{
6678
return value.ValueText;
6779
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+

2+
namespace Rubberduck.Inspections.Concrete.UnreachableCaseInspection
3+
{
4+
public interface IParseTreeValueFactory
5+
{
6+
IParseTreeValue Create(string valueToken, string declaredTypeName = null);
7+
}
8+
9+
public class ParseTreeValueFactory : IParseTreeValueFactory
10+
{
11+
public IParseTreeValue Create(string valueToken, string declaredTypeName = null)
12+
{
13+
return new ParseTreeValue(valueToken, declaredTypeName);
14+
}
15+
}
16+
}

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/UCIParseTreeValueVisitor.cs renamed to Rubberduck.Inspections/Concrete/UnreachableCaseInspection/ParseTreeValueVisitor.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010

1111
namespace Rubberduck.Inspections.Concrete.UnreachableCaseInspection
1212
{
13-
public interface IUCIParseTreeValueVisitor : IParseTreeVisitor<IUCIValueResults>
13+
public interface IParseTreeValueVisitor : IParseTreeVisitor<IParseTreeVisitorResults>
1414
{
1515
event EventHandler<ValueResultEventArgs> OnValueResultCreated;
1616
}
1717

18-
public class UCIParseTreeValueVisitor : IUCIParseTreeValueVisitor
18+
public class ParseTreeValueVisitor : IParseTreeValueVisitor
1919
{
20-
private IUCIValueResults _contextValues;
20+
private IParseTreeVisitorResults _contextValues;
2121
private RubberduckParserState _state;
22-
private IUCIValueFactory _inspValueFactory;
22+
private IParseTreeValueFactory _inspValueFactory;
2323

24-
public UCIParseTreeValueVisitor(RubberduckParserState state, IUCIValueFactory valueFactory)
24+
public ParseTreeValueVisitor(RubberduckParserState state, IParseTreeValueFactory valueFactory)
2525
{
2626
_state = state;
2727
_inspValueFactory = valueFactory;
28-
Calculator = new UCIValueExpressionEvaluator(valueFactory);
29-
_contextValues = new UCIValueResults();
28+
Calculator = new ParseTreeExpressionEvaluator(valueFactory);
29+
_contextValues = new ParseTreeVisitorResults();
3030
OnValueResultCreated += _contextValues.OnNewValueResult;
3131
}
3232

3333
public event EventHandler<ValueResultEventArgs> OnValueResultCreated;
3434

35-
public IUCIValueExpressionEvaluator Calculator { set; get; }
35+
public IParseTreeExpressionEvaluator Calculator { set; get; }
3636

37-
public virtual IUCIValueResults Visit(IParseTree tree)
37+
public virtual IParseTreeVisitorResults Visit(IParseTree tree)
3838
{
3939
if (tree is ParserRuleContext context)
4040
{
@@ -43,7 +43,7 @@ public virtual IUCIValueResults Visit(IParseTree tree)
4343
return _contextValues;
4444
}
4545

46-
public virtual IUCIValueResults VisitChildren(IRuleNode node)
46+
public virtual IParseTreeVisitorResults VisitChildren(IRuleNode node)
4747
{
4848
if (node is ParserRuleContext context)
4949
{
@@ -55,12 +55,12 @@ public virtual IUCIValueResults VisitChildren(IRuleNode node)
5555
return _contextValues;
5656
}
5757

58-
public virtual IUCIValueResults VisitTerminal(ITerminalNode node)
58+
public virtual IParseTreeVisitorResults VisitTerminal(ITerminalNode node)
5959
{
6060
return _contextValues;
6161
}
6262

63-
public virtual IUCIValueResults VisitErrorNode(IErrorNode node)
63+
public virtual IParseTreeVisitorResults VisitErrorNode(IErrorNode node)
6464
{
6565
return _contextValues;
6666
}
@@ -75,7 +75,7 @@ internal static bool IsLogicalContext<T>(T context)
7575
return IsBinaryLogicalContext(context) || IsUnaryLogicalContext(context);
7676
}
7777

78-
private void StoreVisitResult(ParserRuleContext context, IUCIValue inspValue)
78+
private void StoreVisitResult(ParserRuleContext context, IParseTreeValue inspValue)
7979
{
8080
OnValueResultCreated(this, new ValueResultEventArgs(context, inspValue));
8181
}
@@ -122,7 +122,7 @@ private void Visit(VBAParser.LExprContext context)
122122
return;
123123
}
124124

125-
IUCIValue newResult = null;
125+
IParseTreeValue newResult = null;
126126
if (TryGetLExprValue(context, out string lexprValue, out string declaredType))
127127
{
128128
newResult = _inspValueFactory.Create(lexprValue, declaredType);
@@ -181,10 +181,10 @@ private void VisitUnaryOpEvaluationContext(ParserRuleContext context)
181181
StoreVisitResult(context, result);
182182
}
183183

184-
private List<IUCIValue> RetrieveRelevantOpData(ParserRuleContext context, out string opSymbol)
184+
private List<IParseTreeValue> RetrieveRelevantOpData(ParserRuleContext context, out string opSymbol)
185185
{
186186
opSymbol = string.Empty;
187-
var values = new List<IUCIValue>();
187+
var values = new List<IParseTreeValue>();
188188
var contextsOfInterest = NonWhitespaceChildren(context);
189189
for (var idx = 0; idx < contextsOfInterest.Count(); idx++)
190190
{
@@ -311,7 +311,7 @@ private string GetConstantDeclarationValueToken(Declaration constantDeclaration)
311311
foreach (var child in contextsOfInterest)
312312
{
313313
Visit(child);
314-
if (_contextValues.TryGetValue(child, out IUCIValue value))
314+
if (_contextValues.TryGetValue(child, out IParseTreeValue value))
315315
{
316316
return value.ValueText;
317317
}
@@ -366,13 +366,13 @@ private static bool IsUnaryLogicalContext<T>(T context)
366366

367367
public class ValueResultEventArgs : EventArgs
368368
{
369-
public ValueResultEventArgs(ParserRuleContext context, IUCIValue value)
369+
public ValueResultEventArgs(ParserRuleContext context, IParseTreeValue value)
370370
{
371371
Context = context;
372372
Value = value;
373373
}
374374

375375
public ParserRuleContext Context { set; get; }
376-
public IUCIValue Value { set; get; }
376+
public IParseTreeValue Value { set; get; }
377377
}
378378
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Rubberduck.Parsing.VBA;
2+
3+
namespace Rubberduck.Inspections.Concrete.UnreachableCaseInspection
4+
{
5+
public interface IParseTreeValueVisitorFactory
6+
{
7+
IParseTreeValueVisitor Create(RubberduckParserState state, IParseTreeValueFactory valueFactory);
8+
}
9+
10+
public class ParseTreeValueVisitorFactory : IParseTreeValueVisitorFactory
11+
{
12+
public IParseTreeValueVisitor Create(RubberduckParserState state, IParseTreeValueFactory valueFactory)
13+
{
14+
return new ParseTreeValueVisitor(state, valueFactory);
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)