Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java @ 9284:5054a206fcf0
Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Wed, 24 Apr 2013 20:35:06 +0200 |
parents | 4497235516df |
children | c485a44097b3 |
comparison
equal
deleted
inserted
replaced
9283:159ac409c27a | 9284:5054a206fcf0 |
---|---|
29 | 29 |
30 private final Source source; | 30 private final Source source; |
31 private final String identifier; | 31 private final String identifier; |
32 private final int startLine; | 32 private final int startLine; |
33 private final int startColumn; | 33 private final int startColumn; |
34 private final int endLine; | 34 private final int charIndex; |
35 private final int endColumn; | 35 private final int charLength; |
36 | 36 |
37 /** | 37 /** |
38 * Creates a new object representing a section in the source code of a guest language program. | 38 * Creates a new object representing a section in the source code of a guest language program. |
39 * | 39 * |
40 * @param source object representing the source program this is should be a section of | 40 * @param source object representing the source program this is should be a section of |
41 * @param identifier an identifier used when printing the section | 41 * @param identifier an identifier used when printing the section |
42 * @param startLine the index of the start line of the section (inclusive) | 42 * @param startLine the index of the start line of the section |
43 * @param startColumn the index of the start column of the section (inclusive) | 43 * @param startColumn the index of the start column of the section |
44 * @param endLine the index of the end line of the section (inclusive) | 44 * @param charIndex the index of the first character of the section |
45 * @param endColumn the index of the end column of the section (inclusive) | 45 * @param charLength the length of the section in number of characters |
46 */ | 46 */ |
47 public SourceSection(Source source, String identifier, int startLine, int startColumn, int endLine, int endColumn) { | 47 public SourceSection(Source source, String identifier, int startLine, int startColumn, int charIndex, int charLength) { |
48 this.source = source; | 48 this.source = source; |
49 this.identifier = identifier; | 49 this.identifier = identifier; |
50 this.startLine = startLine; | 50 this.startLine = startLine; |
51 this.startColumn = startColumn; | 51 this.startColumn = startColumn; |
52 this.endLine = endLine; | 52 this.charIndex = charIndex; |
53 this.endColumn = endColumn; | 53 this.charLength = charLength; |
54 } | 54 } |
55 | 55 |
56 /** | 56 /** |
57 * Returns the source object representing the source program this is a section of. | 57 * Returns the source object representing the source program this is a section of. |
58 * | 58 * |
79 public final int getStartColumn() { | 79 public final int getStartColumn() { |
80 return startColumn; | 80 return startColumn; |
81 } | 81 } |
82 | 82 |
83 /** | 83 /** |
84 * Returns the index of the end line of this source section (inclusive). | 84 * Returns the index of the first character of this section. All characters of the source can be |
85 * retrieved via the {@link Source#getCode()} method. | |
85 * | 86 * |
86 * @return the end line | 87 * @return the character index |
87 */ | 88 */ |
88 public final int getEndLine() { | 89 public final int getCharIndex() { |
89 return endLine; | 90 return charIndex; |
90 } | 91 } |
91 | 92 |
92 /** | 93 /** |
93 * Returns the index of the end column of this source section (inclusive). | 94 * Returns the length of this section in characters. All characters of the source can be |
95 * retrieved via the {@link Source#getCode()} method. | |
94 * | 96 * |
95 * @return the end column | 97 * @return the character length |
96 */ | 98 */ |
97 public final int getEndColumn() { | 99 public final int getCharLength() { |
98 return endColumn; | 100 return charLength; |
99 } | 101 } |
100 | 102 |
101 /** | 103 /** |
102 * Returns the identifier of this source section that is used for printing the section. | 104 * Returns the identifier of this source section that is used for printing the section. |
103 * | 105 * |
104 * @return the identifier of the section | 106 * @return the identifier of the section |
105 */ | 107 */ |
106 public final String getIdentifier() { | 108 public final String getIdentifier() { |
107 return identifier; | 109 return identifier; |
108 } | 110 } |
111 | |
112 /** | |
113 * Returns the code represented by this code section. | |
114 * | |
115 * @return the code as a String object | |
116 */ | |
117 public final String getCode() { | |
118 return getSource().getCode().substring(charIndex, charLength); | |
119 } | |
109 } | 120 } |