annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java @ 9775:5dc05fdcf3c2

Fix SourceSection.getCode.
author Chris Seaton <chris.seaton@oracle.com>
date Mon, 20 May 2013 23:22:36 -0700
parents c485a44097b3
children e210293dca77
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
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
126 }