changeset 20906:c8b83aa6cc82

Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Mon, 13 Apr 2015 10:55:15 -0700
parents ca13a009e38b
children 06b0a2fb20a1
files graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceTest.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceTag.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/StandardSourceTag.java
diffstat 4 files changed, 65 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceTest.java	Sun Apr 12 22:37:16 2015 -0700
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceTest.java	Mon Apr 13 10:55:15 2015 -0700
@@ -54,9 +54,9 @@
         // Initially has only the default tag
         assertEquals(source.getSourceTags().size(), 1);
 
-        assertTrue(source.getSourceTags().contains(StandardSourceTag.FROM_LITERAL));
-        assertTrue(source.isTaggedAs(StandardSourceTag.FROM_LITERAL));
-        assertTrue(Source.findSourcesTaggedAs(StandardSourceTag.FROM_LITERAL).contains(source));
+        assertTrue(source.getSourceTags().contains(Source.Tags.FROM_LITERAL));
+        assertTrue(source.isTaggedAs(Source.Tags.FROM_LITERAL));
+        assertTrue(Source.findSourcesTaggedAs(Source.Tags.FROM_LITERAL).contains(source));
 
         assertFalse(source.isTaggedAs(testTag));
         assertEquals(Source.findSourcesTaggedAs(testTag).size(), 0);
@@ -67,9 +67,9 @@
         // Now there are exactly two tags
         assertEquals(source.getSourceTags().size(), 2);
 
-        assertTrue(source.getSourceTags().contains(StandardSourceTag.FROM_LITERAL));
-        assertTrue(source.isTaggedAs(StandardSourceTag.FROM_LITERAL));
-        assertTrue(Source.findSourcesTaggedAs(StandardSourceTag.FROM_LITERAL).contains(source));
+        assertTrue(source.getSourceTags().contains(Source.Tags.FROM_LITERAL));
+        assertTrue(source.isTaggedAs(Source.Tags.FROM_LITERAL));
+        assertTrue(Source.findSourcesTaggedAs(Source.Tags.FROM_LITERAL).contains(source));
 
         assertTrue(source.getSourceTags().contains(testTag));
         assertTrue(source.isTaggedAs(testTag));
@@ -82,9 +82,9 @@
         // Nothing has changed
         assertEquals(source.getSourceTags().size(), 2);
 
-        assertTrue(source.getSourceTags().contains(StandardSourceTag.FROM_LITERAL));
-        assertTrue(source.isTaggedAs(StandardSourceTag.FROM_LITERAL));
-        assertTrue(Source.findSourcesTaggedAs(StandardSourceTag.FROM_LITERAL).contains(source));
+        assertTrue(source.getSourceTags().contains(Source.Tags.FROM_LITERAL));
+        assertTrue(source.isTaggedAs(Source.Tags.FROM_LITERAL));
+        assertTrue(Source.findSourcesTaggedAs(Source.Tags.FROM_LITERAL).contains(source));
 
         assertTrue(source.getSourceTags().contains(testTag));
         assertTrue(source.isTaggedAs(testTag));
@@ -135,7 +135,7 @@
         assertEquals(newSource[0], source);
         assertEquals(newTagEvents[0], 1);
         assertEquals(taggedSource[0], source);
-        assertEquals(newTag[0], StandardSourceTag.FROM_LITERAL);
+        assertEquals(newTag[0], Source.Tags.FROM_LITERAL);
 
         // reset
         newSource[0] = null;
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java	Sun Apr 12 22:37:16 2015 -0700
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java	Mon Apr 13 10:55:15 2015 -0700
@@ -78,6 +78,51 @@
     // TODO (mlvdv) consider canonicalizing and reusing SourceSection instances
     // TOOD (mlvdv) connect SourceSections into a spatial tree for fast geometric lookup
 
+    public enum Tags implements SourceTag {
+
+        /**
+         * From bytes.
+         */
+        FROM_BYTES("bytes", "read from bytes"),
+
+        /**
+         * Read from a file.
+         */
+        FROM_FILE("file", "read from a file"),
+
+        /**
+         * From literal text.
+         */
+        FROM_LITERAL("literal", "from literal text"),
+
+        /**
+         * From a {@linkplain java.io.Reader Reader}.
+         */
+        FROM_READER("reader", "read from a Java Reader"),
+
+        /**
+         * Read from a URL.
+         */
+        FROM_URL("URL", "read from a URL");
+
+        private final String name;
+        private final String description;
+
+        private Tags(String name, String description) {
+            this.name = name;
+            this.description = description;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getDescription() {
+            return description;
+        }
+
+    }
+
     /**
      * All Sources that have been created.
      */
@@ -119,7 +164,7 @@
         if (reset) {
             source.reset();
         }
-        notifyNewSource(source).tagAs(StandardSourceTag.FROM_FILE);
+        notifyNewSource(source).tagAs(Tags.FROM_FILE);
         return source;
     }
 
