Skip to content

Commit def1d88

Browse files
committed
C#: Add body of partial methods
1 parent e80cc63 commit def1d88

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void PopulateMethodBody(TextWriter trapFile)
8080
else
8181
Expression.Create(Context, expr, this, 0);
8282

83-
Context.NumberOfLines(trapFile, symbol, this);
83+
Context.NumberOfLines(trapFile, BodyDeclaringSymbol, this);
8484
});
8585
}
8686

@@ -126,7 +126,7 @@ protected static void BuildMethodId(Method m, TextWriter trapFile)
126126
{
127127
trapFile.Write('<');
128128
// Encode the nullability of the type arguments in the label.
129-
// Type arguments with different nullability can result in
129+
// Type arguments with different nullability can result in
130130
// a constructed method with different nullability of its parameters and return type,
131131
// so we need to create a distinct database entity for it.
132132
trapFile.BuildList(",", m.symbol.GetAnnotatedTypeArguments(), (ta, tb0) => { AddSignatureTypeToId(m.Context, tb0, m.symbol, ta.Symbol); trapFile.Write((int)ta.Nullability); });

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class OrdinaryMethod : Method
1313

1414
public override string Name => symbol.GetName();
1515

16+
protected override IMethodSymbol BodyDeclaringSymbol => symbol.PartialImplementationPart ?? symbol;
17+
1618
public IMethodSymbol SourceDeclaration
1719
{
1820
get

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,15 @@ protected void BindComments()
9595
Context.BindComments(this, FullLocation);
9696
}
9797

98+
protected virtual T BodyDeclaringSymbol => symbol;
99+
98100
public BlockSyntax Block
99101
{
100102
get
101103
{
102-
return symbol.
104+
return BodyDeclaringSymbol.
103105
DeclaringSyntaxReferences.
104-
Select(r => r.GetSyntax()).
105-
SelectMany(n => n.ChildNodes()).
106+
SelectMany(r => r.GetSyntax().ChildNodes()).
106107
OfType<BlockSyntax>().
107108
FirstOrDefault();
108109
}
@@ -112,7 +113,7 @@ public ExpressionSyntax ExpressionBody
112113
{
113114
get
114115
{
115-
return symbol.
116+
return BodyDeclaringSymbol.
116117
DeclaringSyntaxReferences.
117118
SelectMany(r => r.GetSyntax().ChildNodes()).
118119
OfType<ArrowExpressionClauseSyntax>().

0 commit comments

Comments
 (0)