Skip to content

Commit ded1328

Browse files
committed
C#: Do not extract comments when scaffolding.
1 parent 9d300e3 commit ded1328

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public virtual IEnumerable<Location> Locations
109109
/// </summary>
110110
protected void BindComments()
111111
{
112-
if (!Symbol.IsImplicitlyDeclared && IsSourceDeclaration && Symbol.FromSource() && !Context.OnlyScaffold)
112+
if (!Symbol.IsImplicitlyDeclared && IsSourceDeclaration && Symbol.FromSource())
113113
Context.BindComments(this, FullLocation);
114114
}
115115

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ private CommentBlock(Context cx, Comments.CommentBlock init)
1010

1111
public override void Populate(TextWriter trapFile)
1212
{
13-
trapFile.commentblock(this);
14-
Symbol.CommentLines.ForEach((l, child) => trapFile.commentblock_child(this, l, child));
1513
if (Context.OnlyScaffold)
1614
{
1715
return;
1816
}
17+
trapFile.commentblock(this);
18+
Symbol.CommentLines.ForEach((l, child) => trapFile.commentblock_child(this, l, child));
1919
WriteLocationToTrap(trapFile.commentblock_location, this, Context.CreateLocation(Symbol.Location));
2020
}
2121

@@ -31,6 +31,10 @@ public override void WriteId(EscapingTextWriter trapFile)
3131

3232
public void BindTo(Label entity, CommentBinding binding)
3333
{
34+
if (Context.OnlyScaffold)
35+
{
36+
return;
37+
}
3438
Context.TrapWriter.Writer.commentblock_binding(this, entity, binding);
3539
}
3640

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ private CommentLine(Context cx, Microsoft.CodeAnalysis.Location loc, CommentLine
2121

2222
public override void Populate(TextWriter trapFile)
2323
{
24-
trapFile.commentline(this, Type == CommentLineType.MultilineContinuation ? CommentLineType.Multiline : Type, Text, RawText);
2524
if (Context.OnlyScaffold)
2625
{
2726
return;
2827
}
28+
trapFile.commentline(this, Type == CommentLineType.MultilineContinuation ? CommentLineType.Multiline : Type, Text, RawText);
2929
location = Context.CreateLocation(Location);
3030
WriteLocationToTrap(trapFile.commentline_location, this, location);
3131

csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ public Entities.Location CreateLocation(Microsoft.CodeAnalysis.Location? locatio
631631
/// <param name="l">Location of the entity.</param>
632632
public void BindComments(Entity entity, Microsoft.CodeAnalysis.Location? l)
633633
{
634+
if (OnlyScaffold)
635+
{
636+
return;
637+
}
634638
var duplicationGuardKey = GetCurrentTagStackKey();
635639
CommentGenerator.AddElement(entity.Label, duplicationGuardKey, l);
636640
}

csharp/extractor/Semmle.Extraction.CSharp/Populators/CommentPopulator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ internal static class CommentPopulator
1212
{
1313
public static void ExtractCommentBlocks(Context cx, CommentProcessor gen)
1414
{
15+
if (cx.OnlyScaffold)
16+
{
17+
return;
18+
}
1519
cx.Try(null, null, () =>
1620
{
1721
gen.GenerateBindings((entity, duplicationGuardKey, block, binding) =>
@@ -34,6 +38,10 @@ public static void ExtractCommentBlocks(Context cx, CommentProcessor gen)
3438

3539
public static void ExtractComment(Context cx, SyntaxTrivia trivia)
3640
{
41+
if (cx.OnlyScaffold)
42+
{
43+
return;
44+
}
3745
switch (trivia.Kind())
3846
{
3947
case SyntaxKind.SingleLineDocumentationCommentTrivia:

0 commit comments

Comments
 (0)