Skip to content

Commit a61a5bc

Browse files
committed
C#: Only extractor locations for source declarations of methods and constructors.
1 parent adbd36e commit a61a5bc

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public override void Populate(TextWriter trapFile)
2929
ContainingType!.PopulateGenerics();
3030

3131
trapFile.constructors(this, Symbol.ContainingType.Name, ContainingType, (Constructor)OriginalDefinition);
32-
trapFile.constructor_location(this, Location);
32+
if (Context.ExtractLocation(Symbol))
33+
{
34+
trapFile.constructor_location(this, Location);
35+
}
3336

3437
if (MakeSynthetic)
3538
{

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ public override void Populate(TextWriter trapFile)
4343
}
4444
}
4545

46-
foreach (var l in Locations)
47-
trapFile.method_location(this, l);
46+
if (Context.ExtractLocation(Symbol))
47+
{
48+
foreach (var l in Locations)
49+
trapFile.method_location(this, l);
50+
}
4851

4952
PopulateGenerics(trapFile);
5053
Overrides(trapFile);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ public bool Defines(ISymbol symbol) =>
550550
!SymbolEqualityComparer.Default.Equals(symbol, symbol.OriginalDefinition) ||
551551
scope.InScope(symbol);
552552

553+
public bool ExtractLocation(ISymbol symbol) =>
554+
SymbolEqualityComparer.Default.Equals(symbol, symbol.OriginalDefinition) &&
555+
scope.InScope(symbol);
556+
553557
/// <summary>
554558
/// Runs the given action <paramref name="a"/>, guarding for trap duplication
555559
/// based on key <paramref name="key"/>.

0 commit comments

Comments
 (0)