@@ -161,7 +206,7 @@
                 filePathToSource.put(path, new WeakReference<>(source));
             }
         }
-        notifyNewSource(source).tagAs(StandardSourceTag.FROM_FILE);
+        notifyNewSource(source).tagAs(Tags.FROM_FILE);
         return source;
     }
 
@@ -176,7 +221,7 @@
     public static Source fromText(CharSequence chars, String description) {
         assert chars != null;
         final LiteralSource source = new LiteralSource(description, chars.toString());
-        notifyNewSource(source).tagAs(StandardSourceTag.FROM_LITERAL);
+        notifyNewSource(source).tagAs(Tags.FROM_LITERAL);
         return source;
     }
 
@@ -190,7 +235,7 @@
      */
     public static Source fromURL(URL url, String description) throws IOException {
         final URLSource source = URLSource.get(url, description);
-        notifyNewSource(source).tagAs(StandardSourceTag.FROM_URL);
+        notifyNewSource(source).tagAs(Tags.FROM_URL);
         return source;
     }
 
@@ -204,7 +249,7 @@
      */
     public static Source fromReader(Reader reader, String description) throws IOException {
         final LiteralSource source = new LiteralSource(description, read(reader));
-        notifyNewSource(source).tagAs(StandardSourceTag.FROM_READER);
+        notifyNewSource(source).tagAs(Tags.FROM_READER);
         return source;
     }
 
@@ -237,7 +282,7 @@
      */
     public static Source fromBytes(byte[] bytes, int byteIndex, int length, String description, BytesDecoder decoder) {
         final BytesSource source = new BytesSource(description, bytes, byteIndex, length, decoder);
-        notifyNewSource(source).tagAs(StandardSourceTag.FROM_BYTES);
+        notifyNewSource(source).tagAs(Tags.FROM_BYTES);
         return source;
     }
 
@@ -252,7 +297,7 @@
     public static Source asPseudoFile(CharSequence chars, String pseudoFileName) {
         final Source source = new LiteralSource(pseudoFileName, chars.toString());
         filePathToSource.put(pseudoFileName, new WeakReference<>(source));
-        notifyNewSource(source).tagAs(StandardSourceTag.FROM_LITERAL);
+        notifyNewSource(source).tagAs(Tags.FROM_LITERAL);
         return source;
     }
 
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceTag.java	Sun Apr 12 22:37:16 2015 -0700
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceTag.java	Mon Apr 13 10:55:15 2015 -0700
@@ -27,16 +27,14 @@
 /**
  * Categorical information (best implemented as enums} about particular sources of Guest Language
  * code that can be useful to configure behavior of both the language runtime and external tools.
- * These might include {@linkplain StandardSourceTag standard tags} noting, for example, whether the
- * source was read from a file and whether it should be considered library code.
- * <p>
- * An untagged {@link Source} should by default be considered application code.
+ * These might include {@linkplain Source.Tags standard tags} noting, for example,
+ * whether the source was read from a file and whether it should be considered library code.
  * <p>
  * The need for additional tags is likely to arise, in some cases because of issue specific to a
  * Guest Language, but also for help configuring the behavior of particular tools.
  *
  * @see Source
- * @see StandardSourceTag
+ * @see Source.Tags
  */
 public interface SourceTag {
 
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/StandardSourceTag.java	Sun Apr 12 22:37:16 2015 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.api.source;
-
-/**
- * A general set of "properties" or "categories" that might be usefully attached to a particular
- * source of code, both for use by the language runtime and by external tools. This set of tags
- * includes some intended to be applied by default by {@link Source} factory methods or other
- * services built into the Truffle platform.
- * <p>
- * The need for additional tags is likely to arise, in some cases because of issue specific to a
- * Guest Language, but also for help configuring the behavior of particular tools.
- *
- * @see Source
- */
-public enum StandardSourceTag implements SourceTag {
-
-    /**
-     * Builtin.
-     */
-    BUILTIN("builtin", "implementation of language builtins"),
-
-    /**
-     * From bytes.
-     */
-    FROM_BYTES("bytes", "read from bytes"),
-
-    /**
-     * Read from a file.
-     */
-    FROM_FILE("file", "read from a file"),
-
-    /**
-     * From literal text.
-     */
-    FROM_LITERAL("literal", "from literal text"),
-
-    /**
-     * From a {@linkplain java.io.Reader Reader}.
-     */
-    FROM_READER("reader", "read from a Java Reader"),
-
-    /**
-     * Read from a URL.
-     */
-    FROM_URL("URL", "read from a URL"),
-
-    /**
-     * Treat as LIBRARY code.
-     */
-    LIBRARY("library", "library code");
-
-    private final String name;
-    private final String description;
-
-    private StandardSourceTag(String name, String description) {
-        this.name = name;
-        this.description = description;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public String getDescription() {
-        return description;
-    }
-
-}