annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java @ 10085:9d15ca2f38d1

fix == on Register value
author Mick Jordan <mick.jordan@oracle.com>
date Tue, 18 Jun 2013 14:17:45 -0700
parents b9b8af46c2b7
children 494b818b527c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.truffle.api;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 /**
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
26 * Represents a contiguous text section within the source code of a guest language program.
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 */
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 public class SourceSection {
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 private final Source source;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 private final String identifier;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 private final int startLine;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 private final int startColumn;
9284
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
34 private final int charIndex;
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
35 private final int charLength;
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 /**
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
38 * Creates a new object representing a contiguous text section within the source code of a guest
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
39 * language program.
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
40 * <p>
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
41 * The starting location of the section is specified using two different coordinate:
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
42 * <ul>
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
43 * <li><b>(row, column)</b>: rows and columns are 1-based, so the first character in a source
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
44 * file is at position {@code (1,1)}.</li>
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
45 * <li><b>character index</b>: 0-based offset of the character from the beginning of the source,
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
46 * so the first character in a file is at index {@code 0}.</li>
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
47 * </ul>
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
48 * The <b>newline</b> that terminates each line counts as a single character for the purpose of
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
49 * a character index. The (row,column) coordinates of a newline character should never appear in
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
50 * a text section.
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
51 * <p>
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 *
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
53 * @param source object representing the complete source program that contains this section
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 * @param identifier an identifier used when printing the section
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
55 * @param startLine the 1-based number of the start line of the section
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
56 * @param startColumn the 1-based number of the start column of the section
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
57 * @param charIndex the 0-based index of the first character of the section
9284
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
58 * @param charLength the length of the section in number of characters
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 */
9284
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
60 public SourceSection(Source source, String identifier, int startLine, int startColumn, int charIndex, int charLength) {
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 this.source = source;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 this.identifier = identifier;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 this.startLine = startLine;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 this.startColumn = startColumn;
9284
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
65 this.charIndex = charIndex;
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
66 this.charLength = charLength;
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 /**
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
70 * Returns the object representing the source program that contains this section.
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 *
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 * @return the source object
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 */
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 public final Source getSource() {
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 return source;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 /**
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
79 * Returns 1-based line number of the first character in this source section (inclusive).
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 *
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
81 * @return the starting line number
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 */
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 public final int getStartLine() {
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84 return startLine;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 /**
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
88 * Returns the 1-based column number of the first character in this source section (inclusive).
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 *
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
90 * @return the starting column number
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 */
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92 public final int getStartColumn() {
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 return startColumn;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 /**
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
97 * Returns the 0-based index of the first character in this source section.
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
98 * <p>
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
99 * The complete text of the source that contains this section can be retrieved via
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
100 * {@link Source#getCode()}.
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 *
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
102 * @return the starting character index
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 */
9284
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
104 public final int getCharIndex() {
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
105 return charIndex;
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 /**
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
109 * Returns the length of this source section in characters.
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
110 * <p>
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
111 * The complete text of the source that contains this section can be retrieved via
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
112 * {@link Source#getCode()}.
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113 *
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
114 * @return the number of characters in the section
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 */
9284
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
116 public final int getCharLength() {
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
117 return charLength;
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 /**
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121 * Returns the identifier of this source section that is used for printing the section.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122 *
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123 * @return the identifier of the section
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 */
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
125 public final String getIdentifier() {
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 return identifier;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 }
9284
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
128
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
129 /**
9989
b9b8af46c2b7 Upgrade the documentation for SourceSection, especially with respect to the specification of text locations.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 9822
diff changeset
130 * Returns text of the code represented by this source section.
9284
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
131 *
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
132 * @return the code as a String object
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
133 */
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
134 public final String getCode() {
9775
5dc05fdcf3c2 Fix SourceSection.getCode.
Chris Seaton <chris.seaton@oracle.com>
parents: 9333
diff changeset
135 return getSource().getCode().substring(charIndex, charIndex + charLength);
9284
5054a206fcf0 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
136 }
9333
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
137
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
138 @Override
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
139 public String toString() {
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
140 return String.format("%s:%d", source.getName(), startLine);
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
141 }
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
142
9822
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
143 @Override
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
144 public int hashCode() {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
145 final int prime = 31;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
146 int result = 1;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
147 result = prime * result + charIndex;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
148 result = prime * result + charLength;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
149 result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
150 result = prime * result + ((source == null) ? 0 : source.hashCode());
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
151 result = prime * result + startColumn;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
152 result = prime * result + startLine;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
153 return result;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
154 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
155
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
156 @Override
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
157 public boolean equals(Object obj) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
158 if (this == obj) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
159 return true;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
160 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
161 if (obj == null) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
162 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
163 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
164 if (!(obj instanceof SourceSection)) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
165 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
166 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
167 SourceSection other = (SourceSection) obj;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
168 if (charIndex != other.charIndex) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
169 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
170 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
171 if (charLength != other.charLength) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
172 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
173 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
174 if (identifier == null) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
175 if (other.identifier != null) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
176 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
177 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
178 } else if (!identifier.equals(other.identifier)) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
179 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
180 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
181 if (source == null) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
182 if (other.source != null) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
183 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
184 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
185 } else if (!source.equals(other.source)) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
186 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
187 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
188 if (startColumn != other.startColumn) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
189 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
190 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
191 if (startLine != other.startLine) {
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
192 return false;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
193 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
194 return true;
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
195 }
e210293dca77 Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
Chris Seaton <chris.seaton@oracle.com>
parents: 9775
diff changeset
196
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 }