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

« back to all changes in this revision

Viewing changes to contrib/NRefactory/Project/Src/Location.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
 
// <file>
2
 
//     <copyright see="prj:///doc/copyright.txt"/>
3
 
//     <license see="prj:///doc/license.txt"/>
4
 
//     <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
5
 
//     <version>$Revision: 4482 $</version>
6
 
// </file>
7
 
 
8
 
using System;
9
 
 
10
 
namespace ICSharpCode.OldNRefactory
11
 
{
12
 
        /// <summary>
13
 
        /// A line/column position.
14
 
        /// NRefactory lines/columns are counting from one.
15
 
        /// </summary>
16
 
        public struct Location : IComparable<Location>, IEquatable<Location>
17
 
        {
18
 
                public static readonly Location Empty = new Location(-1, -1);
19
 
                
20
 
                public Location(int column, int line)
21
 
                {
22
 
                        x = column;
23
 
                        y = line;
24
 
                }
25
 
                
26
 
                int x, y;
27
 
                
28
 
                public int X {
29
 
                        get { return x; }
30
 
                        set { x = value; }
31
 
                }
32
 
                
33
 
                public int Y {
34
 
                        get { return y; }
35
 
                        set { y = value; }
36
 
                }
37
 
                
38
 
                public int Line {
39
 
                        get { return y; }
40
 
                        set { y = value; }
41
 
                }
42
 
                
43
 
                public int Column {
44
 
                        get { return x; }
45
 
                        set { x = value; }
46
 
                }
47
 
                
48
 
                public bool IsEmpty {
49
 
                        get {
50
 
                                return x <= 0 && y <= 0;
51
 
                        }
52
 
                }
53
 
                
54
 
                public override string ToString()
55
 
                {
56
 
                        return string.Format("(Line {1}, Col {0})", this.x, this.y);
57
 
                }
58
 
                
59
 
                public override int GetHashCode()
60
 
                {
61
 
                        return unchecked (87 * x.GetHashCode() ^ y.GetHashCode());
62
 
                }
63
 
                
64
 
                public override bool Equals(object obj)
65
 
                {
66
 
                        if (!(obj is Location)) return false;
67
 
                        return (Location)obj == this;
68
 
                }
69
 
                
70
 
                public bool Equals(Location other)
71
 
                {
72
 
                        return this == other;
73
 
                }
74
 
                
75
 
                public static bool operator ==(Location a, Location b)
76
 
                {
77
 
                        return a.x == b.x && a.y == b.y;
78
 
                }
79
 
                
80
 
                public static bool operator !=(Location a, Location b)
81
 
                {
82
 
                        return a.x != b.x || a.y != b.y;
83
 
                }
84
 
                
85
 
                public static bool operator <(Location a, Location b)
86
 
                {
87
 
                        if (a.y < b.y)
88
 
                                return true;
89
 
                        else if (a.y == b.y)
90
 
                                return a.x < b.x;
91
 
                        else
92
 
                                return false;
93
 
                }
94
 
                
95
 
                public static bool operator >(Location a, Location b)
96
 
                {
97
 
                        if (a.y > b.y)
98
 
                                return true;
99
 
                        else if (a.y == b.y)
100
 
                                return a.x > b.x;
101
 
                        else
102
 
                                return false;
103
 
                }
104
 
                
105
 
                public static bool operator <=(Location a, Location b)
106
 
                {
107
 
                        return !(a > b);
108
 
                }
109
 
                
110
 
                public static bool operator >=(Location a, Location b)
111
 
                {
112
 
                        return !(a < b);
113
 
                }
114
 
                
115
 
                public int CompareTo(Location other)
116
 
                {
117
 
                        if (this == other)
118
 
                                return 0;
119
 
                        if (this < other)
120
 
                                return -1;
121
 
                        else
122
 
                                return 1;
123
 
                }
124
 
        }
125
 
}