Skip to content

Commit

Permalink
Issue Accenture#3 - Fix renaming of delegate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sadreck committed Nov 26, 2022
1 parent 7edc9e5 commit 4f79f36
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Codecepticon/Codecepticon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<LangVersion>9.0</LangVersion>
<PackageId>Codecepticon</PackageId>
<Title>Codecepticon</Title>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<Authors>Pavel Tsakalidis</Authors>
<Company>Accenture Security</Company>
<Product>Codecepticon</Product>
Expand Down
12 changes: 12 additions & 0 deletions Codecepticon/Modules/CSharp/DataCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,18 @@ public static async Task CollectFunctions(Solution solution, string projectName,
}
AllFunctions.Add(name);
}

// Also collect Delegate function declarations.
var delegateMethods = syntaxTree.GetRoot().DescendantNodes().OfType<DelegateDeclarationSyntax>();
foreach (var m in delegateMethods)
{
string name = m.Identifier.ToString();
if (AllFunctions.Contains(name))
{
continue;
}
AllFunctions.Add(name);
}
}

public static async Task FilterCollectedData()
Expand Down
15 changes: 15 additions & 0 deletions Codecepticon/Modules/CSharp/DataRenamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ public async Task<Solution> RenameFunctions(Solution solution, string projectNam
solution = await RenameCode<MethodDeclarationSyntax>(solution, projectName, documentName, name, DataCollector.Mapping.Functions[name]);
}

// Rename delegates.
var delegateMethods = syntaxTree.GetRoot().DescendantNodes().OfType<DelegateDeclarationSyntax>();
foreach(var m in delegateMethods)
{
string name = m.Identifier.ToString();
if (!DataCollector.Mapping.Functions.ContainsKey(name))
{
Logger.Debug($"Delegate Function does not exist in mapping: {name}");

continue;
}

solution = await RenameCode<DelegateDeclarationSyntax>(solution, projectName, documentName, name, DataCollector.Mapping.Functions[name]);
}

return solution;
}

Expand Down
4 changes: 4 additions & 0 deletions Codecepticon/Modules/CSharp/SyntaxTreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ public async Task<Solution> RenameCode<T>(Solution solution, string projectName,
{
node = ((IEnumerable<ClassDeclarationSyntax>)nodes).FirstOrDefault(s => s.Identifier.ToString() == existingName);
}
else if (typeof(T) == typeof(DelegateDeclarationSyntax))
{
node = ((IEnumerable<DelegateDeclarationSyntax>)nodes).FirstOrDefault(s => s.Identifier.ToString() == existingName);
}
else if (typeof(T) == typeof(MethodDeclarationSyntax))
{
node = ((IEnumerable<MethodDeclarationSyntax>)nodes).FirstOrDefault(s => s.Identifier.ToString() == existingName);
Expand Down
3 changes: 1 addition & 2 deletions Codecepticon/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"profiles": {
"Codecepticon": {
"commandName": "Project",
"commandLineArgs": "--config C:\\data\\tmp\\seatbelt.xml"
"commandName": "Project"
}
}
}

0 comments on commit 4f79f36

Please sign in to comment.