Skip to content

Commit 44575bd

Browse files
committed
Added resx file
- New context function to add parent types
1 parent 6f903a8 commit 44575bd

16 files changed

+1427
-172
lines changed

CSharpCodeAnalyst/CSharpCodeAnalyst.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,19 @@
119119
<HintPath>..\ReferencedAssemblies\Microsoft.Msagl.WpfGraphControl.dll</HintPath>
120120
</Reference>
121121
</ItemGroup>
122+
123+
<ItemGroup>
124+
<Compile Update="Resources\Strings.Designer.cs">
125+
<DesignTime>True</DesignTime>
126+
<AutoGen>True</AutoGen>
127+
<DependentUpon>Strings.resx</DependentUpon>
128+
</Compile>
129+
</ItemGroup>
130+
131+
<ItemGroup>
132+
<EmbeddedResource Update="Resources\Strings.resx">
133+
<Generator>PublicResXFileCodeGenerator</Generator>
134+
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
135+
</EmbeddedResource>
136+
</ItemGroup>
122137
</Project>

CSharpCodeAnalyst/Exploration/CodeGraphExplorer.cs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Contracts.Graph;
1+
using CodeParser.Analysis.Cycles;
2+
using Contracts.Graph;
23

34
namespace CSharpCodeAnalyst.Exploration;
45

@@ -37,6 +38,38 @@ public List<CodeElement> GetElements(List<string> ids)
3738
return elements;
3839
}
3940

