annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java @ 9822:e210293dca77

Generated hashCode and equals for SourceSection. Source is abstract, so just uses identity methods for that.
author Chris Seaton <chris.seaton@oracle.com>
date Sat, 25 May 2013 16:31:05 -0700
parents 5dc05fdcf3c2
children b9b8af46c2b7
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 /**
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
26 * Represents a section in the source code of a guest language program.
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 /**
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
38 * Creates a new object representing a section in the source code of a guest language program.
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
39 *
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
40 * @param source object representing the source program this is should be a section of
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
41 * @param identifier an identifier used when printing 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
42 * @param startLine the index of the start line of the section
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
43 * @param startColumn the index of the start column of the section
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
44 * @param charIndex the index of the first character of the section
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
45 * @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
46 */
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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 }
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
55
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
56 /**
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
57 * Returns the source object representing the source program this is a section of.
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
58 *
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 * @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
60 */
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 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
62 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
63 }
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
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
65 /**
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
66 * Returns the index of the start line of this source section (inclusive).
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 * @return the start line
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 */
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
70 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
71 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
72 }
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 /**
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 * Returns the index of the start column of this source section (inclusive).
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 * @return the start column
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 */
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
79 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
80 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
81 }
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 /**
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
84 * Returns the index of the first character of this section. All characters of the source can be
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
85 * retrieved via the {@link Source#getCode()} method.
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
86 *
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
87 * @return the 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
88 */
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
89 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
90 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
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
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 /**
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
94 * Returns the length of this section in characters. All characters of the source can be
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
95 * retrieved via the {@link Source#getCode()} method.
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
96 *
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
97 * @return the character length
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
98 */
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
99 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
100 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
101 }
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
102
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 /**
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
104 * 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
105 *
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 * @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
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 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
109 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
110 }
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
111
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
112 /**
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
113 * Returns the code represented by this code section.
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
114 *
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
115 * @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
116 */
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 public final String getCode() {
9775
5dc05fdcf3c2 Fix SourceSection.getCode.
Chris Seaton <chris.seaton@oracle.com>
parents: 9333
diff changeset
118 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
119 }
9333
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
120
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
121 @Override
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
122 public String toString() {
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
123 return String.format("%s:%d", source.getName(), startLine);
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
124 }
c485a44097b3 toString for SourceSection.
Chris Seaton <chris.seaton@oracle.com>
parents: 9284
diff changeset
125
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
126 @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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 }
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
138
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
139 @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
140 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
141 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
142 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
143 }
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 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
145 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
146 }
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 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
148 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
149 }
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 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
151 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
152 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
153 }
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 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
155 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
156 }
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 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
158 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
159 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
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 } 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
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 (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
165 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
166 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
167 }
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 } 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
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 (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
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 (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
175 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
176 }
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 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
178 }
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
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
180 }