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

Add fileIndex property to file object #1186

Merged
merged 2 commits into from
Dec 28, 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
21 changes: 19 additions & 2 deletions src/Sarif.Converters/PREFastConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ private Result CreateResult(Defect defect)
};

var resultsFileUri = new Uri($"{defect.SFA.FilePath}{defect.SFA.FileName}", UriKind.Relative);
var physicalLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: resultsFileUri, uriBaseId: null, properties: null), region: region, contextRegion: null, properties: null);

var physicalLocation = new PhysicalLocation
{
FileLocation = new FileLocation
{
Uri = resultsFileUri
},
Region = region
};

var location = new Location()
{
PhysicalLocation = physicalLocation,
Expand Down Expand Up @@ -169,7 +178,15 @@ private void GenerateCodeFlows(Defect defect, Result result)
};

var uri = new Uri($"{sfa.FilePath}{sfa.FileName}", UriKind.Relative);
var fileLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: uri, uriBaseId: null, properties: null), region: region, contextRegion: null, properties: null);
var fileLocation = new PhysicalLocation
{
FileLocation = new FileLocation
{
Uri = uri
},
Region = region
};

var threadFlowLocation = new ThreadFlowLocation
{
Location = new Location
Expand Down
9 changes: 8 additions & 1 deletion src/Sarif.Converters/PylintConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ internal Result CreateResult(PylintLogEntry defect)
};

var fileUri = new Uri($"{defect.FilePath}", UriKind.RelativeOrAbsolute);
var physicalLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: fileUri, uriBaseId: null, properties: null), region: region, contextRegion: null, properties: null);
var physicalLocation = new PhysicalLocation
{
FileLocation = new FileLocation
{
Uri = fileUri
},
Region = region
};

var location = new Location
{
Expand Down
19 changes: 17 additions & 2 deletions src/Sarif.Converters/TSLintConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ internal Result CreateResult(TSLintLogEntry entry)

Uri analysisTargetUri = new Uri(entry.Name, UriKind.Relative);

var physicalLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: analysisTargetUri, uriBaseId: null, properties: null), region: region, contextRegion: null, properties: null);
var physicalLocation = new PhysicalLocation
{
FileLocation = new FileLocation
{
Uri = analysisTargetUri
},
Region = region
};

Location location = new Location()
{
PhysicalLocation = physicalLocation
Expand Down Expand Up @@ -135,7 +143,14 @@ internal Result CreateResult(TSLintLogEntry entry)
replacements.Add(replacement);
}

FileChange sarifFileChange = new FileChange(fileLocation: new FileLocation(uri: analysisTargetUri, uriBaseId: null, properties: null), replacements: replacements, properties: null);
var sarifFileChange = new FileChange
{
FileLocation = new FileLocation
{
Uri = analysisTargetUri
},
Replacements = replacements
};

Fix sarifFix = new Fix(description: null, fileChanges: new List<FileChange>() { sarifFileChange }, properties: null);
result.Fixes = new List<Fix> { sarifFix };
Expand Down
21 changes: 17 additions & 4 deletions src/Sarif/Autogenerated/FileLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public SarifNodeKind SarifNodeKind
[DataMember(Name = "uriBaseId", IsRequired = false, EmitDefaultValue = false)]
public string UriBaseId { get; set; }

/// <summary>
/// The index within the run files array that specifies the file object associated with the file location.
/// </summary>
[DataMember(Name = "fileIndex", IsRequired = false, EmitDefaultValue = false)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
[System.ComponentModel.DefaultValue(-1)]
public int FileIndex { get; set; }

/// <summary>
/// Key/value pairs that provide additional information about the file location.
/// </summary>
Expand All @@ -57,6 +65,7 @@ public SarifNodeKind SarifNodeKind
/// </summary>
public FileLocation()
{
FileIndex = -1;
}

/// <summary>
Expand All @@ -68,12 +77,15 @@ public FileLocation()
/// <param name="uriBaseId">
/// An initialization value for the <see cref="P: UriBaseId" /> property.
/// </param>
/// <param name="fileIndex">
/// An initialization value for the <see cref="P: FileIndex" /> property.
/// </param>
/// <param name="properties">
/// An initialization value for the <see cref="P: Properties" /> property.
/// </param>
public FileLocation(Uri uri, string uriBaseId, IDictionary<string, SerializedPropertyInfo> properties)
public FileLocation(Uri uri, string uriBaseId, int fileIndex, IDictionary<string, SerializedPropertyInfo> properties)
{
Init(uri, uriBaseId, properties);
Init(uri, uriBaseId, fileIndex, properties);
}

/// <summary>
Expand All @@ -92,7 +104,7 @@ public FileLocation(FileLocation other)
throw new ArgumentNullException(nameof(other));
}

