Debian Codegraph @

src/com/google/javascript/rhino/SourcePosition.java

raw symbols SCIP
1 /*
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is Rhino code, released
17 * May 6, 1999.
18 *
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1997-1999
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s):
25 * Bob Jervis
26 * Google Inc.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU General Public License Version 2 or later (the "GPL"), in which
30 * case the provisions of the GPL are applicable instead of those above. If
31 * you wish to allow use of your version of this file only under the terms of
32 * the GPL and not to allow others to use your version of this file under the
33 * MPL, indicate your decision by deleting the provisions above and replacing
34 * them with the notice and other provisions required by the GPL. If you do
35 * not delete the provisions above, a recipient may use your version of this
36 * file under either the MPL or the GPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 package com.google.javascript.rhino;
41
42 /**
43 * Represents a position in some piece of source code, with an associated
44 * item of type T found at that position.
45 *
46 */
47 public abstract class SourcePosition<T> {
48 /**
49 * The (well typed) item found at the source position.
50 */
51 private T item = null;
52
53 /**
54 * The starting line number.
55 */
56 private int startLineno = 0;
57
58 /**
59 * The character position on the starting line.
60 */
61 private int startCharno = 0;
62
63 /**
64 * The ending line number.
65 */
66 private int endLineno = 0;
67
68 /**
69 * The character position on the ending line.
70 */
71 private int endCharno = 0;
72
73 /**
74 * Sets the item that this source position references.
75 */
76 public void setItem(T item) {
77 this.item = item;
78 }
79
80 /**
81 * Sets the position information contained in this source position.
82 */
83 public void setPositionInformation(int startLineno, int startCharno,
84 int endLineno, int endCharno) {
85 if (startLineno == endLineno) {
86 if (startCharno >= endCharno) {
87 throw new IllegalStateException(
88 "Recorded bad position information\n" +
89 "start-char: " + startCharno + "\n" +
90 "end-char: " + endCharno);
91 }
92 } else {
93 if (startLineno > endLineno) {
94 throw new IllegalStateException(
95 "Recorded bad position information\n" +
96 "start-line: " + startLineno + "\n" +
97 "end-line: " + endLineno);
98 }
99 }
100
101 this.startLineno = startLineno;
102 this.startCharno = startCharno;
103 this.endLineno = endLineno;
104 this.endCharno = endCharno;
105 }
106
107 /**
108 * Returns the item found at this source position.
109 */
110 public T getItem() {
111 return item;
112 }
113
114 /**
115 * Returns the starting line number of this position.
116 */
117 public int getStartLine() {
118 return startLineno;
119 }
120
121 /**
122 * Returns the character position on the starting line.
123 */
124 public int getPositionOnStartLine() {
125 return startCharno;
126 }
127
128 /**
129 * Returns the ending line number of this position.
130 */
131 public int getEndLine() {
132 return endLineno;
133 }
134
135 /**
136 * Returns the character position on the ending line.
137 */
138 public int getPositionOnEndLine() {
139 return endCharno;
140 }
141 }