-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathSqlScriptGeneratorVisitor.StatementList.cs
More file actions
54 lines (50 loc) · 2.48 KB
/
SqlScriptGeneratorVisitor.StatementList.cs
File metadata and controls
54 lines (50 loc) · 2.48 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//------------------------------------------------------------------------------
// <copyright file="SqlScriptGeneratorVisitor.StatementList.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using Microsoft.SqlServer.TransactSql.ScriptDom;
using System;
namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator
{
partial class SqlScriptGeneratorVisitor
{
public override void ExplicitVisit(StatementList node)
{
if (node.Statements != null)
{
for (int i = 0; i < node.Statements.Count; i++)
{
var statement = node.Statements[i];
if (i > 0)
{
for (var nl = 0; nl < _options.NumNewlinesAfterStatement; nl++)
{
NewLine();
}
// Emit any deferred comments captured from previous statement before generating the next.
EmitPendingLeadingComments();
}
GenerateFragmentIfNotNull(statement);
// If we just generated a statement and the last emitted token is a single-line comment
// while more statements follow, and PreserveComments + spacing option indicate separation,
// defer that comment so it becomes a leading comment for the next statement instead of
// trailing inline before the semicolon.
if (_options.PreserveComments && i < node.Statements.Count - 1 && _options.NumNewlinesAfterStatement > 0)
{
var deferred = _writer.PopLastSingleLineCommentIfAny();
if (deferred != null)
{
_pendingLeadingComments.Add(deferred);
_suppressNextClauseAlignment = false; // ensure next clause aligns normally
_writer.TrimTrailingWhitespace(); // remove space that was inserted for inline comment
}
}
GenerateSemiColonWhenNecessary(statement);
}
// In case script ends with deferred comments (edge case), emit them.
EmitPendingLeadingComments();
}
}
}
}