changeset 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 159ac409c27a
children cadb3702cb8f
files graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java
diffstat 1 files changed, 28 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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);
+    }
 }