1
ļ»æ// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
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:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
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.
20
using System.Globalization;
22
namespace ICSharpCode.NRefactory.TypeSystem
25
public struct DomRegion : IEquatable<DomRegion>
27
readonly string fileName;
28
readonly int beginLine;
30
readonly int beginColumn;
31
readonly int endColumn;
33
public readonly static DomRegion Empty = new DomRegion();
37
return BeginLine <= 0;
41
public string FileName {
42
get { return fileName; }
45
public int BeginLine {
52
/// if the end line is == -1 the end column is -1 too
53
/// this stands for an unknwon end
61
public int BeginColumn {
68
/// if the end column is == -1 the end line is -1 too
69
/// this stands for an unknown end
71
public int EndColumn {
77
public TextLocation Begin {
79
return new TextLocation (beginLine, beginColumn);
83
public TextLocation End {
85
return new TextLocation (endLine, endColumn);
89
public DomRegion (int beginLine, int beginColumn, int endLine, int endColumn) : this (null, beginLine, beginColumn, endLine, endColumn)
93
public DomRegion(string fileName, int beginLine, int beginColumn, int endLine, int endColumn)
95
this.fileName = fileName;
96
this.beginLine = beginLine;
97
this.beginColumn = beginColumn;
98
this.endLine = endLine;
99
this.endColumn = endColumn;
102
public DomRegion (int beginLine, int beginColumn) : this (null, beginLine, beginColumn)
106
public DomRegion (string fileName, int beginLine, int beginColumn)
108
this.fileName = fileName;
109
this.beginLine = beginLine;
110
this.beginColumn = beginColumn;
115
public DomRegion (TextLocation begin, TextLocation end) : this (null, begin, end)
119
public DomRegion (string fileName, TextLocation begin, TextLocation end)
121
this.fileName = fileName;
122
this.beginLine = begin.Line;
123
this.beginColumn = begin.Column;
124
this.endLine = end.Line;
125
this.endColumn = end.Column;
128
public DomRegion (TextLocation begin) : this (null, begin)
132
public DomRegion (string fileName, TextLocation begin)
134
this.fileName = fileName;
135
this.beginLine = begin.Line;
136
this.beginColumn = begin.Column;
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
145
public bool IsInside(int line, int column)
149
return line >= BeginLine &&
150
(line <= EndLine || EndLine == -1) &&
151
(line != BeginLine || column >= BeginColumn) &&
152
(line != EndLine || column <= EndColumn);
155
public bool IsInside(TextLocation location)
157
return IsInside(location.Line, location.Column);
160
public override string ToString()
162
return string.Format(
163
CultureInfo.InvariantCulture,
164
"[DomRegion FileName={0}, Begin=({1}, {2}), End=({3}, {4})]",
165
fileName, beginLine, beginColumn, endLine, endColumn);
168
public override bool Equals(object obj)
170
return obj is DomRegion && Equals((DomRegion)obj);
173
public override int GetHashCode()
176
int hashCode = fileName != null ? fileName.GetHashCode() : 0;
177
hashCode ^= beginColumn + 1100009 * beginLine + 1200007 * endLine + 1300021 * endColumn;
182
public bool Equals(DomRegion other)
184
return beginLine == other.beginLine && beginColumn == other.beginColumn
185
&& endLine == other.endLine && endColumn == other.endColumn
186
&& fileName == other.fileName;
189
public static bool operator ==(DomRegion left, DomRegion right)
191
return left.Equals(right);
194
public static bool operator !=(DomRegion left, DomRegion right)
196
return !left.Equals(right);