changeset 15371:c54f5fa05fd5

Truffle: add getShortName and getShortDescription to Source and SourceSection for when we don't need full paths.
author Chris Seaton <chris.seaton@oracle.com>
date Thu, 24 Apr 2014 23:29:04 +0100
parents 0aed1c2d0caa
children 2cea065e419d
files graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Source.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultSourceSection.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceManager.java
diffstat 4 files changed, 54 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Source.java	Thu Apr 24 17:31:25 2014 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Source.java	Thu Apr 24 23:29:04 2014 +0100
@@ -34,12 +34,21 @@
     /**
      * Returns the name of this resource holding a guest language program. An example would be the
      * name of a guest language source code file.
-     * 
+     *
      * @return the name of the guest language program
      */
     String getName();
 
     /**
+     * Returns a short version of the name of the resource holding a guest language program (as
+     * described in @getName). For example, this could be just the name of the file, rather than a
+     * full path.
+     *
+     * @return the short name of the guest language program
+     */
+    String getShortName();
+
+    /**
      * The normalized, canonical name of the file.
      */
     String getPath();
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java	Thu Apr 24 17:31:25 2014 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java	Thu Apr 24 23:29:04 2014 +0100
@@ -31,21 +31,21 @@
 
     /**
      * Returns the object representing the source program that contains this section.
-     * 
+     *
      * @return the source object
      */
     Source getSource();
 
     /**
      * Returns 1-based line number of the first character in this source section (inclusive).
-     * 
+     *
      * @return the starting line number
      */
     int getStartLine();
 
     /**
      * Returns the 1-based column number of the first character in this source section (inclusive).
-     * 
+     *
      * @return the starting column number
      */
     int getStartColumn();
@@ -55,7 +55,7 @@
      * <p>
      * The complete text of the source that contains this section can be retrieved via
      * {@link Source#getCode()}.
-     * 
+     *
      * @return the starting character index
      */
     int getCharIndex();
@@ -65,7 +65,7 @@
      * <p>
      * The complete text of the source that contains this section can be retrieved via
      * {@link Source#getCode()}.
-     * 
+     *
      * @return the number of characters in the section
      */
     int getCharLength();
@@ -73,42 +73,54 @@
     /**
      * Returns the index of the text position immediately following the last character in the
      * section.
-     * 
+     *
      * @return the end position of the section
      */
     int getCharEndIndex();
 
     /**
      * Returns the identifier of this source section that is used for printing the section.
-     * 
+     *
      * @return the identifier of the section
      */
     String getIdentifier();
 
     /**
      * Returns text of the code represented by this source section.
-     * 
+     *
      * @return the code as a String object
      */
     String getCode();
 
     /**
+     * Returns a short description of the source section, using just the file name, rather than its
+     * full path.
+     *
+     * @return a short description of the source section
+     */
+    String getShortDescription();
+
+    /**
      * Singleton instance with no content.
      */
     SourceSection NULL = new NullSourceSection() {
 
+        @Override
         public Source getSource() {
             return null;
         }
 
+        @Override
         public int getStartLine() {
             return 0;
         }
 
+        @Override
         public int getStartColumn() {
             return 0;
         }
 
+        @Override
         public int getCharIndex() {
             return 0;
         }
@@ -118,18 +130,26 @@
             return 0;
         }
 
+        @Override
         public int getCharEndIndex() {
             return 0;
         }
 
+        @Override
         public String getIdentifier() {
             return null;
         }
 
+        @Override
         public String getCode() {
             return null;
         }
 
+        @Override
+        public String getShortDescription() {
+            return "short";
+        }
+
     };
 
 }
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultSourceSection.java	Thu Apr 24 17:31:25 2014 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultSourceSection.java	Thu Apr 24 23:29:04 2014 +0100
@@ -53,7 +53,7 @@
      * a character index. The (row,column) coordinates of a newline character should never appear in
      * a text section.
      * <p>
-     * 
+     *
      * @param source object representing the complete source program that contains this section
      * @param identifier an identifier used when printing the section
      * @param startLine the 1-based number of the start line of the section
@@ -102,6 +102,10 @@
         return getSource().getCode().substring(charIndex, charIndex + charLength);
     }
 
+    public final String getShortDescription() {
+        return String.format("%s:%d", source.getShortName(), startLine);
+    }
+
     @Override
     public String toString() {
         return String.format("%s:%d", source.getName(), startLine);
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceManager.java	Thu Apr 24 17:31:25 2014 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceManager.java	Thu Apr 24 23:29:04 2014 +0100
@@ -70,7 +70,7 @@
     /**
      * Gets the canonical representation of a source file, whose contents will be read lazily and
      * then cached.
-     * 
+     *
      * @param reset forces any existing {@link Source} cache to be cleared, forcing a re-read
      */
     public Source get(String fileName, boolean reset) {
@@ -227,6 +227,11 @@
         }
 
         @Override
+        public String getShortName() {
+            return name;
+        }
+
+        @Override
         public String getCode() {
             return code;
         }
@@ -292,6 +297,11 @@
         }
 
         @Override
+        public String getShortName() {
+            return file.getName();
+        }
+
+        @Override
         public String getCode() {
             if (code == null || timeStamp != file.lastModified()) {
                 try {