Skip to content

Commit 51ae3bb

Browse files
committed
Cleanup
1 parent 838b74e commit 51ae3bb

10 files changed

Lines changed: 51 additions & 307 deletions

File tree

ExpressionToString.sln

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Visualizer", "Tests.V
2727
EndProject
2828
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.DataGenerator", "Tests.DataGenerator\Tests.DataGenerator.csproj", "{68EE3CE3-26F0-4934-AFAC-FC7DDE710EF8}"
2929
EndProject
30-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_visualizerTests.dotnetcore", "_visualizerTests.dotnetcore\_visualizerTests.dotnetcore.csproj", "{E20FCDF7-3E4B-4D4E-A2E7-1CEB94D379B6}"
31-
EndProject
3230
Global
3331
GlobalSection(SharedMSBuildProjectFiles) = preSolution
3432
Visualizer.Shared\Visualizer.Shared.projitems*{16ca0653-e03a-47df-a5bf-292eef9aa5f0}*SharedItemsImports = 13
@@ -113,12 +111,6 @@ Global
113111
{68EE3CE3-26F0-4934-AFAC-FC7DDE710EF8}.Release|Any CPU.Build.0 = Release|Any CPU
114112
{68EE3CE3-26F0-4934-AFAC-FC7DDE710EF8}.ReleaseCI|Any CPU.ActiveCfg = Release|Any CPU
115113
{68EE3CE3-26F0-4934-AFAC-FC7DDE710EF8}.ReleaseCI2017|Any CPU.ActiveCfg = Release|Any CPU
116-
{E20FCDF7-3E4B-4D4E-A2E7-1CEB94D379B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
117-
{E20FCDF7-3E4B-4D4E-A2E7-1CEB94D379B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
118-
{E20FCDF7-3E4B-4D4E-A2E7-1CEB94D379B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
119-
{E20FCDF7-3E4B-4D4E-A2E7-1CEB94D379B6}.Release|Any CPU.Build.0 = Release|Any CPU
120-
{E20FCDF7-3E4B-4D4E-A2E7-1CEB94D379B6}.ReleaseCI|Any CPU.ActiveCfg = Release|Any CPU
121-
{E20FCDF7-3E4B-4D4E-A2E7-1CEB94D379B6}.ReleaseCI2017|Any CPU.ActiveCfg = Release|Any CPU
122114
EndGlobalSection
123115
GlobalSection(SolutionProperties) = preSolution
124116
HideSolutionNode = FALSE

Tests.Common.VB/CompilerGenerated/Literals.vb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ Partial Public Class VBCompilerGeneratedBase
4949

5050
<Fact> <Trait("Category", Literal)>
5151
Sub InterpolatedString()
52-
Dim dte = #2001-1-1#
53-
Dim expr = Functions.Expr(Function() $"{dte}")
54-
Assert.Equal("Function() $""{#" + dte.ToString + "#}""", expr.ToString("Visual Basic"))
52+
Dim expr = Functions.Expr(Function() $"{#2001-1-1#}")
53+
Assert.Equal("Function() $""{#" + #2001-1-1#.ToString + "#}""", expr.ToString("Visual Basic"))
5554
End Sub
5655
End Class

Tests.DataGenerator/NodeTypeExpressionTypeMapper.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

Tests.DataGenerator/Program.cs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,51 @@
66
using System.Reflection;
77
using System.IO;
88
using static ExpressionToString.Tests.Functions;
9+
using System.Collections.Generic;
10+
using System.Linq.Expressions;
11+
using static ExpressionToString.FormatterNames;
12+
using ExpressionToString;
913

1014
namespace Tests.DataGenerator {
1115
class Program {
1216
static void Main(string[] args) {
1317
RegisterTestObjectContainer(typeof(ExpressionToString.Tests.Objects.VBCompiler));
14-
var objects = GetObjects();
1518

16-
return;
19+
var formatter = TextualTree;
20+
var language = CSharp;
21+
var objects = GetObjects();
1722

18-
var instances = new TestsBase[] {
19-
new CompilerGeneratedTestData(),
20-
new ConstructedTestData(),
21-
new VBCompilerGeneratedTestData()
22-
};
23-
var methods = instances
24-
.SelectMany(x =>
25-
x.GetType()
26-
.GetMethods()
27-
.Where(m => m.HasAttribute<FactAttribute>() && m.GetCustomAttribute<FactAttribute>().Skip.IsNullOrWhitespace())
28-
.Select(m => (instance: x, method: m))
29-
)
30-
.OrderBy(x => x.method.ReflectedType.Name)
31-
.ThenBy(x => x.method.Name)
32-
.ToList();
33-
Runner.total = methods.Count;
34-
foreach (var (instance, method) in methods) {
35-
method.Invoke(instance, new object[] { });
36-
}
23+
var lines = new List<string>();
24+
GetObjects().ForEachT((o, objectName, category) => {
25+
lines.Add($"---- {objectName}");
3726

38-
Runner.lines.InsertRange(0, new [] {
39-
$"Count {Runner.lines.Count / 3}",
40-
""
27+
string toWrite;
28+
switch (o) {
29+
case Expression expr:
30+
toWrite = expr.ToString(formatter, language);
31+
break;
32+
case MemberBinding mbind:
33+
toWrite = mbind.ToString(formatter, language);
34+
break;
35+
case ElementInit init:
36+
toWrite = init.ToString(formatter, language);
37+
break;
38+
case SwitchCase switchCase:
39+
toWrite = switchCase.ToString(formatter, language);
40+
break;
41+
case CatchBlock catchBlock:
42+
toWrite = catchBlock.ToString(formatter, language);
43+
break;
44+
case LabelTarget labelTarget:
45+
toWrite = labelTarget.ToString(formatter, language);
46+
break;
47+
default:
48+
throw new NotImplementedException();
49+
}
50+
lines.Add(toWrite);
4151
});
4252

43-
//var toHide = NodeTypeExpressionTypeMapper.maps
44-
// .Where(x => !x.Item1.IsGenericType)
45-
// .GroupBy(x => x.Item1, (key, grp) =>(key, grp.Count()))
46-
// .Where(x => x.Item2 == 1)
47-
// .ToList();
48-
49-
File.WriteAllLines("generated test data.txt", Runner.lines);
53+
File.WriteAllLines("generated test data.txt", lines);
5054
}
5155
}
5256
}

Tests.DataGenerator/Runner.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

Tests.DataGenerator/TestClasses.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

Visualizer.Shared/VisualizerData.cs

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -185,30 +185,12 @@ internal ExpressionNodeData(object o, (string aggregatePath, string pathFromPare
185185
IsDeclaration = isParameterDeclaration;
186186

187187
// fill the Name and Closure properties, for expressions
188-
string staticTypename = "";
189-
switch (expr) {
190-
case ParameterExpression pexpr:
191-
Name = pexpr.Name;
192-
break;
193-
case MemberExpression mexpr:
194-
if (mexpr.Expression == null) {
195-
staticTypename = mexpr.Member.DeclaringType.FriendlyName(language) + ".";
196-
}
197-
Name = staticTypename + mexpr.Member.Name;
198-
var expressionType = mexpr.Expression?.Type;
199-
if (expressionType.IsClosureClass()) {
200-
Closure = expressionType.FriendlyName(language);
201-
}
202-
break;
203-
case MethodCallExpression callexpr:
204-
if (callexpr.Object == null) {
205-
staticTypename = callexpr.Method.DeclaringType.FriendlyName(language) + ".";
206-
}
207-
Name = staticTypename + callexpr.Method.Name;
208-
break;
209-
case LambdaExpression lambdaExpression:
210-
Name = lambdaExpression.Name;
211-
break;
188+
Name = expr.Name(language);
189+
190+
if (expr is MemberExpression mexpr &&
191+
mexpr.Expression?.Type is Type expressionType &&
192+
expressionType.IsClosureClass()) {
193+
Closure = expressionType.Name;
212194
}
213195

214196
object value = null;
@@ -227,8 +209,8 @@ internal ExpressionNodeData(object o, (string aggregatePath, string pathFromPare
227209
EndNodeType = ClosedVar;
228210
break;
229211
case DefaultExpression defexpr:
230-
EndNodeType = Default;
231212
value = defexpr.ExtractValue();
213+
EndNodeType = Default;
232214
break;
233215
}
234216
if (EndNodeType != null) { visualizerData.CollectedEndNodes.Add(this); }
@@ -247,7 +229,6 @@ internal ExpressionNodeData(object o, (string aggregatePath, string pathFromPare
247229
Name = mbind.Member.Name;
248230
break;
249231
case CallSiteBinder callSiteBinder:
250-
ReflectionTypeName = callSiteBinder.GetType().Name;
251232
NodeType = callSiteBinder.BinderType();
252233
break;
253234
default:
@@ -273,7 +254,7 @@ internal ExpressionNodeData(object o, (string aggregatePath, string pathFromPare
273254

274255
// populate Children
275256
var type = o.GetType();
276-
var preferredOrder = preferredPropertyOrders.FirstOrDefault(x => x.Item1.IsAssignableFrom(type)).Item2;
257+
var preferredOrder = PreferredPropertyOrders.FirstOrDefault(x => x.Item1.IsAssignableFrom(type)).Item2;
277258
Children = type.GetProperties()
278259
.Where(prp =>
279260
!(prp.DeclaringType.Name == "BlockExpression" && prp.Name == "Result") &&
@@ -317,23 +298,6 @@ internal ExpressionNodeData(object o, (string aggregatePath, string pathFromPare
317298
}
318299
}
319300

320-
private static List<(Type, string[])> preferredPropertyOrders = new List<(Type, string[])> {
321-
(typeof(LambdaExpression), new [] {"Parameters", "Body" } ),
322-
(typeof(BinaryExpression), new [] {"Left", "Right", "Conversion"}),
323-
(typeof(BlockExpression), new [] { "Variables", "Expressions"}),
324-
(typeof(CatchBlock), new [] { "Variable", "Filter", "Body"}),
325-
(typeof(ConditionalExpression), new [] { "Test", "IfTrue", "IfFalse"}),
326-
(typeof(IndexExpression), new [] { "Object", "Arguments" }),
327-
(typeof(InvocationExpression), new [] {"Arguments", "Expression"}),
328-
(typeof(ListInitExpression), new [] {"NewExpression", "Initializers"}),
329-
(typeof(MemberInitExpression), new [] {"NewExpression", "Bindings"}),
330-
(typeof(MethodCallExpression), new [] {"Object", "Arguments"}),
331-
(typeof(SwitchCase), new [] {"TestValues", "Body"}),
332-
(typeof(SwitchExpression), new [] {"SwitchValue", "Cases", "DefaultBody"}),
333-
(typeof(TryExpression), new [] {"Body", "Handlers", "Finally", "Fault"}),
334-
(typeof(DynamicExpression), new [] {"Binder", "Arguments"})
335-
};
336-
337301
private static Dictionary<Type, List<(string @namespace, string typename)>> baseTypes = new Dictionary<Type, List<(string @namespace, string typename)>>();
338302

339303
private static Dictionary<Type, string[]> factoryMethods = typeof(Expression).GetMethods()

0 commit comments

Comments
 (0)