mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Use property- and indexer implementation location and extract the accessor implementations instead of declarations.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 ?
|
||||
|
||||
Reference in New Issue
Block a user