# HG changeset patch # User Thomas Wuerthinger # Date 1366828506 -7200 # Node ID 5054a206fcf0af328a246b7ea49203e640c93002 # Parent 159ac409c27a203a9ced9576e9bae35d63880242 Remove endLine and endIndex from SourceSection class and add charIndex and charLength instead. Also add getCode() method. diff -r 159ac409c27a -r 5054a206fcf0 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java Wed Apr 24 18:53:06 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java Wed Apr 24 20:35:06 2013 +0200 @@ -31,26 +31,26 @@ private final String identifier; private final int startLine; private final int startColumn; - private final int endLine; - private final int endColumn; + private final int charIndex; + private final int charLength; /** * Creates a new object representing a section in the source code of a guest language program. * * @param source object representing the source program this is should be a section of * @param identifier an identifier used when printing the section - * @param startLine the index of the start line of the section (inclusive) - * @param startColumn the index of the start column of the section (inclusive) - * @param endLine the index of the end line of the section (inclusive) - * @param endColumn the index of the end column of the section (inclusive) + * @param startLine the index of the start line of the section + * @param startColumn the index of the start column of the section + * @param charIndex the index of the first character of the section + * @param charLength the length of the section in number of characters */ - public SourceSection(Source source, String identifier, int startLine, int startColumn, int endLine, int endColumn) { + public SourceSection(Source source, String identifier, int startLine, int startColumn, int charIndex, int charLength) { this.source = source; this.identifier = identifier; this.startLine = startLine; this.startColumn = startColumn; - this.endLine = endLine; - this.endColumn = endColumn; + this.charIndex = charIndex; + this.charLength = charLength; } /** @@ -81,21 +81,23 @@ } /** - * Returns the index of the end line of this source section (inclusive). + * Returns the index of the first character of this section. All characters of the source can be + * retrieved via the {@link Source#getCode()} method. * - * @return the end line + * @return the character index */ - public final int getEndLine() { - return endLine; + public final int getCharIndex() { + return charIndex; } /** - * Returns the index of the end column of this source section (inclusive). + * Returns the length of this section in characters. All characters of the source can be + * retrieved via the {@link Source#getCode()} method. * - * @return the end column + * @return the character length */ - public final int getEndColumn() { - return endColumn; + public final int getCharLength() { + return charLength; } /** @@ -106,4 +108,13 @@ public final String getIdentifier() { return identifier; } + + /** + * Returns the code represented by this code section. + * + * @return the code as a String object + */ + public final String getCode() { + return getSource().getCode().substring(charIndex, charLength); + } }