author | jlahoda |
Wed, 27 Aug 2014 07:44:00 +0200 | |
changeset 26266 | 2d24bda701dc |
parent 25874 | 83c19f00452c |
child 44822 | 2f24758e7ae0 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
14258 | 2 |
* Copyright (c) 2006, 2012, 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 |
||
26 |
package com.sun.tools.javac.api; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.net.URI; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.Collections; |
|
32 |
import java.util.List; |
|
33 |
import java.util.Set; |
|
14258 | 34 |
|
35 |
import javax.tools.*; |
|
10 | 36 |
import javax.tools.JavaFileObject.Kind; |
37 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
38 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
39 |
import com.sun.tools.javac.util.DefinedBy.Api; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
40 |
|
10 | 41 |
/** |
42 |
* Wraps all calls to a given file manager. Subclasses of this class |
|
43 |
* might override some of these methods and might also provide |
|
44 |
* additional fields and methods. |
|
45 |
* |
|
46 |
* <p>This class might be moved to {@link javax.tools} in a future |
|
47 |
* release. |
|
48 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
49 |
* <p><b>This is NOT part of any supported API. |
10 | 50 |
* If you write code that depends on this, you do so at your own |
51 |
* risk. This code and its internal interfaces are subject to change |
|
52 |
* or deletion without notice.</b></p> |
|
53 |
* |
|
54 |
* @param <M> the type of file manager wrapped to by this object |
|
55 |
* |
|
56 |
* @author Peter von der Ahé |
|
57 |
* @since 1.6 |
|
58 |
*/ |
|
59 |
public class WrappingJavaFileManager<M extends JavaFileManager> extends ForwardingJavaFileManager<M> { |
|
60 |
||
61 |
/** |
|
62 |
* Creates a new instance of WrappingJavaFileManager. |
|
63 |
* @param fileManager file manager to be wrapped |
|
64 |
*/ |
|
65 |
protected WrappingJavaFileManager(M fileManager) { |
|
66 |
super(fileManager); |
|
67 |
} |
|
68 |
||
69 |
/** |
|
70 |
* This implementation returns the given file object. Subclasses |
|
71 |
* may override this behavior. |
|
72 |
* |
|
73 |
* @param fileObject a file object |
|
74 |
*/ |
|
75 |
protected FileObject wrap(FileObject fileObject) { |
|
76 |
return fileObject; |
|
77 |
} |
|
78 |
||
79 |
/** |
|
80 |
* This implementation forwards to {@link #wrap(FileObject)}. |
|
81 |
* Subclasses may override this behavior. |
|
82 |
* |
|
83 |
* @param fileObject a file object |
|
84 |
* @throws ClassCastException if the file object returned from the |
|
85 |
* forwarded call is not a subtype of {@linkplain JavaFileObject} |
|
86 |
*/ |
|
87 |
protected JavaFileObject wrap(JavaFileObject fileObject) { |
|
88 |
return (JavaFileObject)wrap((FileObject)fileObject); |
|
89 |
} |
|
90 |
||
91 |
/** |
|
92 |
* This implementation returns the given file object. Subclasses |
|
93 |
* may override this behavior. |
|
94 |
* |
|
95 |
* @param fileObject a file object |
|
96 |
*/ |
|
97 |
protected FileObject unwrap(FileObject fileObject) { |
|
98 |
return fileObject; |
|
99 |
} |
|
100 |
||
101 |
/** |
|
102 |
* This implementation forwards to {@link #unwrap(FileObject)}. |
|
103 |
* Subclasses may override this behavior. |
|
104 |
* |
|
105 |
* @param fileObject a file object |
|
106 |
* @throws ClassCastException if the file object returned from the |
|
107 |
* forwarded call is not a subtype of {@linkplain JavaFileObject} |
|
108 |
*/ |
|
109 |
protected JavaFileObject unwrap(JavaFileObject fileObject) { |
|
110 |
return (JavaFileObject)unwrap((FileObject)fileObject); |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* This implementation maps the given list of file objects by |
|
115 |
* calling wrap on each. Subclasses may override this behavior. |
|
116 |
* |
|
117 |
* @param fileObjects a list of file objects |
|
118 |
* @return the mapping |
|
119 |
*/ |
|
120 |
protected Iterable<JavaFileObject> wrap(Iterable<JavaFileObject> fileObjects) { |
|
22163 | 121 |
List<JavaFileObject> mapped = new ArrayList<>(); |
10 | 122 |
for (JavaFileObject fileObject : fileObjects) |
123 |
mapped.add(wrap(fileObject)); |
|
124 |
return Collections.unmodifiableList(mapped); |
|
125 |
} |
|
126 |
||
127 |
/** |
|
128 |
* This implementation returns the given URI. Subclasses may |
|
129 |
* override this behavior. |
|
130 |
* |
|
131 |
* @param uri a URI |
|
132 |
*/ |
|
133 |
protected URI unwrap(URI uri) { |
|
134 |
return uri; |
|
135 |
} |
|
136 |
||
137 |
/** |
|
138 |
* @throws IllegalStateException {@inheritDoc} |
|
139 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
140 |
@DefinedBy(Api.COMPILER) |
10 | 141 |
public Iterable<JavaFileObject> list(Location location, |
142 |
String packageName, |
|
143 |
Set<Kind> kinds, |
|
144 |
boolean recurse) |
|
145 |
throws IOException |
|
146 |
{ |
|
147 |
return wrap(super.list(location, packageName, kinds, recurse)); |
|
148 |
} |
|
149 |
||
150 |
/** |
|
151 |
* @throws IllegalStateException {@inheritDoc} |
|
152 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
153 |
@DefinedBy(Api.COMPILER) |
10 | 154 |
public String inferBinaryName(Location location, JavaFileObject file) { |
155 |
return super.inferBinaryName(location, unwrap(file)); |
|
156 |
} |
|
157 |
||
158 |
/** |
|
159 |
* @throws IllegalArgumentException {@inheritDoc} |
|
160 |
* @throws UnsupportedOperationException {@inheritDoc} |
|
161 |
* @throws IllegalStateException {@inheritDoc} |
|
162 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
163 |
@DefinedBy(Api.COMPILER) |
10 | 164 |
public JavaFileObject getJavaFileForInput(Location location, |
165 |
String className, |
|
166 |
Kind kind) |
|
167 |
throws IOException |
|
168 |
{ |
|
169 |
return wrap(super.getJavaFileForInput(location, className, kind)); |
|
170 |
} |
|
171 |
||
172 |
/** |
|
173 |
* @throws IllegalArgumentException {@inheritDoc} |
|
174 |
* @throws UnsupportedOperationException {@inheritDoc} |
|
175 |
* @throws IllegalStateException {@inheritDoc} |
|
176 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
177 |
@DefinedBy(Api.COMPILER) |
10 | 178 |
public JavaFileObject getJavaFileForOutput(Location location, |
179 |
String className, |
|
180 |
Kind kind, |
|
181 |
FileObject sibling) |
|
182 |
throws IOException |
|
183 |
{ |
|
184 |
return wrap(super.getJavaFileForOutput(location, className, kind, unwrap(sibling))); |
|
185 |
} |
|
186 |
||
187 |
/** |
|
188 |
* @throws IllegalArgumentException {@inheritDoc} |
|
189 |
* @throws IllegalStateException {@inheritDoc} |
|
190 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
191 |
@DefinedBy(Api.COMPILER) |
10 | 192 |
public FileObject getFileForInput(Location location, |
193 |
String packageName, |
|
194 |
String relativeName) |
|
195 |
throws IOException |
|
196 |
{ |
|
197 |
return wrap(super.getFileForInput(location, packageName, relativeName)); |
|
198 |
} |
|
199 |
||
200 |
/** |
|
201 |
* @throws IllegalArgumentException {@inheritDoc} |
|
202 |
* @throws IllegalStateException {@inheritDoc} |
|
203 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
204 |
@DefinedBy(Api.COMPILER) |
10 | 205 |
public FileObject getFileForOutput(Location location, |
206 |
String packageName, |
|
207 |
String relativeName, |
|
208 |
FileObject sibling) |
|
209 |
throws IOException |
|
210 |
{ |
|
211 |
return wrap(super.getFileForOutput(location, |
|
212 |
packageName, |
|
213 |
relativeName, |
|
214 |
unwrap(sibling))); |
|
215 |
} |
|
216 |
||
217 |
} |