~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory/TypeSystem/DomRegion.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
ļ»æ// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
 
2
// 
 
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 
4
// software and associated documentation files (the "Software"), to deal in the Software
 
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
 
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 
7
// to whom the Software is furnished to do so, subject to the following conditions:
 
8
// 
 
9
// The above copyright notice and this permission notice shall be included in all copies or
 
10
// substantial portions of the Software.
 
11
// 
 
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
17
// DEALINGS IN THE SOFTWARE.
 
18
 
 
19
using System;
 
20
using System.Globalization;
 
21
 
 
22
namespace ICSharpCode.NRefactory.TypeSystem
 
23
{
 
24
        [Serializable]
 
25
        public struct DomRegion : IEquatable<DomRegion>
 
26
        {
 
27
                readonly string fileName;
 
28
                readonly int beginLine;
 
29
                readonly int endLine;
 
30
                readonly int beginColumn;
 
31
                readonly int endColumn;
 
32
                
 
33
                public readonly static DomRegion Empty = new DomRegion();
 
34
                
 
35
                public bool IsEmpty {
 
36
                        get {
 
37
                                return BeginLine <= 0;
 
38
                        }
 
39
                }
 
40
                
 
41
                public string FileName {
 
42
                        get { return fileName; }
 
43
                }
 
44
                
 
45
                public int BeginLine {
 
46
                        get {
 
47
                                return beginLine;
 
48
                        }
 
49
                }
 
50
                
 
51
                /// <value>
 
52
                /// if the end line is == -1 the end column is -1 too
 
53
                /// this stands for an unknwon end
 
54
                /// </value>
 
55
                public int EndLine {
 
56
                        get {
 
57
                                return endLine;
 
58
                        }
 
59
                }
 
60
                
 
61
                public int BeginColumn {
 
62
                        get {
 
63
                                return beginColumn;
 
64
                        }
 
65
                }
 
66
                
 
67
                /// <value>
 
68
                /// if the end column is == -1 the end line is -1 too
 
69
                /// this stands for an unknown end
 
70
                /// </value>
 
71
                public int EndColumn {
 
72
                        get {
 
73
                                return endColumn;
 
74
                        }
 
75
                }
 
76
                
 
77
                public TextLocation Begin {
 
78
                        get {
 
79
                                return new TextLocation (beginLine, beginColumn);
 
80
                        }
 
81
                }
 
82
                
 
83
                public TextLocation End {
 
84
                        get {
 
85
                                return new TextLocation (endLine, endColumn);
 
86
                        }
 
87
                }
 
88
                
 
89
                public DomRegion (int beginLine, int beginColumn, int endLine, int endColumn) : this (null, beginLine, beginColumn, endLine, endColumn)
 
90
                {
 
91
                }
 
92
 
 
93
                public DomRegion(string fileName, int beginLine, int beginColumn, int endLine, int endColumn)
 
94
                {
 
95
                        this.fileName = fileName;
 
96
                        this.beginLine   = beginLine;
 
97
                        this.beginColumn = beginColumn;
 
98
                        this.endLine     = endLine;
 
99
                        this.endColumn   = endColumn;
 
100
                }
 
101
                
 
102
                public DomRegion (int beginLine, int beginColumn) : this (null, beginLine, beginColumn)
 
103
                {
 
104
                }
 
105
                
 
106
                public DomRegion (string fileName, int beginLine, int beginColumn)
 
107
                {
 
108
                        this.fileName = fileName;
 
109
                        this.beginLine = beginLine;
 
110
                        this.beginColumn = beginColumn;
 
111
                        this.endLine = -1;
 
112
                        this.endColumn = -1;
 
113
                }
 
114
                
 
115
                public DomRegion (TextLocation begin, TextLocation end) : this (null, begin, end)
 
116
                {
 
117
                }
 
118
                
 
119
                public DomRegion (string fileName, TextLocation begin, TextLocation end)
 
120
                {
 
121
                        this.fileName = fileName;
 
122
                        this.beginLine = begin.Line;
 
123
                        this.beginColumn = begin.Column;
 
124
                        this.endLine = end.Line;
 
125
                        this.endColumn = end.Column;
 
126
                }
 
127
                
 
128
                public DomRegion (TextLocation begin) : this (null, begin)
 
129
                {
 
130
                }
 
131
                
 
132
                public DomRegion (string fileName, TextLocation begin)
 
133
                {
 
134
                        this.fileName = fileName;
 
135
                        this.beginLine = begin.Line;
 
136
                        this.beginColumn = begin.Column;
 
137
                        this.endLine = -1;
 
138
                        this.endColumn = -1;
 
139
                }
 
140
                
 
141
                /// <remarks>
 
142
                /// Returns true, if the given coordinates (line, column) are in the region.
 
143
                /// This method assumes that for an unknown end the end line is == -1
 
144
                /// </remarks>
 
145
                public bool IsInside(int line, int column)
 
146
                {
 
147
                        if (IsEmpty)
 
148
                                return false;
 
149
                        return line >= BeginLine &&
 
150
                                (line <= EndLine   || EndLine == -1) &&
 
151
                                (line != BeginLine || column >= BeginColumn) &&
 
152
                                (line != EndLine   || column <= EndColumn);
 
153
                }
 
154
                
 
155
                public bool IsInside(TextLocation location)
 
156
                {
 
157
                        return IsInside(location.Line, location.Column);
 
158
                }
 
159
                
 
160
                public override string ToString()
 
161
                {
 
162
                        return string.Format(
 
163
                                CultureInfo.InvariantCulture,
 
164
                                "[DomRegion FileName={0}, Begin=({1}, {2}), End=({3}, {4})]",
 
165
                                fileName, beginLine, beginColumn, endLine, endColumn);
 
166
                }
 
167
                
 
168
                public override bool Equals(object obj)
 
169
                {
 
170
                        return obj is DomRegion && Equals((DomRegion)obj);
 
171
                }
 
172
                
 
173
                public override int GetHashCode()
 
174
                {
 
175
                        unchecked {
 
176
                                int hashCode = fileName != null ? fileName.GetHashCode() : 0;
 
177
                                hashCode ^= beginColumn + 1100009 * beginLine + 1200007 * endLine + 1300021 * endColumn;
 
178
                                return hashCode;
 
179
                        }
 
180
                }
 
181
                
 
182
                public bool Equals(DomRegion other)
 
183
                {
 
184
                        return beginLine == other.beginLine && beginColumn == other.beginColumn
 
185
                                && endLine == other.endLine && endColumn == other.endColumn
 
186
                                && fileName == other.fileName;
 
187
                }
 
188
                
 
189
                public static bool operator ==(DomRegion left, DomRegion right)
 
190
                {
 
191
                        return left.Equals(right);
 
192
                }
 
193
                
 
194
                public static bool operator !=(DomRegion left, DomRegion right)
 
195
                {
 
196
                        return !left.Equals(right);
 
197
                }
 
198
        }
 
199
}