Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix qualified class names #52

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions FineCodeCoverage/Core/FCCEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Process PropertyGroup settings
return settings;
}

public static string[] GetSourceFiles(string assemblyName, string className)
public static string[] GetSourceFiles(string assemblyName, string qualifiedClassName)
{
// Note : There may be more than one file; e.g. in the case of partial classes

Expand All @@ -271,11 +271,9 @@ public static string[] GetSourceFiles(string assemblyName, string className)
return new string[0];
}

var longClassName = $"{assemblyName}.{className}";

var classFiles = package
.Classes.Class
.Where(x => x.Name.Equals(longClassName))
.Where(x => x.Name.Equals(qualifiedClassName))
.Select(x => x.Filename)
.ToArray();

Expand Down
53 changes: 48 additions & 5 deletions FineCodeCoverage/Core/ReportGenerator/ReportGeneratorUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ public static void ProcessCoberturaHtmlFile(string htmlFile, bool darkMode, out

var htmlFileContent = File.ReadAllText(htmlFile);

// delete all html files

var folder = Path.GetDirectoryName(htmlFile);

// create and save doc util
Expand Down Expand Up @@ -274,8 +272,50 @@ public static void ProcessCoberturaHtmlFile(string htmlFile, bool darkMode, out
try { tableRows[12].SetAttributeValue("style", "display:none"); } catch { }

// TEXT changes
var assemblyClassDelimiter = "!";
var outerHtml = doc.DocumentNode.OuterHtml;
var htmlSb = new StringBuilder(outerHtml);
var assembliesSearch = "var assemblies = [";
var startIndex = outerHtml.IndexOf(assembliesSearch) + assembliesSearch.Length - 1;
var endIndex = outerHtml.IndexOf("var historicCoverageExecutionTimes");
var assembliesToReplace = outerHtml.Substring(startIndex, endIndex - startIndex);
endIndex = assembliesToReplace.LastIndexOf(']');
assembliesToReplace = assembliesToReplace.Substring(0, endIndex + 1);
var assemblies = JArray.Parse(assembliesToReplace);
foreach (JObject assembly in assemblies)
{
var assemblyName = assembly["name"];
var classes = assembly["classes"] as JArray;

var autoGeneratedRemovals = new List<JObject>();
foreach (JObject @class in classes)
{
var className = @class["name"].ToString();
if (className == "AutoGeneratedProgram")
{
autoGeneratedRemovals.Add(@class);
}
else
{
// simplify name
var lastIndexOfDotInName = className.LastIndexOf('.');
if (lastIndexOfDotInName != -1) @class["name"] = className.Substring(lastIndexOfDotInName).Trim('.');

//mark with # and add the assembly name
var rp = @class["rp"].ToString();
var htmlIndex = rp.IndexOf(".html");
@class["rp"] = $"#{assemblyName}{assemblyClassDelimiter}{className + ".html" + rp.Substring(htmlIndex + 5)}";
}

}
foreach (var autoGeneratedRemoval in autoGeneratedRemovals)
{
classes.Remove(autoGeneratedRemoval);
}

var htmlSb = new StringBuilder(doc.DocumentNode.OuterHtml);
}
var assembliesReplaced = assemblies.ToString();
htmlSb.Replace(assembliesToReplace, assembliesReplaced);

htmlSb.Replace(".table-fixed", ".table-fixed-ignore-me");

Expand Down Expand Up @@ -357,15 +397,18 @@ public static void ProcessCoberturaHtmlFile(string htmlFile, bool darkMode, out
if (event.preventDefault) event.preventDefault()
if (event.stopPropagation) event.stopPropagation();

var classs = classes[href];
var assemblyAndQualifiedClassName = href.substring(1, htmlExtensionIndex);
var delimiterIndex = assemblyAndQualifiedClassName.indexOf('{assemblyClassDelimiter}');
var assembly = assemblyAndQualifiedClassName.substring(0, delimiterIndex);
var qualifiedClassName = assemblyAndQualifiedClassName.substring(delimiterIndex + 1);
var fileLine = href.substring(htmlExtensionIndex + htmlExtension.length);

if (fileLine.indexOf('#') !== -1)
fileLine = fileLine.substring(fileLine.indexOf('#') + 1).replace('file', '').replace('line', '').split('_');
else
fileLine = ['0', '0'];

window.external.OpenFile(classs.assembly.name, classs.name, parseInt(fileLine[0]), parseInt(fileLine[1]));
window.external.OpenFile(assembly, qualifiedClassName, parseInt(fileLine[0]), parseInt(fileLine[1]));

return false;
}});
Expand Down
6 changes: 3 additions & 3 deletions FineCodeCoverage/Output/OutputToolWindowControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public ScriptManager(DTE dte)

[SuppressMessage("Usage", "VSTHRD104:Offer async methods")]
[SuppressMessage("Style", "IDE0060:Remove unused parameter")]
public void OpenFile(string assemblyName, string className, int file, int line)
public void OpenFile(string assemblyName, string qualifiedClassName, int file, int line)
{
// Note : There may be more than one file; e.g. in the case of partial classes

var sourceFiles = FCCEngine.GetSourceFiles(assemblyName, className);
var sourceFiles = FCCEngine.GetSourceFiles(assemblyName, qualifiedClassName);

if (!sourceFiles.Any())
{
var message = $"Source File(s) Not Found : [{ assemblyName }]{ className }";
var message = $"Source File(s) Not Found : [{ assemblyName }]{ qualifiedClassName }";
Logger.Log(message);
MessageBox.Show(message);
return;
Expand Down