Skip to content

Commit 0453ae8

Browse files
committed
C#: Use property- and indexer implementation location and extract the accessor implementations instead of declarations.
1 parent 443a2a4 commit 0453ae8

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ protected Accessor(Context cx, IMethodSymbol init, IPropertySymbol property)
3030
return props.SingleOrDefault();
3131
}
3232

33+
public override bool NeedsPopulation =>
34+
base.NeedsPopulation &&
35+
!Symbol.IsPartialDefinition; // Accessors always have an implementing declaration as well.
36+
3337
public override void Populate(TextWriter trapFile)
3438
{
3539
PopulateMethod(trapFile);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ public override void Populate(TextWriter trapFile)
2222
foreach (var l in Locations)
2323
trapFile.indexer_location(this, l);
2424

25-
var getter = Symbol.GetMethod;
26-
var setter = Symbol.SetMethod;
25+
var getter = BodyDeclaringSymbol.GetMethod;
26+
var setter = BodyDeclaringSymbol.SetMethod;
2727

2828
if (getter is null && setter is null)
2929
Context.ModelError(Symbol, "No indexer accessor defined");
3030

31-
if (!(getter is null))
31+
if (getter is not null)
3232
Method.Create(Context, getter);
3333

34-
if (!(setter is null))
34+
if (setter is not null)
3535
Method.Create(Context, setter);
3636

3737
for (var i = 0; i < Symbol.Parameters.Length; ++i)

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ protected Property(Context cx, IPropertySymbol init)
2121

2222
private Type Type => type.Value;
2323

24+
protected override IPropertySymbol BodyDeclaringSymbol => Symbol.PartialImplementationPart ?? Symbol;
25+
26+
public override Microsoft.CodeAnalysis.Location? ReportingLocation => BodyDeclaringSymbol.Locations.BestOrDefault();
27+
2428
public override void WriteId(EscapingTextWriter trapFile)
2529
{
2630
trapFile.WriteSubId(Type);
@@ -43,13 +47,13 @@ public override void Populate(TextWriter trapFile)
4347
var type = Type;
4448
trapFile.properties(this, Symbol.GetName(), ContainingType!, type.TypeRef, Create(Context, Symbol.OriginalDefinition));
4549

46-
var getter = Symbol.GetMethod;
47-
var setter = Symbol.SetMethod;
50+
var getter = BodyDeclaringSymbol.GetMethod;
51+
var setter = BodyDeclaringSymbol.SetMethod;
4852

49-
if (!(getter is null))
53+
if (getter is not null)
5054
Method.Create(Context, getter);
5155

52-
if (!(setter is null))
56+
if (setter is not null)
5357
Method.Create(Context, setter);
5458

5559
var declSyntaxReferences = IsSourceDeclaration ?

0 commit comments

Comments
 (0)