author | mchung |
Fri, 20 Jun 2014 13:36:10 -0700 | |
changeset 25303 | 5f9e68207588 |
parent 5847 | 1908176fd6e3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 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; |
|
3782 | 32 |
import java.net.URI; |
33 |
import java.net.URISyntaxException; |
|
10 | 34 |
import java.nio.charset.CharsetDecoder; |
35 |
import javax.lang.model.element.Modifier; |
|
36 |
import javax.lang.model.element.NestingKind; |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
37 |
import javax.tools.FileObject; |
10 | 38 |
import javax.tools.JavaFileObject; |
39 |
||
40 |
import static javax.tools.JavaFileObject.Kind.*; |
|
41 |
||
4548 | 42 |
import com.sun.tools.javac.util.BaseFileManager; |
43 |
||
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
815
diff
changeset
|
44 |
/** |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
45 |
* <p><b>This is NOT part of any supported API. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
815
diff
changeset
|
46 |
* If you write code that depends on this, you do so at your own risk. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
815
diff
changeset
|
47 |
* This code and its internal interfaces are subject to change or |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
815
diff
changeset
|
48 |
* deletion without notice.</b> |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
815
diff
changeset
|
49 |
*/ |
10 | 50 |
public abstract class BaseFileObject implements JavaFileObject { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
51 |
protected BaseFileObject(JavacFileManager fileManager) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
52 |
this.fileManager = fileManager; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
53 |
} |
10 | 54 |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
55 |
/** Return a short name for the object, such as for use in raw diagnostics |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
56 |
*/ |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
57 |
public abstract String getShortName(); |
10 | 58 |
|
59 |
@Override |
|
60 |
public String toString() { |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
61 |
return getClass().getSimpleName() + "[" + getName() + "]"; |
10 | 62 |
} |
63 |
||
64 |
public NestingKind getNestingKind() { return null; } |
|
65 |
||
66 |
public Modifier getAccessLevel() { return null; } |
|
67 |
||
68 |
public Reader openReader(boolean ignoreEncodingErrors) throws IOException { |
|
69 |
return new InputStreamReader(openInputStream(), getDecoder(ignoreEncodingErrors)); |
|
70 |
} |
|
71 |
||
72 |
protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) { |
|
73 |
throw new UnsupportedOperationException(); |
|
74 |
} |
|
75 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
76 |
protected abstract String inferBinaryName(Iterable<? extends File> path); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
77 |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
78 |
protected static JavaFileObject.Kind getKind(String filename) { |
4548 | 79 |
return BaseFileManager.getKind(filename); |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
80 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
81 |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
82 |
protected static String removeExtension(String fileName) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
83 |
int lastDot = fileName.lastIndexOf("."); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
84 |
return (lastDot == -1 ? fileName : fileName.substring(0, lastDot)); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
85 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
86 |
|
3782 | 87 |
protected static URI createJarUri(File jarFile, String entryName) { |
88 |
URI jarURI = jarFile.toURI().normalize(); |
|
89 |
String separator = entryName.startsWith("/") ? "!" : "!/"; |
|
90 |
try { |
|
91 |
// The jar URI convention appears to be not to re-encode the jarURI |
|
92 |
return new URI("jar:" + jarURI + separator + entryName); |
|
93 |
} catch (URISyntaxException e) { |
|
94 |
throw new CannotCreateUriError(jarURI + separator + entryName, e); |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
/** Used when URLSyntaxException is thrown unexpectedly during |
|
99 |
* implementations of (Base)FileObject.toURI(). */ |
|
100 |
protected static class CannotCreateUriError extends Error { |
|
101 |
private static final long serialVersionUID = 9101708840997613546L; |
|
102 |
public CannotCreateUriError(String value, Throwable cause) { |
|
103 |
super(value, cause); |
|
104 |
} |
|
105 |
} |
|
106 |
||
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
107 |
/** Return the last component of a presumed hierarchical URI. |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
108 |
* From the scheme specific part of the URI, it returns the substring |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
109 |
* after the last "/" if any, or everything if no "/" is found. |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
110 |
*/ |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
111 |
public static String getSimpleName(FileObject fo) { |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
112 |
URI uri = fo.toUri(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
113 |
String s = uri.getSchemeSpecificPart(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
114 |
return s.substring(s.lastIndexOf("/") + 1); // safe when / not found |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
115 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
116 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
117 |
|
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
118 |
// force subtypes to define equals |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
119 |
@Override |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
120 |
public abstract boolean equals(Object other); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
121 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
122 |
// force subtypes to define hashCode |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
123 |
@Override |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
124 |
public abstract int hashCode(); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
125 |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
126 |
/** The file manager that created this JavaFileObject. */ |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
127 |
protected final JavacFileManager fileManager; |
10 | 128 |
} |