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

Logical locations notes #1184

Merged
merged 2 commits into from
Dec 26, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void AndroidStudioConverter_ConvertSarifResult_DoesNotRecordTopLevelEntry
loc.PhysicalLocation.Should().BeNull();
}

private static void ValidateLogicalLocations(IList<LogicalLocation> expectedLogicalLocations, IList<LogicalLocation> actualLogicalLocations)
internal static void ValidateLogicalLocations(IList<LogicalLocation> expectedLogicalLocations, IList<LogicalLocation> actualLogicalLocations)
{
for (int i = 0; i < expectedLogicalLocations.Count; i++)
{
Expand Down
8 changes: 2 additions & 6 deletions src/Sarif.Converters.UnitTests/FxCopConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,8 @@ public class FxCopConverterTests
{
private static void ValidateLogicalLocations(IList<LogicalLocation> expectedLogicalLocations, IList<LogicalLocation> actualLogicalLocations)
{
actualLogicalLocations.Count.Should().Be(expectedLogicalLocations.Count);

for (int i = 0; i < expectedLogicalLocations.Count; i++)
{
expectedLogicalLocations[i].ValueEquals(actualLogicalLocations[i]).Should().BeTrue();
}
// If we end up with more shared helper code, we could extend these tests types from a common base.
AndroidStudioConverterTests.ValidateLogicalLocations(expectedLogicalLocations, actualLogicalLocations);
}

[Fact]
Expand Down
18 changes: 12 additions & 6 deletions src/Sarif/Writers/PrereleaseCompatibilityTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private static JArray ConstructLogicalLocationsArray(
// location that happened to be enumerated after one of its children
if (fullyQualifiedLogicalNameToIndexMap.ContainsKey(logicalLocationEntry.Name)) { continue; }

fullyQualifiedLogicalNameToIndexMap = CreateLogicalLocationArrayEntry(
AddEntryToFullyQualifiedNameToIndexMap(
logicalLocations,
logicalLocationEntry.Name,
(JObject)logicalLocationEntry.Value,
Expand All @@ -250,15 +250,23 @@ private static JArray ConstructLogicalLocationsArray(
return new JArray(updatedArrayElements);
}

private static Dictionary<string, int> CreateLogicalLocationArrayEntry(
private static void AddEntryToFullyQualifiedNameToIndexMap(
JObject logicalLocationsDictionary,
string keyName,
JObject logicalLocation,
Dictionary<LogicalLocation, int> logicalLocationToIndexMap,
Dictionary<JObject, int> jObjectToIndexMap,
Dictionary<string, int> keyToIndexMap)
{
keyToIndexMap = keyToIndexMap ?? new Dictionary<string, int>();
if (keyToIndexMap == null)
{
throw new ArgumentNullException(nameof(keyToIndexMap));
}

if (logicalLocation == null)
{
throw new ArgumentNullException(nameof(logicalLocation));
}

string fullyQualifiedName = keyName;

Expand All @@ -280,7 +288,7 @@ private static Dictionary<string, int> CreateLogicalLocationArrayEntry(
// determine its index in our array. This code path results in
// an array order that does not precisely match the enumeration
// order of the logical locations dictionary.
keyToIndexMap = CreateLogicalLocationArrayEntry(
AddEntryToFullyQualifiedNameToIndexMap(
logicalLocationsDictionary,
parentKey,
(JObject)logicalLocationsDictionary[parentKey],
Expand Down Expand Up @@ -319,8 +327,6 @@ private static Dictionary<string, int> CreateLogicalLocationArrayEntry(
jObjectToIndexMap[logicalLocation] = index;
keyToIndexMap[fullyQualifiedName] = index;
}

return keyToIndexMap;
}

private static bool RemapRuleDefaultLevelFromOpenToNote(JObject resources)
Expand Down