Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58e6d23

Browse files
committed
C#: Tidy up CommentProcessing.
1 parent c642e72 commit 58e6d23

7 files changed

Lines changed: 208 additions & 173 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override IId Id
3232

3333
public override Microsoft.CodeAnalysis.Location ReportingLocation => symbol.Location;
3434

35-
public void BindTo(Label entity, Binding binding)
35+
public void BindTo(Label entity, CommentBinding binding)
3636
{
3737
Context.Emit(Tuples.commentblock_binding(this, entity, binding));
3838
}

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
using Microsoft.CodeAnalysis;
33
using Microsoft.CodeAnalysis.CSharp;
44
using Semmle.Extraction.Entities;
5-
using System;
65

76
namespace Semmle.Extraction.CSharp.Entities
87
{
98
class CommentLine : CachedEntity<(Microsoft.CodeAnalysis.Location, string)>, ICommentLine
109
{
11-
CommentLine(Context cx, Microsoft.CodeAnalysis.Location loc, CommentType type, string text, string raw)
10+
CommentLine(Context cx, Microsoft.CodeAnalysis.Location loc, CommentLineType type, string text, string raw)
1211
: base(cx, (loc, text))
1312
{
1413
Type = type;
1514
RawText = raw;
1615
}
1716

1817
public Microsoft.CodeAnalysis.Location Location => symbol.Item1;
19-
public CommentType Type { get; private set; }
18+
public CommentLineType Type { get; private set; }
2019

2120
public string Text { get { return symbol.Item2; } }
2221
public string RawText { get; private set; }
@@ -53,7 +52,7 @@ So split it up.
5352

5453
var span = Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(currentLocation, currentLocation + fullLine.Length);
5554
var location = Microsoft.CodeAnalysis.Location.Create(trivia.SyntaxTree, span);
56-
var commentType = CommentType.XmlDoc;
55+
var commentType = CommentLineType.XmlDoc;
5756
cx.CommentGenerator.AddComment(Create(cx, location, commentType, trimmedLine, fullLine));
5857
}
5958
else
@@ -67,10 +66,10 @@ So split it up.
6766
case SyntaxKind.SingleLineCommentTrivia:
6867
{
6968
string contents = trivia.ToString().Substring(2);
70-
var commentType = CommentType.Singleline;
69+
var commentType = CommentLineType.Singleline;
7170
if (contents.Length > 0 && contents[0] == '/')
7271
{
73-
commentType = CommentType.XmlDoc;
72+
commentType = CommentLineType.XmlDoc;
7473
contents = contents.Substring(1); // An XML comment.
7574
}
7675
cx.CommentGenerator.AddComment(Create(cx, trivia.GetLocation(), commentType, contents.Trim(), trivia.ToFullString()));
@@ -98,7 +97,7 @@ So we split it into separate lines
9897

9998
var span = Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(currentLocation, currentLocation + fullLine.Length);
10099
var location = Microsoft.CodeAnalysis.Location.Create(trivia.SyntaxTree, span);
101-
var commentType = line == 0 ? CommentType.Multiline : CommentType.MultilineContinuation;
100+
var commentType = line == 0 ? CommentLineType.Multiline : CommentLineType.MultilineContinuation;
102101
cx.CommentGenerator.AddComment(Create(cx, location, commentType, trimmedLine, fullLine));
103102
currentLocation = nextLineLocation;
104103
}
@@ -115,7 +114,7 @@ So we split it into separate lines
115114
public override void Populate()
116115
{
117116
location = Context.Create(Location);
118-
Context.Emit(Tuples.commentline(this, Type == CommentType.MultilineContinuation ? CommentType.Multiline : Type, Text, RawText));
117+
Context.Emit(Tuples.commentline(this, Type == CommentLineType.MultilineContinuation ? CommentLineType.Multiline : Type, Text, RawText));
119118
Context.Emit(Tuples.commentline_location(this, location));
120119
}
121120

@@ -132,13 +131,13 @@ public override IId Id
132131
}
133132
}
134133

135-
static CommentLine Create(Context cx, Microsoft.CodeAnalysis.Location loc, CommentType type, string text, string raw) => CommentLineFactory.Instance.CreateEntity(cx, loc, type, text, raw);
134+
static CommentLine Create(Context cx, Microsoft.CodeAnalysis.Location loc, CommentLineType type, string text, string raw) => CommentLineFactory.Instance.CreateEntity(cx, loc, type, text, raw);
136135

137-
class CommentLineFactory : ICachedEntityFactory<(Microsoft.CodeAnalysis.Location, CommentType, string, string), CommentLine>
136+
class CommentLineFactory : ICachedEntityFactory<(Microsoft.CodeAnalysis.Location, CommentLineType, string, string), CommentLine>
138137
{
139138
public static readonly CommentLineFactory Instance = new CommentLineFactory();
140139

141-
public CommentLine Create(Context cx, (Microsoft.CodeAnalysis.Location, CommentType, string, string) init) =>
140+
public CommentLine Create(Context cx, (Microsoft.CodeAnalysis.Location, CommentLineType, string, string) init) =>
142141
new CommentLine(cx, init.Item1, init.Item2, init.Item3, init.Item4);
143142
}
144143

csharp/extractor/Semmle.Extraction.CSharp/Tuples.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ internal static class Tuples
3131

3232
internal static Tuple commentblock(CommentBlock k) => new Tuple("commentblock", k);
3333

34-
internal static Tuple commentblock_binding(CommentBlock commentBlock, Label entity, Binding binding) => new Tuple("commentblock_binding", commentBlock, entity, binding);
34+
internal static Tuple commentblock_binding(CommentBlock commentBlock, Label entity, CommentBinding binding) => new Tuple("commentblock_binding", commentBlock, entity, binding);
3535

3636
internal static Tuple commentblock_child(CommentBlock commentBlock, CommentLine commentLine, int child) => new Tuple("commentblock_child", commentBlock, commentLine, child);
3737

3838
internal static Tuple commentblock_location(CommentBlock k, Location l) => new Tuple("commentblock_location", k, l);
3939

40-
internal static Tuple commentline(CommentLine commentLine, CommentType type, string text, string rawtext) => new Tuple("commentline", commentLine, type, text, rawtext);
40+
internal static Tuple commentline(CommentLine commentLine, CommentLineType type, string text, string rawtext) => new Tuple("commentline", commentLine, type, text, rawtext);
4141

4242
internal static Tuple commentline_location(CommentLine commentLine, Location location) => new Tuple("commentline_location", commentLine, location);
4343

0 commit comments

Comments
 (0)