Skip to content

Commit 335ec4a

Browse files
authored
Introduce stable names for cycle groups (#38)
1 parent 4a0df3f commit 335ec4a

File tree

163 files changed

+766
-736
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+766
-736
lines changed

ApprovalTestTool/ApprovalTestTool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ItemGroup>
1515
<ProjectReference Include="..\CodeParser\CodeParser.csproj"/>
16-
<ProjectReference Include="..\Contracts\Contracts.csproj"/>
16+
<ProjectReference Include="..\CodeGraph\CodeGraph.csproj"/>
1717
</ItemGroup>
1818

1919
<ItemGroup>

CSharpCodeAnalyst.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2424
.editorconfig = .editorconfig
2525
EndProjectSection
2626
EndProject
27-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Contracts.csproj", "{7D5EA751-84A3-43F1-BCCE-C9D10536AB1B}"
27+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeGraph", "CodeGraph\CodeGraph.csproj", "{7D5EA751-84A3-43F1-BCCE-C9D10536AB1B}"
2828
EndProject
2929
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApprovalTestTool", "ApprovalTestTool\ApprovalTestTool.csproj", "{767539BE-FBE3-4B46-9A5E-21D60E1B278B}"
3030
EndProject

CSharpCodeAnalyst/Analyzers/ArchitecturalRules/Analyzer.cs

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.IO;
33
using System.Text.Json;
44
using System.Windows;
5-
using Contracts.Graph;
65
using CSharpCodeAnalyst.Analyzers.ArchitecturalRules.Presentation;
76
using CSharpCodeAnalyst.Analyzers.ArchitecturalRules.Rules;
87
using CSharpCodeAnalyst.Common;
@@ -13,13 +12,13 @@ namespace CSharpCodeAnalyst.Analyzers.ArchitecturalRules;
1312

1413
public class Analyzer : IAnalyzer
1514
{
16-
private readonly IUserNotification _userNotification;
1715
private readonly IPublisher _messaging;
16+
private readonly IUserNotification _userNotification;
17+
private CodeGraph.Graph.CodeGraph? _currentGraph;
18+
private bool _isDirty;
19+
private ArchitecturalRulesDialog? _openDialog;
1820
private List<RuleBase> _rules = [];
1921
private string _rulesText;
20-
private ArchitecturalRulesDialog? _openDialog;
21-
private CodeGraph? _currentGraph;
22-
private bool _isDirty;
2322

2423
public Analyzer(IPublisher messaging, IUserNotification userNotification)
2524
{
@@ -35,7 +34,7 @@ public Analyzer(IPublisher messaging, IUserNotification userNotification)
3534
_rulesText = GetSampleRules();
3635
}
3736

38-
public void Analyze(CodeGraph graph)
37+
public void Analyze(CodeGraph.Graph.CodeGraph graph)
3938
{
4039
// If dialog is already open, just bring it to front
4140
if (_openDialog != null)
@@ -70,43 +69,6 @@ public void Analyze(CodeGraph graph)
7069
_openDialog.Show();
7170
}
7271

73-
private void OnValidateRules(string rulesText)
74-
{
75-
if (_currentGraph == null)
76-
{
77-
return;
78-
}
79-
80-
try
81-
{
82-
ParseAndStoreRules(rulesText);
83-
}
84-
catch (Exception ex)
85-
{
86-
_userNotification.ShowError($"Error parsing rules: {ex.Message}");
87-
return;
88-
}
89-
90-
// Execute analysis
91-
var violations = ExecuteAnalysis(_currentGraph);
92-
93-
if (violations.Count == 0)
94-
{
95-
_userNotification.ShowSuccess("No rule violations found!");
96-
}
97-
else
98-
{
99-
// Show violations in tabular format
100-
var violationsViewModel = new RuleViolationsViewModel(violations, _currentGraph);
101-
_messaging.Publish(new ShowTabularDataRequest(violationsViewModel));
102-
}
103-
}
104-
105-
private void OnApplicationExit(object sender, ExitEventArgs e)
106-
{
107-
_openDialog?.Close();
108-
}
109-
11072
public string Name
11173
{
11274
get => "Architectural rules";
@@ -119,19 +81,10 @@ public string Id
11981
get => "ArchitecturalRules";
12082
}
12183

122-
void SetDirty(bool isDirty)
123-
{
124-
_isDirty = isDirty;
125-
if (_isDirty)
126-
{
127-
DataChanged?.Invoke(this, EventArgs.Empty);
128-
}
129-
}
130-
13184
public string? GetPersistentData()
13285
{
13386
SetDirty(false);
134-
87+
13588
if (string.IsNullOrEmpty(_rulesText))
13689
{
13790
return null;
@@ -151,7 +104,7 @@ public void SetPersistentData(string? data)
151104
{
152105
_rulesText = string.Empty;
153106
_rules.Clear();
154-
SetDirty(false);
107+
SetDirty(false);
155108
return;
156109
}
157110

@@ -181,10 +134,56 @@ public bool IsDirty()
181134

182135
public event EventHandler? DataChanged;
183136

137+
private void OnValidateRules(string rulesText)
138+
{
139+
if (_currentGraph == null)
140+
{
141+
return;
142+
}
143+
144+
try
145+
{
146+
ParseAndStoreRules(rulesText);
147+
}
148+
catch (Exception ex)
149+
{
150+
_userNotification.ShowError($"Error parsing rules: {ex.Message}");
151+
return;
152+
}
153+
154+
// Execute analysis
155+
var violations = ExecuteAnalysis(_currentGraph);
156+
157+
if (violations.Count == 0)
158+
{
159+
_userNotification.ShowSuccess("No rule violations found!");
160+
}
161+
else
162+
{
163+
// Show violations in tabular format
164+
var violationsViewModel = new RuleViolationsViewModel(violations, _currentGraph);
165+
_messaging.Publish(new ShowTabularDataRequest(violationsViewModel));
166+
}
167+
}
168+
169+
private void OnApplicationExit(object sender, ExitEventArgs e)
170+
{
171+
_openDialog?.Close();
172+
}
173+
174+
private void SetDirty(bool isDirty)
175+
{
176+
_isDirty = isDirty;
177+
if (_isDirty)
178+
{
179+
DataChanged?.Invoke(this, EventArgs.Empty);
180+
}
181+
}
182+
184183
/// <summary>
185184
/// Direct analysis with rules from file (for command-line use)
186185
/// </summary>
187-
public List<Violation> Analyze(CodeGraph graph, string fileToRules)
186+
public List<Violation> Analyze(CodeGraph.Graph.CodeGraph graph, string fileToRules)
188187
{
189188
ParseAndStoreRules(File.ReadAllText(fileToRules));
190189
return ExecuteAnalysis(graph);
@@ -216,16 +215,16 @@ private static string GetSampleRules()
216215
private void ParseAndStoreRules(string rulesText)
217216
{
218217
_rules = RuleParser.ParseRules(rulesText);
219-
218+
220219
if (!_isDirty && _rulesText != rulesText)
221220
{
222221
SetDirty(true);
223222
}
224-
223+
225224
_rulesText = rulesText;
226225
}
227226

228-
private List<Violation> ExecuteAnalysis(CodeGraph graph)
227+
private List<Violation> ExecuteAnalysis(CodeGraph.Graph.CodeGraph graph)
229228
{
230229
var violations = new List<Violation>();
231230

CSharpCodeAnalyst/Analyzers/ArchitecturalRules/PatternMatcher.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Contracts.Graph;
1+
using CodeGraph.Graph;
22

33
namespace CSharpCodeAnalyst.Analyzers.ArchitecturalRules;
44

@@ -8,7 +8,7 @@ public static class PatternMatcher
88
/// Resolves a pattern like "Business.**" to a set of CodeElement IDs
99
/// Pattern format: "Base.Path" or "Base.Path.*" or "Base.Path.**"
1010
/// </summary>
11-
public static HashSet<string> ResolvePattern(string pattern, CodeGraph codeGraph)
11+
public static HashSet<string> ResolvePattern(string pattern, CodeGraph.Graph.CodeGraph codeGraph)
1212
{
1313
var matchingIds = new HashSet<string>();
1414

@@ -47,7 +47,7 @@ private static (string basePath, ExpansionMode mode) ParsePattern(string pattern
4747
return (pattern, ExpansionMode.Self);
4848
}
4949

50-
private static CodeElement? FindStartElement(string basePath, CodeGraph codeGraph)
50+
private static CodeElement? FindStartElement(string basePath, CodeGraph.Graph.CodeGraph codeGraph)
5151
{
5252
// Find element with exact FullName match
5353
return codeGraph.Nodes.Values.FirstOrDefault(element =>

CSharpCodeAnalyst/Analyzers/ArchitecturalRules/Presentation/RelationshipViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Contracts.Graph;
1+
using CodeGraph.Graph;
22

33
namespace CSharpCodeAnalyst.Analyzers.ArchitecturalRules.Presentation;
44

CSharpCodeAnalyst/Analyzers/ArchitecturalRules/Presentation/RuleViolationViewModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Windows;
33
using System.Windows.Input;
44
using System.Windows.Media;
5-
using Contracts.Graph;
65
using CSharpCodeAnalyst.Analyzers.ArchitecturalRules.Rules;
76
using CSharpCodeAnalyst.Resources;
87
using CSharpCodeAnalyst.Shared.DynamicDataGrid.Contracts.TabularData;
@@ -13,10 +12,10 @@ namespace CSharpCodeAnalyst.Analyzers.ArchitecturalRules.Presentation;
1312

1413
public class RuleViolationViewModel : TableRow
1514
{
16-
private readonly CodeGraph _codeGraph;
15+
private readonly CodeGraph.Graph.CodeGraph _codeGraph;
1716
private readonly Violation _violation;
1817

19-
public RuleViolationViewModel(Violation violation, CodeGraph codeGraph)
18+
public RuleViolationViewModel(Violation violation, CodeGraph.Graph.CodeGraph codeGraph)
2019
{
2120
ErrorIcon = IconLoader.LoadIcon("Resources/error.png");
2221
_violation = violation;

CSharpCodeAnalyst/Analyzers/ArchitecturalRules/Presentation/RuleViolationsViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.ObjectModel;
22
using System.Windows;
3-
using Contracts.Graph;
43
using CSharpCodeAnalyst.Shared.DynamicDataGrid.Contracts.TabularData;
54

65
namespace CSharpCodeAnalyst.Analyzers.ArchitecturalRules.Presentation;
@@ -9,7 +8,7 @@ public class RuleViolationsViewModel : Table
98
{
109
private readonly ObservableCollection<TableRow> _violations;
1110

12-
public RuleViolationsViewModel(List<Violation> violations, CodeGraph codeGraph)
11+
public RuleViolationsViewModel(List<Violation> violations, CodeGraph.Graph.CodeGraph codeGraph)
1312
{
1413
var violationViewModels = violations.Select(v => new RuleViolationViewModel(v, codeGraph));
1514
_violations = new ObservableCollection<TableRow>(violationViewModels);

CSharpCodeAnalyst/Analyzers/ArchitecturalRules/Rules/DenyRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Contracts.Graph;
1+
using CodeGraph.Graph;
22

33
namespace CSharpCodeAnalyst.Analyzers.ArchitecturalRules.Rules;
44

CSharpCodeAnalyst/Analyzers/ArchitecturalRules/Rules/IsolateRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Contracts.Graph;
1+
using CodeGraph.Graph;
22

33
namespace CSharpCodeAnalyst.Analyzers.ArchitecturalRules.Rules;
44

CSharpCodeAnalyst/Analyzers/ArchitecturalRules/Rules/RestrictRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Contracts.Graph;
1+
using CodeGraph.Graph;
22

33
namespace CSharpCodeAnalyst.Analyzers.ArchitecturalRules.Rules;
44

0 commit comments

Comments
 (0)