C#: Use property- and indexer implementation location and extract the accessor implementations instead of declarations.

This commit is contained in:
Michael Nebel
2025-01-20 14:08:06 +01:00
parent 443a2a47b5
commit 0453ae8dbd
3 changed files with 16 additions and 8 deletions

View File

@@ -30,6 +30,10 @@ namespace Semmle.Extraction.CSharp.Entities
return props.SingleOrDefault();
}
public override bool NeedsPopulation =>
base.NeedsPopulation &&
!Symbol.IsPartialDefinition; // Accessors always have an implementing declaration as well.
public override void Populate(TextWriter trapFile)
{
PopulateMethod(trapFile);

View File

@@ -22,16 +22,16 @@ namespace Semmle.Extraction.CSharp.Entities
foreach (var l in Locations)
trapFile.indexer_location(this, l);
var getter = Symbol.GetMethod;
var setter = Symbol.SetMethod;
var getter = BodyDeclaringSymbol.GetMethod;
var setter = BodyDeclaringSymbol.SetMethod;
if (getter is null && setter is null)
Context.ModelError(Symbol, "No indexer accessor defined");
if (!(getter is null))
if (getter is not null)
Method.Create(Context, getter);
if (!(setter is null))
if (setter is not null)
Method.Create(Context, setter);
for (var i = 0; i < Symbol.Parameters.Length; ++i)

View File

@@ -21,6 +21,10 @@ namespace Semmle.Extraction.CSharp.Entities
private Type Type => type.Value;
protected override IPropertySymbol BodyDeclaringSymbol => Symbol.PartialImplementationPart ?? Symbol;
public override Microsoft.CodeAnalysis.Location? ReportingLocation => BodyDeclaringSymbol.Locations.BestOrDefault();
public override void WriteId(EscapingTextWriter trapFile)
{
trapFile.WriteSubId(Type);
@@ -43,13 +47,13 @@ namespace Semmle.Extraction.CSharp.Entities
var type = Type;
trapFile.properties(this, Symbol.GetName(), ContainingType!, type.TypeRef, Create(Context, Symbol.OriginalDefinition));
var getter = Symbol.GetMethod;
var setter = Symbol.SetMethod;
var getter = BodyDeclaringSymbol.GetMethod;
var setter = BodyDeclaringSymbol.SetMethod;
if (!(getter is null))
if (getter is not null)
Method.Create(Context, getter);
if (!(setter is null))
if (setter is not null)
Method.Create(Context, setter);
var declSyntaxReferences = IsSourceDeclaration ?