mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
C#: Update the extractor to use the BestOrDefault extension method to choose between multiple locations.
This commit is contained in:
@@ -82,12 +82,12 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
/// The location which is stored in the database and is used when highlighting source code.
|
||||
/// It's generally short, e.g. a method name.
|
||||
/// </summary>
|
||||
public override Microsoft.CodeAnalysis.Location? ReportingLocation => Symbol.Locations.FirstOrDefault();
|
||||
public override Microsoft.CodeAnalysis.Location? ReportingLocation => Symbol.Locations.BestOrDefault();
|
||||
|
||||
/// <summary>
|
||||
/// The full text span of the entity, e.g. for binding comments.
|
||||
/// </summary>
|
||||
public virtual Microsoft.CodeAnalysis.Location? FullLocation => Symbol.Locations.FirstOrDefault();
|
||||
public virtual Microsoft.CodeAnalysis.Location? FullLocation => Symbol.Locations.BestOrDefault();
|
||||
|
||||
public virtual IEnumerable<Extraction.Entities.Location> Locations
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
.OfType<ConversionOperatorDeclarationSyntax>()
|
||||
.Select(s => s.FixedLocation())
|
||||
.Concat(Symbol.Locations)
|
||||
.FirstOrDefault();
|
||||
.BestOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
.OfType<IndexerDeclarationSyntax>()
|
||||
.Select(s => s.GetLocation())
|
||||
.Concat(Symbol.Locations)
|
||||
.First();
|
||||
.Best();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
.OfType<PropertyDeclarationSyntax>()
|
||||
.Select(s => s.GetLocation())
|
||||
.Concat(Symbol.Locations)
|
||||
.First();
|
||||
.Best();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
public static DynamicType Create(Context cx, IDynamicTypeSymbol type) => DynamicTypeFactory.Instance.CreateEntityFromSymbol(cx, type);
|
||||
|
||||
public override Microsoft.CodeAnalysis.Location? ReportingLocation => Context.Compilation.ObjectType.Locations.FirstOrDefault();
|
||||
public override Microsoft.CodeAnalysis.Location? ReportingLocation => Context.Compilation.ObjectType.Locations.BestOrDefault();
|
||||
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
);
|
||||
}
|
||||
|
||||
public override Microsoft.CodeAnalysis.Location? ReportingLocation => GetLocations(Symbol).FirstOrDefault();
|
||||
public override Microsoft.CodeAnalysis.Location? ReportingLocation => GetLocations(Symbol).BestOrDefault();
|
||||
|
||||
private bool IsAnonymousType() => Symbol.IsAnonymousType || Symbol.Name.Contains("__AnonymousType");
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Semmle.Extraction.CSharp
|
||||
return Path.ChangeExtension(entryPointFile, ".exe");
|
||||
}
|
||||
|
||||
var entryPointFilename = entry.Locations.First().SourceTree!.FilePath;
|
||||
var entryPointFilename = entry.Locations.Best().SourceTree!.FilePath;
|
||||
return Path.ChangeExtension(entryPointFilename, ".exe");
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace Semmle.Extraction.CSharp.Populators
|
||||
{
|
||||
return symbol.DeclaringSyntaxReferences.Any() ?
|
||||
symbol.DeclaringSyntaxReferences.First().GetSyntax().FixedLocation() :
|
||||
symbol.Locations.First();
|
||||
symbol.Locations.Best();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,7 +379,7 @@ namespace Semmle.Extraction
|
||||
{
|
||||
if (!(optionalSymbol is null))
|
||||
{
|
||||
ExtractionError(message, optionalSymbol.ToDisplayString(), CreateLocation(optionalSymbol.Locations.FirstOrDefault()));
|
||||
ExtractionError(message, optionalSymbol.ToDisplayString(), CreateLocation(optionalSymbol.Locations.BestOrDefault()));
|
||||
}
|
||||
else if (!(optionalEntity is null))
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Semmle.Extraction
|
||||
{
|
||||
Text = msg;
|
||||
EntityText = symbol.ToString() ?? "";
|
||||
Location = symbol.Locations.FirstOrDefault();
|
||||
Location = symbol.Locations.BestOrDefault();
|
||||
}
|
||||
|
||||
public InternalError(SyntaxNode node, string msg)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Semmle.Extraction
|
||||
|
||||
public static Message Create(Context cx, string text, ISymbol symbol, string? stackTrace = null, Severity severity = Severity.Error)
|
||||
{
|
||||
return new Message(text, symbol.ToString(), cx.CreateLocation(symbol.Locations.FirstOrDefault()), stackTrace, severity);
|
||||
return new Message(text, symbol.ToString(), cx.CreateLocation(symbol.Locations.BestOrDefault()), stackTrace, severity);
|
||||
}
|
||||
|
||||
public static Message Create(Context cx, string text, SyntaxNode node, string? stackTrace = null, Severity severity = Severity.Error)
|
||||
|
||||
Reference in New Issue
Block a user