Init(other.Uri, other.UriBaseId, other.Properties);
Init(other.Uri, other.UriBaseId, other.FileIndex, other.Properties);
}

ISarifNode ISarifNode.DeepClone()
Expand All @@ -113,14 +125,15 @@ private ISarifNode DeepCloneCore()
return new FileLocation(this);
}

private void Init(Uri uri, string uriBaseId, IDictionary<string, SerializedPropertyInfo> properties)
private void Init(Uri uri, string uriBaseId, int fileIndex, IDictionary<string, SerializedPropertyInfo> properties)
{
if (uri != null)
{
Uri = new Uri(uri.OriginalString, uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative);
}

UriBaseId = uriBaseId;
FileIndex = fileIndex;
if (properties != null)
{
Properties = new Dictionary<string, SerializedPropertyInfo>(properties);
Expand Down
6 changes: 6 additions & 0 deletions src/Sarif/Autogenerated/FileLocationEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public bool Equals(FileLocation left, FileLocation right)
return false;
}

if (left.FileIndex != right.FileIndex)
{
return false;
}

if (!object.ReferenceEquals(left.Properties, right.Properties))
{
if (left.Properties == null || right.Properties == null || left.Properties.Count != right.Properties.Count)
Expand Down Expand Up @@ -83,6 +88,7 @@ public int GetHashCode(FileLocation obj)
result = (result * 31) + obj.UriBaseId.GetHashCode();
}

result = (result * 31) + obj.FileIndex.GetHashCode();
if (obj.Properties != null)
{
// Use xor for dictionaries to be order-independent.
Expand Down
4 changes: 2 additions & 2 deletions src/Sarif/Autogenerated/RuleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public SarifNodeKind SarifNodeKind
public bool Enabled { get; set; }

/// <summary>
/// Specifies the default severity level of the result.
/// Specifies the default severity level for results generated by this rule.
/// </summary>
[DataMember(Name = "defaultLevel", IsRequired = false, EmitDefaultValue = false)]
[JsonConverter(typeof(EnumConverter))]
public RuleConfigurationDefaultLevel DefaultLevel { get; set; }

/// <summary>
/// Specifies the default priority or importance of the result.
/// Specifies the default priority or importance for results generated by this rule.
/// </summary>
[DataMember(Name = "defaultRank", IsRequired = false, EmitDefaultValue = false)]
public double DefaultRank { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public SarifNodeKind SarifNodeKind
public IDictionary<string, FileLocation> OriginalUriBaseIds { get; set; }

/// <summary>
/// A dictionary, each of whose keys is a URI and each of whose values is a file object.
/// An array of file objects relevant to the run.
/// </summary>
[DataMember(Name = "files", IsRequired = false, EmitDefaultValue = false)]
public IDictionary<string, FileData> Files { get; set; }
Expand Down
34 changes: 34 additions & 0 deletions src/Sarif/CodeGenHints.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,23 @@
}
}
],
"FileLocation.FileIndex": [
{
"kind": "AttributeHint",
"arguments": {
"namespaceName": "Newtonsoft.Json",
"typeName": "JsonProperty",
"arguments": [ "DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate" ]
}
},
{
"kind": "AttributeHint",
"arguments": {
"typeName": "System.ComponentModel.DefaultValue",
"arguments": [ "-1" ]
}
}
],
"fix": [
{
"kind": "BaseTypeHint",
Expand Down Expand Up @@ -289,6 +306,23 @@
}
}
],
"Location.LogicalLocationIndex": [
{
"kind": "AttributeHint",
"arguments": {
"namespaceName": "Newtonsoft.Json",
"typeName": "JsonProperty",
"arguments": [ "DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate" ]
}
},
{
"kind": "AttributeHint",
"arguments": {
"typeName": "System.ComponentModel.DefaultValue",
"arguments": [ "-1" ]
}
}
],
"logicalLocation": [
{
"kind": "BaseTypeHint",
Expand Down
143 changes: 143 additions & 0 deletions src/Sarif/NotYetAutoGenerated/FileLocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Copyright (c) Microsoft. All Rights Reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Microsoft.CodeAnalysis.Sarif.Readers;
using Newtonsoft.Json;

namespace Microsoft.CodeAnalysis.Sarif
{
/// <summary>
/// Specifies the location of a file.
/// </summary>
[DataContract]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "0.58.0.0")]
public partial class FileLocation : PropertyBagHolder, ISarifNode
{
public static IEqualityComparer<FileLocation> ValueComparer => FileLocationEqualityComparer.Instance;

public bool ValueEquals(FileLocation other) => ValueComparer.Equals(this, other);
public int ValueGetHashCode() => ValueComparer.GetHashCode(this);

/// <summary>
/// Gets a value indicating the type of object implementing <see cref="ISarifNode" />.
/// </summary>
public SarifNodeKind SarifNodeKind
{
get
{
return SarifNodeKind.FileLocation;
}
}

/// <summary>
/// A string containing a valid relative or absolute URI.
/// </summary>
[DataMember(Name = "uri", IsRequired = true)]
[JsonConverter(typeof(Microsoft.CodeAnalysis.Sarif.Readers.UriConverter))]
public Uri Uri { get; set; }

/// <summary>
/// A string which indirectly specifies the absolute URI with respect to which a relative URI in the "uri" property is interpreted.
/// </summary>
[DataMember(Name = "uriBaseId", IsRequired = false, EmitDefaultValue = false)]
public string UriBaseId { get; set; }

/// <summary>
/// The index within the run files array that specifies the file object associated with the file location.
/// </summary>
[DataMember(Name = "fileIndex", IsRequired = false, EmitDefaultValue = false)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
[System.ComponentModel.DefaultValue(-1)]
public int FileIndex { get; set; }

/// <summary>
/// Key/value pairs that provide additional information about the file location.
/// </summary>
[DataMember(Name = "properties", IsRequired = false, EmitDefaultValue = false)]
internal override IDictionary<string, SerializedPropertyInfo> Properties { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="FileLocation" /> class.
/// </summary>
public FileLocation()
{
FileIndex = -1;
}

/// <summary>
/// Initializes a new instance of the <see cref="FileLocation" /> class from the supplied values.
/// </summary>
/// <param name="uri">
/// An initialization value for the <see cref="P: Uri" /> property.
/// </param>
/// <param name="uriBaseId">
/// An initialization value for the <see cref="P: UriBaseId" /> property.
/// </param>
/// <param name="fileIndex">
/// An initialization value for the <see cref="P: FileIndex" /> property.
/// </param>
/// <param name="properties">
/// An initialization value for the <see cref="P: Properties" /> property.
/// </param>
public FileLocation(Uri uri, string uriBaseId, int fileIndex, IDictionary<string, SerializedPropertyInfo> properties)
{
Init(uri, uriBaseId, fileIndex, properties);
}

/// <summary>
/// Initializes a new instance of the <see cref="FileLocation" /> class from the specified instance.
/// </summary>
/// <param name="other">
/// The instance from which the new instance is to be initialized.
/// </param>
/// <exception cref="ArgumentNullException">
/// Thrown if <paramref name="other" /> is null.
/// </exception>
public FileLocation(FileLocation other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}

Init(other.Uri, other.UriBaseId, other.FileIndex, other.Properties);
}

ISarifNode ISarifNode.DeepClone()
{
return DeepCloneCore();
}

/// <summary>
/// Creates a deep copy of this instance.
/// </summary>
public FileLocation DeepClone()
{
return (FileLocation)DeepCloneCore();
}

private ISarifNode DeepCloneCore()
{
return new FileLocation(this);
}

private void Init(Uri uri, string uriBaseId, int fileIndex, IDictionary<string, SerializedPropertyInfo> properties)
{
if (uri != null)
{
Uri = new Uri(uri.OriginalString, uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative);
}

UriBaseId = uriBaseId;
FileIndex = fileIndex;
if (properties != null)
{
Properties = new Dictionary<string, SerializedPropertyInfo>(properties);
}
}
}
}
2 changes: 2 additions & 0 deletions src/Sarif/Sarif.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@
</ItemGroup>

<Import Project="ToDotNet\ToDotNet.targets" />

<ProjectExtensions><VisualStudio><UserProperties CodeGenHints_1json__JSONSchema="http://json.schemastore.org/asmdef" /></VisualStudio></ProjectExtensions>
</Project>
Loading