langtools/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java
changeset 3995 73af8b6fb8bc
parent 3782 ae62279eeb46
child 3998 c66be272f350
--- a/langtools/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Wed Sep 23 18:48:13 2009 -0700
@@ -34,6 +34,7 @@
 import java.nio.charset.CharsetDecoder;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.NestingKind;
+import javax.tools.FileObject;
 import javax.tools.JavaFileObject;
 
 import static javax.tools.JavaFileObject.Kind.*;
@@ -49,33 +50,15 @@
         this.fileManager = fileManager;
     }
 
-    public JavaFileObject.Kind getKind() {
-        String n = getName();
-        if (n.endsWith(CLASS.extension))
-            return CLASS;
-        else if (n.endsWith(SOURCE.extension))
-            return SOURCE;
-        else if (n.endsWith(HTML.extension))
-            return HTML;
-        else
-            return OTHER;
-    }
+    /** Return a short name for the object, such as for use in raw diagnostics
+     */
+    public abstract String getShortName();
 
     @Override
     public String toString() {
-        return getPath();
+        return getClass().getSimpleName() + "[" + getName() + "]";
     }
 
-    /** @deprecated see bug 6410637 */
-    @Deprecated
-    public String getPath() {
-        return getName();
-    }
-
-    /** @deprecated see bug 6410637 */
-    @Deprecated
-    abstract public String getName();
-
     public NestingKind getNestingKind() { return null; }
 
     public Modifier getAccessLevel()  { return null; }
@@ -90,6 +73,17 @@
 
     protected abstract String inferBinaryName(Iterable<? extends File> path);
 
+    protected static JavaFileObject.Kind getKind(String filename) {
+        if (filename.endsWith(CLASS.extension))
+            return CLASS;
+        else if (filename.endsWith(SOURCE.extension))
+            return SOURCE;
+        else if (filename.endsWith(HTML.extension))
+            return HTML;
+        else
+            return OTHER;
+    }
+
     protected static String removeExtension(String fileName) {
         int lastDot = fileName.lastIndexOf(".");
         return (lastDot == -1 ? fileName : fileName.substring(0, lastDot));
@@ -115,6 +109,17 @@
         }
     }
 
+    /** Return the last component of a presumed hierarchical URI.
+     *  From the scheme specific part of the URI, it returns the substring
+     *  after the last "/" if any, or everything if no "/" is found.
+     */
+    public static String getSimpleName(FileObject fo) {
+        URI uri = fo.toUri();
+        String s = uri.getSchemeSpecificPart();
+        return s.substring(s.lastIndexOf("/") + 1); // safe when / not found
+
+    }
+
     /** The file manager that created this JavaFileObject. */
     protected final JavacFileManager fileManager;
 }