Skip to content

Commit 3f12101

Browse files
committed
C#: Only use source locations from context.
1 parent 4b33d2c commit 3f12101

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ protected void ExtractCompilerGenerated(TextWriter trapFile)
8181
/// The location which is stored in the database and is used when highlighting source code.
8282
/// It's generally short, e.g. a method name.
8383
/// </summary>
84-
public override Microsoft.CodeAnalysis.Location? ReportingLocation => Symbol.Locations.BestOrDefault();
84+
public override Microsoft.CodeAnalysis.Location? ReportingLocation => Context.GetMsLocations(Symbol).BestOrDefault();
8585

8686
/// <summary>
8787
/// The full text span of the entity, e.g. for binding comments.
8888
/// </summary>
89-
public virtual Microsoft.CodeAnalysis.Location? FullLocation => Symbol.Locations.BestOrDefault();
89+
public virtual Microsoft.CodeAnalysis.Location? FullLocation => Context.GetMsLocations(Symbol).BestOrDefault();
9090

9191
public virtual IEnumerable<Location> Locations
9292
{

csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,9 @@ public override void Populate(TextWriter trapFile)
115115
var type = Type.Create(Context, Symbol.Type);
116116
trapFile.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent!, Original);
117117

118-
foreach (var l in Symbol.Locations)
119-
{
120-
WriteLocationToTrap(trapFile.param_location, this, Context.CreateLocation(l));
121-
}
118+
var locations = Context.GetLocations(Symbol);
119+
120+
WriteLocationsToTrap(trapFile.param_location, this, locations);
122121

123122
if (!Symbol.Locations.Any() &&
124123
Symbol.ContainingSymbol is IMethodSymbol ms &&

csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,20 @@ public bool ExtractLocation(ISymbol symbol) =>
562562
/// <param name="symbol">The symbol</param>
563563
/// <returns>List of locations</returns>
564564
public IEnumerable<Entities.Location> GetLocations(ISymbol symbol) =>
565-
symbol.Locations
566-
.Where(l => !l.IsInSource || IsLocationInContext(l))
565+
GetMsLocations(symbol)
567566
.Select(CreateLocation);
568567

568+
/// <summary>
569+
/// Gets the locations of the symbol that are either
570+
/// (1) In assemblies.
571+
/// (2) In the current context.
572+
/// </summary>
573+
/// <param name="symbol">The symbol</param>
574+
/// <returns>List of locations</returns>
575+
public IEnumerable<Location> GetMsLocations(ISymbol symbol) =>
576+
symbol.Locations
577+
.Where(l => !l.IsInSource || IsLocationInContext(l));
578+
569579
public bool IsLocationInContext(Location location) =>
570580
location.SourceTree == SourceTree;
571581

0 commit comments

Comments
 (0)