41+
public SearchResult CompleteToContainingTypes(HashSet<string> ids)
42+
{
43+
if (_codeGraph is null)
44+
{
45+
return new SearchResult([], []);
46+
}
47+
48+
var parents = new List<CodeElement>();
49+
50+
foreach (var id in ids)
51+
{
52+
if (_codeGraph.Nodes.TryGetValue(id, out var element))
53+
{
54+
var current = element;
55+
while (current.Parent is not null &&
56+
CodeElementClassifier.GetContainerLevel(current.ElementType) == 0)
57+
{
58+
// We need a parent
59+
var parent = current.Parent;
60+
if (ids.Contains(parent.Id) is false)
61+
{
62+
parents.Add(parent);
63+
}
64+
65+
current = current.Parent;
66+
}
67+
}
68+
}
69+
70+
return new SearchResult(parents, []);
71+
}
72+
4073
public SearchResult FindParents(List<string> ids)
4174
{
4275
if (_codeGraph is null)
@@ -211,16 +244,19 @@ public SearchResult FindFullInheritanceTree(string id)
211244
var types = new HashSet<CodeElement>();
212245
var relationships = new HashSet<Dependency>();
213246
var processingQueue = new Queue<CodeElement>();
214-
processingQueue.Enqueue(type);
247+
215248
var processed = new HashSet<string>();
216249

217250
var inheritsAndImplements = FindInheritsAndImplementsRelationships();
251+
252+
// Find base classes recursive
253+
processingQueue.Enqueue(type);
254+
processed.Clear();
218255
while (processingQueue.Any())
219256
{
220257
var typeToAnalyze = processingQueue.Dequeue();
221258
if (!processed.Add(typeToAnalyze.Id))
222259
{
223-
// Since we evaluate both direction in one iteration, an already processed node is added again.
224260
continue;
225261
}
226262

@@ -234,6 +270,19 @@ public SearchResult FindFullInheritanceTree(string id)
234270
relationships.Add(abstraction);
235271
processingQueue.Enqueue(baseType);
236272
}
273+
}
274+
275+
// Find sub-classes recursive
276+
processingQueue.Enqueue(type);
277+
processed.Clear();
278+
while (processingQueue.Any())
279+
{
280+
var typeToAnalyze = processingQueue.Dequeue();
281+
if (!processed.Add(typeToAnalyze.Id))
282+
{
283+
// Since we evaluate both direction in one iteration, an already processed node is added again.
284+
continue;
285+
}
237286

238287
// Case typeToAnalyze is base class: typeToAnalyze is implemented by X or Y inherits from it.
239288
var specializationsOfAnalyzedType
@@ -379,7 +428,7 @@ private HashSet<Dependency> FindInheritsAndImplementsRelationships()
379428

380429
void Collect(CodeElement c)
381430
{
382-
if (c.ElementType is not (CodeElementType.Class or CodeElementType.Interface))
431+
if (c.ElementType is not (CodeElementType.Class or CodeElementType.Interface or CodeElementType.Struct))
383432
{
384433
return;
385434
}

CSharpCodeAnalyst/Exploration/ICodeGraphExplorer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public interface ICodeGraphExplorer
88
Invocation FindOutgoingCalls(string id);
99

1010
/// <summary>
11-
/// Follows all incoming calls recursively.
11+
/// Follows all incoming calls recursively.
1212
/// </summary>
1313
Invocation FindIncomingCallsRecursive(string id);
1414

1515
/// <summary>
16-
/// Traces back callers of the given method. Includes also abstractions and their callers
16+
/// Traces back callers of the given method. Includes also abstractions and their callers
1717
/// </summary>
1818
SearchResult FollowIncomingCallsRecursive(string id);
1919

@@ -39,4 +39,10 @@ public interface ICodeGraphExplorer
3939
void LoadCodeGraph(CodeGraph graph);
4040
List<CodeElement> GetElements(List<string> ids);
4141
SearchResult FindParents(List<string> ids);
42+
43+
/// <summary>
44+
/// Completes the list of Ids such that at least the containing type is present.
45+
/// If we already have a type the search stops.
46+
/// </summary>
47+
SearchResult CompleteToContainingTypes(HashSet<string> ids);
4248
}

CSharpCodeAnalyst/Filter/FilterDialog.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Windows;
22
using CodeParser.Parser.Config;
3+
using CSharpCodeAnalyst.Resources;
34

45
namespace CSharpCodeAnalyst.Filter;
56

@@ -24,7 +25,7 @@ private void OkButton_Click(object sender, RoutedEventArgs e)
2425

2526
if (expressions.Any(f => f.Contains(";")))
2627
{
27-
MessageBox.Show("Filters cannot contain semicolons (;).", "Invalid Filter", MessageBoxButton.OK,
28+
MessageBox.Show(Strings.InvalidFilter_Message, Strings.InvalidFilter_Title, MessageBoxButton.OK,
2829
MessageBoxImage.Error);
2930
return;
3031
}

CSharpCodeAnalyst/GraphArea/DependencyGraphViewer.cs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Runtime.CompilerServices;
44
using System.Windows.Controls;
55
using System.Windows.Input;
6-
using CodeParser.Extensions;
76
using Contracts.Graph;
87
using CSharpCodeAnalyst.Common;
98
using CSharpCodeAnalyst.GraphArea.Highlighting;
@@ -20,7 +19,6 @@ namespace CSharpCodeAnalyst.GraphArea;
2019
/// Between nodes we can have multiple dependencies if the dependency type is different.
2120
/// Dependencies of the same type (i.e a method Calls another multiple times) are handled
2221
/// in the parser. In this case the dependency holds all source references.
23-
///
2422
/// If ever the MSAGL is replaced this is the adapter to re-write.
2523
/// </summary>
2624
internal class DependencyGraphViewer : IDependencyGraphViewer, IDependencyGraphBinding, INotifyPropertyChanged
@@ -238,6 +236,32 @@ public bool IsCollapsed(string id)
238236
return _presentationState.IsCollapsed(id);
239237
}
240238

239+
public void LoadSession(List<CodeElement> codeElements, List<Dependency> dependencies, PresentationState state)
240+
{
241+
if (_msaglViewer is null)
242+
{
243+
return;
244+
}
245+
246+
Clear();
247+
AddToGraphInternal(codeElements, dependencies);
248+
_presentationState = state;
249+
250+
RefreshGraph();
251+
}
252+
253+
public void LoadSession(CodeGraph newGraph, PresentationState? presentationState)
254+
{
255+
if (presentationState is null)
256+
{
257+
presentationState = new PresentationState();
258+
}
259+
260+
_presentationState = presentationState;
261+
_clonedCodeGraph = newGraph;
262+
RefreshGraph();
263+
}
264+
241265
public event PropertyChangedEventHandler? PropertyChanged;
242266

243267
private bool IsBoundToPanel()
@@ -421,30 +445,4 @@ private void AddToContextMenuEntries(Node node, ContextMenu contextMenu)
421445
}
422446
}
423447
}
424-
425-
public void LoadSession(List<CodeElement> codeElements, List<Dependency> dependencies, PresentationState state)
426-
{
427-
if (_msaglViewer is null)
428-
{
429-
return;
430-
}
431-
432-
Clear();
433-
AddToGraphInternal(codeElements, dependencies);
434-
_presentationState = state;
435-
436-
RefreshGraph();
437-
}
438-
439-
public void LoadSession(CodeGraph newGraph, PresentationState? presentationState)
440-
{
441-
if (presentationState is null)
442-
{
443-
presentationState = new PresentationState();
444-
}
445-
446-
_presentationState = presentationState;
447-
_clonedCodeGraph = newGraph;
448-
RefreshGraph();
449-
}
450448
}

0 commit comments

Comments
 (0)