Relocate 'AstLineCounter'

This commit is contained in:
Tamas Vajk
2021-02-10 09:26:28 +01:00
parent 1cd7fd6cf7
commit 6f07230725
2 changed files with 15 additions and 14 deletions

View File

@@ -4,9 +4,9 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
using Semmle.Util;
using System.IO;
namespace Semmle.Extraction.CSharp.Populators
namespace Semmle.Extraction.CSharp.Entities
{
public static class MethodExtensions
public abstract partial class Method
{
private class AstLineCounter : CSharpSyntaxVisitor<LineCounts>
{
@@ -47,15 +47,5 @@ namespace Semmle.Extraction.CSharp.Populators
return Visit(node.OperatorToken, node.Body ?? (SyntaxNode)node.ExpressionBody);
}
}
public static void NumberOfLines(this Context cx, TextWriter trapFile, ISymbol symbol, IEntity callable)
{
foreach (var decl in symbol.DeclaringSyntaxReferences)
{
var node = (CSharpSyntaxNode)decl.GetSyntax();
var lineCounts = node.Accept(new AstLineCounter());
trapFile.numlines(callable, lineCounts);
}
}
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Semmle.Extraction.CSharp.Populators;
using System.Collections.Generic;
@@ -7,7 +8,7 @@ using System.Linq;
namespace Semmle.Extraction.CSharp.Entities
{
public abstract class Method : CachedSymbol<IMethodSymbol>, IExpressionParentEntity, IStatementParentEntity
public abstract partial class Method : CachedSymbol<IMethodSymbol>, IExpressionParentEntity, IStatementParentEntity
{
protected Method(Context cx, IMethodSymbol init)
: base(cx, init) { }
@@ -83,11 +84,21 @@ namespace Semmle.Extraction.CSharp.Entities
else
Expression.Create(Context, expr, this, 0);
Context.NumberOfLines(trapFile, BodyDeclaringSymbol, this);
NumberOfLines(trapFile, BodyDeclaringSymbol, this);
});
}
}
public static void NumberOfLines(TextWriter trapFile, ISymbol symbol, IEntity callable)
{
foreach (var decl in symbol.DeclaringSyntaxReferences)
{
var node = (CSharpSyntaxNode)decl.GetSyntax();
var lineCounts = node.Accept(new AstLineCounter());
trapFile.numlines(callable, lineCounts);
}
}
public void Overrides(TextWriter trapFile)
{
foreach (var explicitInterface in symbol.ExplicitInterfaceImplementations