langtools/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java
changeset 3995 73af8b6fb8bc
parent 3782 ae62279eeb46
child 3998 c66be272f350
--- a/langtools/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Wed Sep 23 18:48:13 2009 -0700
@@ -68,98 +68,38 @@
         this.f = f;
     }
 
+    @Override
+    public URI toUri() {
+        return f.toURI().normalize();
+    }
+
+    @Override
+    public String getName() {
+        return f.getPath();
+    }
+
+    @Override
+    public String getShortName() {
+        return name;
+    }
+
+    @Override
+    public JavaFileObject.Kind getKind() {
+        return getKind(name);
+    }
+
+    @Override
     public InputStream openInputStream() throws IOException {
         return new FileInputStream(f);
     }
 
     @Override
-    protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
-        return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
-    }
-
     public OutputStream openOutputStream() throws IOException {
         ensureParentDirectoriesExist();
         return new FileOutputStream(f);
     }
 
-    public Writer openWriter() throws IOException {
-        ensureParentDirectoriesExist();
-        return new OutputStreamWriter(new FileOutputStream(f), fileManager.getEncodingName());
-    }
-
     @Override
-    protected String inferBinaryName(Iterable<? extends File> path) {
-        String fPath = f.getPath();
-        //System.err.println("RegularFileObject " + file + " " +r.getPath());
-        for (File dir: path) {
-            //System.err.println("dir: " + dir);
-            String dPath = dir.getPath();
-            if (dPath.length() == 0)
-                dPath = System.getProperty("user.dir");
-            if (!dPath.endsWith(File.separator))
-                dPath += File.separator;
-            if (fPath.regionMatches(true, 0, dPath, 0, dPath.length())
-                && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) {
-                String relativeName = fPath.substring(dPath.length());
-                return removeExtension(relativeName).replace(File.separatorChar, '.');
-            }
-        }
-        return null;
-    }
-
-    private void ensureParentDirectoriesExist() throws IOException {
-        if (!hasParents) {
-            File parent = f.getParentFile();
-            if (parent != null && !parent.exists()) {
-                if (!parent.mkdirs()) {
-                    if (!parent.exists() || !parent.isDirectory()) {
-                        throw new IOException("could not create parent directories");
-                    }
-                }
-            }
-            hasParents = true;
-        }
-    }
-
-    @Deprecated
-    public String getName() {
-        return name;
-    }
-
-    public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
-        cn.getClass();
-        // null check
-        if (kind == Kind.OTHER && getKind() != kind) {
-            return false;
-        }
-        String n = cn + kind.extension;
-        if (name.equals(n)) {
-            return true;
-        }
-        if (name.equalsIgnoreCase(n)) {
-            try {
-                // allow for Windows
-                return f.getCanonicalFile().getName().equals(n);
-            } catch (IOException e) {
-            }
-        }
-        return false;
-    }
-
-    @Deprecated
-    @Override
-    public String getPath() {
-        return f.getPath();
-    }
-
-    public long getLastModified() {
-        return f.lastModified();
-    }
-
-    public boolean delete() {
-        return f.delete();
-    }
-
     public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
         CharBuffer cb = fileManager.getCachedContent(this);
         if (cb == null) {
@@ -184,6 +124,82 @@
     }
 
     @Override
+    public Writer openWriter() throws IOException {
+        ensureParentDirectoriesExist();
+        return new OutputStreamWriter(new FileOutputStream(f), fileManager.getEncodingName());
+    }
+
+    @Override
+    public long getLastModified() {
+        return f.lastModified();
+    }
+
+    @Override
+    public boolean delete() {
+        return f.delete();
+    }
+
+    @Override
+    protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
+        return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
+    }
+
+    @Override
+    protected String inferBinaryName(Iterable<? extends File> path) {
+        String fPath = f.getPath();
+        //System.err.println("RegularFileObject " + file + " " +r.getPath());
+        for (File dir: path) {
+            //System.err.println("dir: " + dir);
+            String dPath = dir.getPath();
+            if (dPath.length() == 0)
+                dPath = System.getProperty("user.dir");
+            if (!dPath.endsWith(File.separator))
+                dPath += File.separator;
+            if (fPath.regionMatches(true, 0, dPath, 0, dPath.length())
+                && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) {
+                String relativeName = fPath.substring(dPath.length());
+                return removeExtension(relativeName).replace(File.separatorChar, '.');
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
+        cn.getClass();
+        // null check
+        if (kind == Kind.OTHER && getKind() != kind) {
+            return false;
+        }
+        String n = cn + kind.extension;
+        if (name.equals(n)) {
+            return true;
+        }
+        if (name.equalsIgnoreCase(n)) {
+            try {
+                // allow for Windows
+                return f.getCanonicalFile().getName().equals(n);
+            } catch (IOException e) {
+            }
+        }
+        return false;
+    }
+
+    private void ensureParentDirectoriesExist() throws IOException {
+        if (!hasParents) {
+            File parent = f.getParentFile();
+            if (parent != null && !parent.exists()) {
+                if (!parent.mkdirs()) {
+                    if (!parent.exists() || !parent.isDirectory()) {
+                        throw new IOException("could not create parent directories");
+                    }
+                }
+            }
+            hasParents = true;
+        }
+    }
+
+    @Override
     public boolean equals(Object other) {
         if (!(other instanceof RegularFileObject)) {
             return false;
@@ -200,8 +216,4 @@
     public int hashCode() {
         return f.hashCode();
     }
-
-    public URI toUri() {
-        return f.toURI().normalize();
-    }
 }