author | jjg |
Wed, 18 Jun 2008 07:23:25 -0700 | |
changeset 810 | e4b6a6d206e6 |
parent 731 | 1dd22bdb9ca5 |
child 815 | bcb5c0d7c1ab |
permissions | -rw-r--r-- |
10 | 1 |
/* |
2 |
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
10
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
10 | 27 |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
28 |
import java.io.File; |
10 | 29 |
import java.io.IOException; |
30 |
import java.io.InputStreamReader; |
|
31 |
import java.io.Reader; |
|
32 |
import java.nio.charset.CharsetDecoder; |
|
33 |
import javax.lang.model.element.Modifier; |
|
34 |
import javax.lang.model.element.NestingKind; |
|
35 |
import javax.tools.JavaFileObject; |
|
36 |
||
37 |
import static javax.tools.JavaFileObject.Kind.*; |
|
38 |
||
39 |
public abstract class BaseFileObject implements JavaFileObject { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
40 |
protected BaseFileObject(JavacFileManager fileManager) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
41 |
this.fileManager = fileManager; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
42 |
} |
10 | 43 |
|
44 |
public JavaFileObject.Kind getKind() { |
|
45 |
String n = getName(); |
|
46 |
if (n.endsWith(CLASS.extension)) |
|
47 |
return CLASS; |
|
48 |
else if (n.endsWith(SOURCE.extension)) |
|
49 |
return SOURCE; |
|
50 |
else if (n.endsWith(HTML.extension)) |
|
51 |
return HTML; |
|
52 |
else |
|
53 |
return OTHER; |
|
54 |
} |
|
55 |
||
56 |
@Override |
|
57 |
public String toString() { |
|
58 |
return getPath(); |
|
59 |
} |
|
60 |
||
61 |
/** @deprecated see bug 6410637 */ |
|
62 |
@Deprecated |
|
63 |
public String getPath() { |
|
64 |
return getName(); |
|
65 |
} |
|
66 |
||
67 |
/** @deprecated see bug 6410637 */ |
|
68 |
@Deprecated |
|
69 |
abstract public String getName(); |
|
70 |
||
71 |
public NestingKind getNestingKind() { return null; } |
|
72 |
||
73 |
public Modifier getAccessLevel() { return null; } |
|
74 |
||
75 |
public Reader openReader(boolean ignoreEncodingErrors) throws IOException { |
|
76 |
return new InputStreamReader(openInputStream(), getDecoder(ignoreEncodingErrors)); |
|
77 |
} |
|
78 |
||
79 |
protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) { |
|
80 |
throw new UnsupportedOperationException(); |
|
81 |
} |
|
82 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
83 |
protected abstract String inferBinaryName(Iterable<? extends File> path); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
84 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
85 |
protected static String removeExtension(String fileName) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
86 |
int lastDot = fileName.lastIndexOf("."); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
87 |
return (lastDot == -1 ? fileName : fileName.substring(0, lastDot)); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
88 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
89 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
90 |
/** The file manager that created this JavaFileObject. */ |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
91 |
protected final JavacFileManager fileManager; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
92 |
|
10 | 93 |
} |