-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathScriptWriter.AlignmentPointData.cs
More file actions
102 lines (93 loc) · 3.93 KB
/
Copy pathScriptWriter.AlignmentPointData.cs
File metadata and controls
102 lines (93 loc) · 3.93 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//------------------------------------------------------------------------------
// <copyright file="ScriptWriter.AlignmentPointInstance.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Collections.Generic;
namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator
{
internal partial class ScriptWriter
{
//[DebuggerDisplay("AlignmentPoint#{Id}(name:{Name}, offset:{Offset}, left:{_leftPoints.Count}, right:{_rightPoints.Count})")]
internal class AlignmentPointData : ScriptWriterElement
{
#if false
private static Int32 _nextId = 0;
internal Int32 Id { get; private set; }
#endif
private Dictionary<AlignmentPointData, Int32> _leftPoints;
private HashSet<AlignmentPointData> _rightPoints;
public AlignmentPointData(String name)
{
this.ElementType = ScriptWriter.ScriptWriterElementType.AlignmentPoint;
Name = name;
_leftPoints = new Dictionary<AlignmentPointData, Int32>();
_rightPoints = new HashSet<AlignmentPointData>();
#if false
Id = _nextId++;
#endif
}
public Int32 Offset { get; set; }
public String Name { get; private set; }
// Tab-layout data (only used when IndentationMode is Tabs). TabTarget is the column the
// content following this alignment point is snapped to (a tab stop); TabShift is how far
// that content is shifted right versus the space layout; MaxLeftTabShift accumulates the
// TabShift of this point's left neighbours; and AbsorbsSeparator is set when this point is
// immediately followed by a single separator space that the tab run replaces.
public Int32 TabTarget { get; set; }
public Int32 TabShift { get; set; }
public Int32 MaxLeftTabShift { get; set; }
public Boolean AbsorbsSeparator { get; set; }
public void AddLeftPoint(AlignmentPointData ap, Int32 width)
{
Int32 currentWidth;
if (_leftPoints.TryGetValue(ap, out currentWidth) == false)
{
// we don't have this point yet, add it
_leftPoints.Add(ap, width);
}
else if (currentWidth < width)
{
// we already have this one, but its width is smaller, so we update it
_leftPoints[ap] = width;
}
// we do nothing if we already have this point and its width is larger
}
public Boolean HasNoLeftPoints
{
get
{
return _leftPoints.Count == 0;
}
}
public void AddRightPoint(AlignmentPointData ap)
{
_rightPoints.Add(ap);
}
public HashSet<AlignmentPointData> RightPoints
{
get
{
return _rightPoints;
}
}
// push the current point right when necessary based on the given left alignment point
// after processing, remove the given point from the left point set of the current point
public void AlignAndRemoveLeftPoint(AlignmentPointData ap)
{
Int32 width;
if (_leftPoints.TryGetValue(ap, out width))
{
Offset = Math.Max(ap.Offset + width, Offset);
_leftPoints.Remove(ap);
}
else
{
Debug.Assert(false, "Cannot find the given AlignmentPointData");
}
}
}
}
}