-
-
Notifications
You must be signed in to change notification settings - Fork 247
/
CodeMetricsService.cs
35 lines (27 loc) · 1.24 KB
/
CodeMetricsService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
namespace Roslynator.CodeMetrics;
internal abstract class CodeMetricsService : ICodeMetricsService
{
public abstract ISyntaxFactsService SyntaxFacts { get; }
public abstract CodeMetricsInfo CountPhysicalLines(SyntaxNode node, SourceText sourceText, CodeMetricsOptions options, CancellationToken cancellationToken);
public abstract CodeMetricsInfo CountLogicalLines(SyntaxNode node, SourceText sourceText, CodeMetricsOptions options, CancellationToken cancellationToken);
private protected int CountWhitespaceLines(SyntaxNode root, SourceText sourceText)
{
int whitespaceLineCount = 0;
foreach (TextLine line in sourceText.Lines)
{
if (line.IsEmptyOrWhiteSpace())
{
if (line.End == sourceText.Length
|| SyntaxFacts.IsEndOfLineTrivia(root.FindTrivia(line.End)))
{
whitespaceLineCount++;
}
}
}
return whitespaceLineCount;
}
}