Wed, 21 Sep 2011 21:56:53 -0700
7092965: javac should not close processorClassLoader before end of compilation
Reviewed-by: darcy
jjg@946 | 1 | /* |
jjg@946 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
jjg@946 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@946 | 4 | * |
jjg@946 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@946 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@946 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@946 | 8 | * particular file as subject to the "Classpath" exception as provided |
jjg@946 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@946 | 10 | * |
jjg@946 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@946 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@946 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@946 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@946 | 15 | * accompanied this code). |
jjg@946 | 16 | * |
jjg@946 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@946 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@946 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@946 | 20 | * |
jjg@946 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@946 | 22 | * or visit www.oracle.com if you need additional information or have any |
jjg@946 | 23 | * questions. |
jjg@946 | 24 | */ |
jjg@946 | 25 | |
jjg@946 | 26 | |
jjg@946 | 27 | package com.sun.tools.javac.api; |
jjg@946 | 28 | |
jjg@946 | 29 | import java.io.IOException; |
jjg@946 | 30 | import java.io.InputStream; |
jjg@946 | 31 | import java.io.OutputStream; |
jjg@946 | 32 | import java.io.Reader; |
jjg@946 | 33 | import java.io.Writer; |
jjg@946 | 34 | import java.net.URI; |
jjg@946 | 35 | import java.util.ArrayList; |
jjg@946 | 36 | import java.util.Collections; |
jjg@946 | 37 | import java.util.HashMap; |
jjg@946 | 38 | import java.util.Iterator; |
jjg@946 | 39 | import java.util.List; |
jjg@1073 | 40 | import java.util.Locale; |
jjg@946 | 41 | import java.util.Map; |
jjg@946 | 42 | import java.util.Set; |
jjg@946 | 43 | |
jjg@946 | 44 | import javax.lang.model.element.NestingKind; |
jjg@946 | 45 | import javax.tools.Diagnostic; |
jjg@946 | 46 | import javax.tools.FileObject; |
jjg@946 | 47 | import javax.tools.JavaFileManager; |
jjg@946 | 48 | import javax.tools.JavaFileManager.Location; |
jjg@946 | 49 | import javax.tools.JavaFileObject; |
jjg@946 | 50 | |
jjg@946 | 51 | import com.sun.source.util.TaskEvent; |
jjg@946 | 52 | import com.sun.source.util.TaskListener; |
jjg@946 | 53 | import com.sun.tools.javac.util.ClientCodeException; |
jjg@946 | 54 | import com.sun.tools.javac.util.Context; |
jjg@1073 | 55 | import com.sun.tools.javac.util.JCDiagnostic; |
jjg@946 | 56 | import java.lang.annotation.ElementType; |
jjg@946 | 57 | import java.lang.annotation.Retention; |
jjg@946 | 58 | import java.lang.annotation.RetentionPolicy; |
jjg@946 | 59 | import java.lang.annotation.Target; |
jjg@946 | 60 | import javax.lang.model.element.Modifier; |
jjg@946 | 61 | import javax.tools.DiagnosticListener; |
jjg@946 | 62 | import javax.tools.JavaFileObject.Kind; |
jjg@946 | 63 | |
jjg@946 | 64 | /** |
jjg@946 | 65 | * Wrap objects to enable unchecked exceptions to be caught and handled. |
jjg@946 | 66 | * |
jjg@946 | 67 | * For each method, exceptions are handled as follows: |
jjg@946 | 68 | * <ul> |
jjg@946 | 69 | * <li>Checked exceptions are left alone and propogate upwards in the |
jjg@946 | 70 | * obvious way, since they are an expected aspect of the method's |
jjg@946 | 71 | * specification. |
jjg@946 | 72 | * <li>Unchecked exceptions which have already been caught and wrapped in |
jjg@946 | 73 | * ClientCodeException are left alone to continue propogating upwards. |
jjg@946 | 74 | * <li>All other unchecked exceptions (i.e. subtypes of RuntimeException |
jjg@946 | 75 | * and Error) and caught, and rethrown as a ClientCodeException with |
jjg@946 | 76 | * its cause set to the original exception. |
jjg@946 | 77 | * </ul> |
jjg@946 | 78 | * |
jjg@946 | 79 | * The intent is that ClientCodeException can be caught at an appropriate point |
jjg@946 | 80 | * in the program and can be distinguished from any unanticipated unchecked |
jjg@946 | 81 | * exceptions arising in the main body of the code (i.e. bugs.) When the |
jjg@946 | 82 | * ClientCodeException has been caught, either a suitable message can be |
jjg@946 | 83 | * generated, or if appropriate, the original cause can be rethrown. |
jjg@946 | 84 | * |
jjg@946 | 85 | * <p><b>This is NOT part of any supported API. |
jjg@946 | 86 | * If you write code that depends on this, you do so at your own risk. |
jjg@946 | 87 | * This code and its internal interfaces are subject to change or |
jjg@946 | 88 | * deletion without notice.</b> |
jjg@946 | 89 | */ |
jjg@946 | 90 | public class ClientCodeWrapper { |
jjg@946 | 91 | @Retention(RetentionPolicy.RUNTIME) |
jjg@946 | 92 | @Target(ElementType.TYPE) |
jjg@946 | 93 | public @interface Trusted { } |
jjg@946 | 94 | |
jjg@946 | 95 | public static ClientCodeWrapper instance(Context context) { |
jjg@946 | 96 | ClientCodeWrapper instance = context.get(ClientCodeWrapper.class); |
jjg@946 | 97 | if (instance == null) |
jjg@946 | 98 | instance = new ClientCodeWrapper(context); |
jjg@946 | 99 | return instance; |
jjg@946 | 100 | } |
jjg@946 | 101 | |
jjg@946 | 102 | /** |
jjg@946 | 103 | * A map to cache the results of whether or not a specific classes can |
jjg@946 | 104 | * be "trusted", and thus does not need to be wrapped. |
jjg@946 | 105 | */ |
jjg@946 | 106 | Map<Class<?>, Boolean> trustedClasses; |
jjg@946 | 107 | |
jjg@946 | 108 | protected ClientCodeWrapper(Context context) { |
jjg@946 | 109 | trustedClasses = new HashMap<Class<?>, Boolean>(); |
jjg@946 | 110 | } |
jjg@946 | 111 | |
jjg@946 | 112 | public JavaFileManager wrap(JavaFileManager fm) { |
jjg@946 | 113 | if (isTrusted(fm)) |
jjg@946 | 114 | return fm; |
jjg@946 | 115 | return new WrappedJavaFileManager(fm); |
jjg@946 | 116 | } |
jjg@946 | 117 | |
jjg@946 | 118 | public FileObject wrap(FileObject fo) { |
jjg@946 | 119 | if (isTrusted(fo)) |
jjg@946 | 120 | return fo; |
jjg@946 | 121 | return new WrappedFileObject(fo); |
jjg@946 | 122 | } |
jjg@946 | 123 | |
jjg@946 | 124 | FileObject unwrap(FileObject fo) { |
jjg@946 | 125 | if (fo instanceof WrappedFileObject) |
jjg@946 | 126 | return ((WrappedFileObject) fo).clientFileObject; |
jjg@946 | 127 | else |
jjg@946 | 128 | return fo; |
jjg@946 | 129 | } |
jjg@946 | 130 | |
jjg@946 | 131 | public JavaFileObject wrap(JavaFileObject fo) { |
jjg@946 | 132 | if (isTrusted(fo)) |
jjg@946 | 133 | return fo; |
jjg@946 | 134 | return new WrappedJavaFileObject(fo); |
jjg@946 | 135 | } |
jjg@946 | 136 | |
jjg@946 | 137 | public Iterable<JavaFileObject> wrapJavaFileObjects(Iterable<? extends JavaFileObject> list) { |
jjg@946 | 138 | List<JavaFileObject> wrapped = new ArrayList<JavaFileObject>(); |
jjg@946 | 139 | for (JavaFileObject fo : list) |
jjg@946 | 140 | wrapped.add(wrap(fo)); |
jjg@946 | 141 | return Collections.unmodifiableList(wrapped); |
jjg@946 | 142 | } |
jjg@946 | 143 | |
jjg@946 | 144 | JavaFileObject unwrap(JavaFileObject fo) { |
jjg@946 | 145 | if (fo instanceof WrappedJavaFileObject) |
jjg@946 | 146 | return ((JavaFileObject) ((WrappedJavaFileObject) fo).clientFileObject); |
jjg@946 | 147 | else |
jjg@946 | 148 | return fo; |
jjg@946 | 149 | } |
jjg@946 | 150 | |
jjg@1073 | 151 | <T /*super JavaFileOject*/> DiagnosticListener<T> wrap(DiagnosticListener<T> dl) { |
jjg@946 | 152 | if (isTrusted(dl)) |
jjg@946 | 153 | return dl; |
jjg@946 | 154 | return new WrappedDiagnosticListener<T>(dl); |
jjg@946 | 155 | } |
jjg@946 | 156 | |
jjg@946 | 157 | TaskListener wrap(TaskListener tl) { |
jjg@946 | 158 | if (isTrusted(tl)) |
jjg@946 | 159 | return tl; |
jjg@946 | 160 | return new WrappedTaskListener(tl); |
jjg@946 | 161 | } |
jjg@946 | 162 | |
jjg@1073 | 163 | @SuppressWarnings("unchecked") |
jjg@1073 | 164 | private <T> Diagnostic<T> unwrap(final Diagnostic<T> diagnostic) { |
jjg@1073 | 165 | if (diagnostic instanceof JCDiagnostic) { |
jjg@1073 | 166 | JCDiagnostic d = (JCDiagnostic) diagnostic; |
jjg@1073 | 167 | return (Diagnostic<T>) new DiagnosticSourceUnwrapper(d); |
jjg@1073 | 168 | } else { |
jjg@1073 | 169 | return diagnostic; |
jjg@1073 | 170 | } |
jjg@1073 | 171 | } |
jjg@1073 | 172 | |
jjg@946 | 173 | protected boolean isTrusted(Object o) { |
jjg@946 | 174 | Class<?> c = o.getClass(); |
jjg@946 | 175 | Boolean trusted = trustedClasses.get(c); |
jjg@946 | 176 | if (trusted == null) { |
jjg@946 | 177 | trusted = c.getName().startsWith("com.sun.tools.javac.") |
jjg@946 | 178 | || c.isAnnotationPresent(Trusted.class); |
jjg@946 | 179 | trustedClasses.put(c, trusted); |
jjg@946 | 180 | } |
jjg@946 | 181 | return trusted; |
jjg@946 | 182 | } |
jjg@946 | 183 | |
jjg@946 | 184 | // <editor-fold defaultstate="collapsed" desc="Wrapper classes"> |
jjg@946 | 185 | |
jjg@946 | 186 | // FIXME: all these classes should be converted to use multi-catch when |
jjg@946 | 187 | // that is available in the bootstrap compiler. |
jjg@946 | 188 | |
jjg@946 | 189 | protected class WrappedJavaFileManager implements JavaFileManager { |
jjg@946 | 190 | protected JavaFileManager clientJavaFileManager; |
jjg@946 | 191 | WrappedJavaFileManager(JavaFileManager clientJavaFileManager) { |
jjg@946 | 192 | clientJavaFileManager.getClass(); // null check |
jjg@946 | 193 | this.clientJavaFileManager = clientJavaFileManager; |
jjg@946 | 194 | } |
jjg@946 | 195 | |
jjg@946 | 196 | @Override |
jjg@946 | 197 | public ClassLoader getClassLoader(Location location) { |
jjg@946 | 198 | try { |
jjg@946 | 199 | return clientJavaFileManager.getClassLoader(location); |
jjg@946 | 200 | } catch (ClientCodeException e) { |
jjg@946 | 201 | throw e; |
jjg@946 | 202 | } catch (RuntimeException e) { |
jjg@946 | 203 | throw new ClientCodeException(e); |
jjg@946 | 204 | } catch (Error e) { |
jjg@946 | 205 | throw new ClientCodeException(e); |
jjg@946 | 206 | } |
jjg@946 | 207 | } |
jjg@946 | 208 | |
jjg@946 | 209 | @Override |
jjg@946 | 210 | public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException { |
jjg@946 | 211 | try { |
jjg@946 | 212 | return wrapJavaFileObjects(clientJavaFileManager.list(location, packageName, kinds, recurse)); |
jjg@946 | 213 | } catch (ClientCodeException e) { |
jjg@946 | 214 | throw e; |
jjg@946 | 215 | } catch (RuntimeException e) { |
jjg@946 | 216 | throw new ClientCodeException(e); |
jjg@946 | 217 | } catch (Error e) { |
jjg@946 | 218 | throw new ClientCodeException(e); |
jjg@946 | 219 | } |
jjg@946 | 220 | } |
jjg@946 | 221 | |
jjg@946 | 222 | @Override |
jjg@946 | 223 | public String inferBinaryName(Location location, JavaFileObject file) { |
jjg@946 | 224 | try { |
jjg@946 | 225 | return clientJavaFileManager.inferBinaryName(location, unwrap(file)); |
jjg@946 | 226 | } catch (ClientCodeException e) { |
jjg@946 | 227 | throw e; |
jjg@946 | 228 | } catch (RuntimeException e) { |
jjg@946 | 229 | throw new ClientCodeException(e); |
jjg@946 | 230 | } catch (Error e) { |
jjg@946 | 231 | throw new ClientCodeException(e); |
jjg@946 | 232 | } |
jjg@946 | 233 | } |
jjg@946 | 234 | |
jjg@946 | 235 | @Override |
jjg@946 | 236 | public boolean isSameFile(FileObject a, FileObject b) { |
jjg@946 | 237 | try { |
jjg@946 | 238 | return clientJavaFileManager.isSameFile(unwrap(a), unwrap(b)); |
jjg@946 | 239 | } catch (ClientCodeException e) { |
jjg@946 | 240 | throw e; |
jjg@946 | 241 | } catch (RuntimeException e) { |
jjg@946 | 242 | throw new ClientCodeException(e); |
jjg@946 | 243 | } catch (Error e) { |
jjg@946 | 244 | throw new ClientCodeException(e); |
jjg@946 | 245 | } |
jjg@946 | 246 | } |
jjg@946 | 247 | |
jjg@946 | 248 | @Override |
jjg@946 | 249 | public boolean handleOption(String current, Iterator<String> remaining) { |
jjg@946 | 250 | try { |
jjg@946 | 251 | return clientJavaFileManager.handleOption(current, remaining); |
jjg@946 | 252 | } catch (ClientCodeException e) { |
jjg@946 | 253 | throw e; |
jjg@946 | 254 | } catch (RuntimeException e) { |
jjg@946 | 255 | throw new ClientCodeException(e); |
jjg@946 | 256 | } catch (Error e) { |
jjg@946 | 257 | throw new ClientCodeException(e); |
jjg@946 | 258 | } |
jjg@946 | 259 | } |
jjg@946 | 260 | |
jjg@946 | 261 | @Override |
jjg@946 | 262 | public boolean hasLocation(Location location) { |
jjg@946 | 263 | try { |
jjg@946 | 264 | return clientJavaFileManager.hasLocation(location); |
jjg@946 | 265 | } catch (ClientCodeException e) { |
jjg@946 | 266 | throw e; |
jjg@946 | 267 | } catch (RuntimeException e) { |
jjg@946 | 268 | throw new ClientCodeException(e); |
jjg@946 | 269 | } catch (Error e) { |
jjg@946 | 270 | throw new ClientCodeException(e); |
jjg@946 | 271 | } |
jjg@946 | 272 | } |
jjg@946 | 273 | |
jjg@946 | 274 | @Override |
jjg@946 | 275 | public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException { |
jjg@946 | 276 | try { |
jjg@946 | 277 | return wrap(clientJavaFileManager.getJavaFileForInput(location, className, kind)); |
jjg@946 | 278 | } catch (ClientCodeException e) { |
jjg@946 | 279 | throw e; |
jjg@946 | 280 | } catch (RuntimeException e) { |
jjg@946 | 281 | throw new ClientCodeException(e); |
jjg@946 | 282 | } catch (Error e) { |
jjg@946 | 283 | throw new ClientCodeException(e); |
jjg@946 | 284 | } |
jjg@946 | 285 | } |
jjg@946 | 286 | |
jjg@946 | 287 | @Override |
jjg@946 | 288 | public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException { |
jjg@946 | 289 | try { |
jjg@946 | 290 | return wrap(clientJavaFileManager.getJavaFileForOutput(location, className, kind, unwrap(sibling))); |
jjg@946 | 291 | } catch (ClientCodeException e) { |
jjg@946 | 292 | throw e; |
jjg@946 | 293 | } catch (RuntimeException e) { |
jjg@946 | 294 | throw new ClientCodeException(e); |
jjg@946 | 295 | } catch (Error e) { |
jjg@946 | 296 | throw new ClientCodeException(e); |
jjg@946 | 297 | } |
jjg@946 | 298 | } |
jjg@946 | 299 | |
jjg@946 | 300 | @Override |
jjg@946 | 301 | public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { |
jjg@946 | 302 | try { |
jjg@946 | 303 | return wrap(clientJavaFileManager.getFileForInput(location, packageName, relativeName)); |
jjg@946 | 304 | } catch (ClientCodeException e) { |
jjg@946 | 305 | throw e; |
jjg@946 | 306 | } catch (RuntimeException e) { |
jjg@946 | 307 | throw new ClientCodeException(e); |
jjg@946 | 308 | } catch (Error e) { |
jjg@946 | 309 | throw new ClientCodeException(e); |
jjg@946 | 310 | } |
jjg@946 | 311 | } |
jjg@946 | 312 | |
jjg@946 | 313 | @Override |
jjg@946 | 314 | public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { |
jjg@946 | 315 | try { |
jjg@946 | 316 | return wrap(clientJavaFileManager.getFileForOutput(location, packageName, relativeName, unwrap(sibling))); |
jjg@946 | 317 | } catch (ClientCodeException e) { |
jjg@946 | 318 | throw e; |
jjg@946 | 319 | } catch (RuntimeException e) { |
jjg@946 | 320 | throw new ClientCodeException(e); |
jjg@946 | 321 | } catch (Error e) { |
jjg@946 | 322 | throw new ClientCodeException(e); |
jjg@946 | 323 | } |
jjg@946 | 324 | } |
jjg@946 | 325 | |
jjg@946 | 326 | @Override |
jjg@946 | 327 | public void flush() throws IOException { |
jjg@946 | 328 | try { |
jjg@946 | 329 | clientJavaFileManager.flush(); |
jjg@946 | 330 | } catch (ClientCodeException e) { |
jjg@946 | 331 | throw e; |
jjg@946 | 332 | } catch (RuntimeException e) { |
jjg@946 | 333 | throw new ClientCodeException(e); |
jjg@946 | 334 | } catch (Error e) { |
jjg@946 | 335 | throw new ClientCodeException(e); |
jjg@946 | 336 | } |
jjg@946 | 337 | } |
jjg@946 | 338 | |
jjg@946 | 339 | @Override |
jjg@946 | 340 | public void close() throws IOException { |
jjg@946 | 341 | try { |
jjg@946 | 342 | clientJavaFileManager.close(); |
jjg@946 | 343 | } catch (ClientCodeException e) { |
jjg@946 | 344 | throw e; |
jjg@946 | 345 | } catch (RuntimeException e) { |
jjg@946 | 346 | throw new ClientCodeException(e); |
jjg@946 | 347 | } catch (Error e) { |
jjg@946 | 348 | throw new ClientCodeException(e); |
jjg@946 | 349 | } |
jjg@946 | 350 | } |
jjg@946 | 351 | |
jjg@946 | 352 | @Override |
jjg@946 | 353 | public int isSupportedOption(String option) { |
jjg@946 | 354 | try { |
jjg@946 | 355 | return clientJavaFileManager.isSupportedOption(option); |
jjg@946 | 356 | } catch (ClientCodeException e) { |
jjg@946 | 357 | throw e; |
jjg@946 | 358 | } catch (RuntimeException e) { |
jjg@946 | 359 | throw new ClientCodeException(e); |
jjg@946 | 360 | } catch (Error e) { |
jjg@946 | 361 | throw new ClientCodeException(e); |
jjg@946 | 362 | } |
jjg@946 | 363 | } |
jjg@946 | 364 | } |
jjg@946 | 365 | |
jjg@946 | 366 | protected class WrappedFileObject implements FileObject { |
jjg@946 | 367 | protected FileObject clientFileObject; |
jjg@946 | 368 | WrappedFileObject(FileObject clientFileObject) { |
jjg@946 | 369 | clientFileObject.getClass(); // null check |
jjg@946 | 370 | this.clientFileObject = clientFileObject; |
jjg@946 | 371 | } |
jjg@946 | 372 | |
jjg@946 | 373 | @Override |
jjg@946 | 374 | public URI toUri() { |
jjg@946 | 375 | try { |
jjg@946 | 376 | return clientFileObject.toUri(); |
jjg@946 | 377 | } catch (ClientCodeException e) { |
jjg@946 | 378 | throw e; |
jjg@946 | 379 | } catch (RuntimeException e) { |
jjg@946 | 380 | throw new ClientCodeException(e); |
jjg@946 | 381 | } catch (Error e) { |
jjg@946 | 382 | throw new ClientCodeException(e); |
jjg@946 | 383 | } |
jjg@946 | 384 | } |
jjg@946 | 385 | |
jjg@946 | 386 | @Override |
jjg@946 | 387 | public String getName() { |
jjg@946 | 388 | try { |
jjg@946 | 389 | return clientFileObject.getName(); |
jjg@946 | 390 | } catch (ClientCodeException e) { |
jjg@946 | 391 | throw e; |
jjg@946 | 392 | } catch (RuntimeException e) { |
jjg@946 | 393 | throw new ClientCodeException(e); |
jjg@946 | 394 | } catch (Error e) { |
jjg@946 | 395 | throw new ClientCodeException(e); |
jjg@946 | 396 | } |
jjg@946 | 397 | } |
jjg@946 | 398 | |
jjg@946 | 399 | @Override |
jjg@946 | 400 | public InputStream openInputStream() throws IOException { |
jjg@946 | 401 | try { |
jjg@946 | 402 | return clientFileObject.openInputStream(); |
jjg@946 | 403 | } catch (ClientCodeException e) { |
jjg@946 | 404 | throw e; |
jjg@946 | 405 | } catch (RuntimeException e) { |
jjg@946 | 406 | throw new ClientCodeException(e); |
jjg@946 | 407 | } catch (Error e) { |
jjg@946 | 408 | throw new ClientCodeException(e); |
jjg@946 | 409 | } |
jjg@946 | 410 | } |
jjg@946 | 411 | |
jjg@946 | 412 | @Override |
jjg@946 | 413 | public OutputStream openOutputStream() throws IOException { |
jjg@946 | 414 | try { |
jjg@946 | 415 | return clientFileObject.openOutputStream(); |
jjg@946 | 416 | } catch (ClientCodeException e) { |
jjg@946 | 417 | throw e; |
jjg@946 | 418 | } catch (RuntimeException e) { |
jjg@946 | 419 | throw new ClientCodeException(e); |
jjg@946 | 420 | } catch (Error e) { |
jjg@946 | 421 | throw new ClientCodeException(e); |
jjg@946 | 422 | } |
jjg@946 | 423 | } |
jjg@946 | 424 | |
jjg@946 | 425 | @Override |
jjg@946 | 426 | public Reader openReader(boolean ignoreEncodingErrors) throws IOException { |
jjg@946 | 427 | try { |
jjg@946 | 428 | return clientFileObject.openReader(ignoreEncodingErrors); |
jjg@946 | 429 | } catch (ClientCodeException e) { |
jjg@946 | 430 | throw e; |
jjg@946 | 431 | } catch (RuntimeException e) { |
jjg@946 | 432 | throw new ClientCodeException(e); |
jjg@946 | 433 | } catch (Error e) { |
jjg@946 | 434 | throw new ClientCodeException(e); |
jjg@946 | 435 | } |
jjg@946 | 436 | } |
jjg@946 | 437 | |
jjg@946 | 438 | @Override |
jjg@946 | 439 | public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
jjg@946 | 440 | try { |
jjg@946 | 441 | return clientFileObject.getCharContent(ignoreEncodingErrors); |
jjg@946 | 442 | } catch (ClientCodeException e) { |
jjg@946 | 443 | throw e; |
jjg@946 | 444 | } catch (RuntimeException e) { |
jjg@946 | 445 | throw new ClientCodeException(e); |
jjg@946 | 446 | } catch (Error e) { |
jjg@946 | 447 | throw new ClientCodeException(e); |
jjg@946 | 448 | } |
jjg@946 | 449 | } |
jjg@946 | 450 | |
jjg@946 | 451 | @Override |
jjg@946 | 452 | public Writer openWriter() throws IOException { |
jjg@946 | 453 | try { |
jjg@946 | 454 | return clientFileObject.openWriter(); |
jjg@946 | 455 | } catch (ClientCodeException e) { |
jjg@946 | 456 | throw e; |
jjg@946 | 457 | } catch (RuntimeException e) { |
jjg@946 | 458 | throw new ClientCodeException(e); |
jjg@946 | 459 | } catch (Error e) { |
jjg@946 | 460 | throw new ClientCodeException(e); |
jjg@946 | 461 | } |
jjg@946 | 462 | } |
jjg@946 | 463 | |
jjg@946 | 464 | @Override |
jjg@946 | 465 | public long getLastModified() { |
jjg@946 | 466 | try { |
jjg@946 | 467 | return clientFileObject.getLastModified(); |
jjg@946 | 468 | } catch (ClientCodeException e) { |
jjg@946 | 469 | throw e; |
jjg@946 | 470 | } catch (RuntimeException e) { |
jjg@946 | 471 | throw new ClientCodeException(e); |
jjg@946 | 472 | } catch (Error e) { |
jjg@946 | 473 | throw new ClientCodeException(e); |
jjg@946 | 474 | } |
jjg@946 | 475 | } |
jjg@946 | 476 | |
jjg@946 | 477 | @Override |
jjg@946 | 478 | public boolean delete() { |
jjg@946 | 479 | try { |
jjg@946 | 480 | return clientFileObject.delete(); |
jjg@946 | 481 | } catch (ClientCodeException e) { |
jjg@946 | 482 | throw e; |
jjg@946 | 483 | } catch (RuntimeException e) { |
jjg@946 | 484 | throw new ClientCodeException(e); |
jjg@946 | 485 | } catch (Error e) { |
jjg@946 | 486 | throw new ClientCodeException(e); |
jjg@946 | 487 | } |
jjg@946 | 488 | } |
jjg@946 | 489 | } |
jjg@946 | 490 | |
jjg@946 | 491 | protected class WrappedJavaFileObject extends WrappedFileObject implements JavaFileObject { |
jjg@946 | 492 | WrappedJavaFileObject(JavaFileObject clientJavaFileObject) { |
jjg@946 | 493 | super(clientJavaFileObject); |
jjg@946 | 494 | } |
jjg@946 | 495 | |
jjg@946 | 496 | @Override |
jjg@946 | 497 | public Kind getKind() { |
jjg@946 | 498 | try { |
jjg@946 | 499 | return ((JavaFileObject)clientFileObject).getKind(); |
jjg@946 | 500 | } catch (ClientCodeException e) { |
jjg@946 | 501 | throw e; |
jjg@946 | 502 | } catch (RuntimeException e) { |
jjg@946 | 503 | throw new ClientCodeException(e); |
jjg@946 | 504 | } catch (Error e) { |
jjg@946 | 505 | throw new ClientCodeException(e); |
jjg@946 | 506 | } |
jjg@946 | 507 | } |
jjg@946 | 508 | |
jjg@946 | 509 | @Override |
jjg@946 | 510 | public boolean isNameCompatible(String simpleName, Kind kind) { |
jjg@946 | 511 | try { |
jjg@946 | 512 | return ((JavaFileObject)clientFileObject).isNameCompatible(simpleName, kind); |
jjg@946 | 513 | } catch (ClientCodeException e) { |
jjg@946 | 514 | throw e; |
jjg@946 | 515 | } catch (RuntimeException e) { |
jjg@946 | 516 | throw new ClientCodeException(e); |
jjg@946 | 517 | } catch (Error e) { |
jjg@946 | 518 | throw new ClientCodeException(e); |
jjg@946 | 519 | } |
jjg@946 | 520 | } |
jjg@946 | 521 | |
jjg@946 | 522 | @Override |
jjg@946 | 523 | public NestingKind getNestingKind() { |
jjg@946 | 524 | try { |
jjg@946 | 525 | return ((JavaFileObject)clientFileObject).getNestingKind(); |
jjg@946 | 526 | } catch (ClientCodeException e) { |
jjg@946 | 527 | throw e; |
jjg@946 | 528 | } catch (RuntimeException e) { |
jjg@946 | 529 | throw new ClientCodeException(e); |
jjg@946 | 530 | } catch (Error e) { |
jjg@946 | 531 | throw new ClientCodeException(e); |
jjg@946 | 532 | } |
jjg@946 | 533 | } |
jjg@946 | 534 | |
jjg@946 | 535 | @Override |
jjg@946 | 536 | public Modifier getAccessLevel() { |
jjg@946 | 537 | try { |
jjg@946 | 538 | return ((JavaFileObject)clientFileObject).getAccessLevel(); |
jjg@946 | 539 | } catch (ClientCodeException e) { |
jjg@946 | 540 | throw e; |
jjg@946 | 541 | } catch (RuntimeException e) { |
jjg@946 | 542 | throw new ClientCodeException(e); |
jjg@946 | 543 | } catch (Error e) { |
jjg@946 | 544 | throw new ClientCodeException(e); |
jjg@946 | 545 | } |
jjg@946 | 546 | } |
jjg@946 | 547 | } |
jjg@946 | 548 | |
jjg@1073 | 549 | protected class WrappedDiagnosticListener<T /*super JavaFileObject*/> implements DiagnosticListener<T> { |
jjg@946 | 550 | protected DiagnosticListener<T> clientDiagnosticListener; |
jjg@946 | 551 | WrappedDiagnosticListener(DiagnosticListener<T> clientDiagnosticListener) { |
jjg@946 | 552 | clientDiagnosticListener.getClass(); // null check |
jjg@946 | 553 | this.clientDiagnosticListener = clientDiagnosticListener; |
jjg@946 | 554 | } |
jjg@946 | 555 | |
jjg@946 | 556 | @Override |
jjg@946 | 557 | public void report(Diagnostic<? extends T> diagnostic) { |
jjg@946 | 558 | try { |
jjg@1073 | 559 | clientDiagnosticListener.report(unwrap(diagnostic)); |
jjg@946 | 560 | } catch (ClientCodeException e) { |
jjg@946 | 561 | throw e; |
jjg@946 | 562 | } catch (RuntimeException e) { |
jjg@946 | 563 | throw new ClientCodeException(e); |
jjg@946 | 564 | } catch (Error e) { |
jjg@946 | 565 | throw new ClientCodeException(e); |
jjg@946 | 566 | } |
jjg@946 | 567 | } |
jjg@946 | 568 | } |
jjg@946 | 569 | |
jjg@1073 | 570 | public class DiagnosticSourceUnwrapper implements Diagnostic<JavaFileObject> { |
jjg@1073 | 571 | public final JCDiagnostic d; |
jjg@1073 | 572 | |
jjg@1073 | 573 | DiagnosticSourceUnwrapper(JCDiagnostic d) { |
jjg@1073 | 574 | this.d = d; |
jjg@1073 | 575 | } |
jjg@1073 | 576 | |
jjg@1073 | 577 | public Diagnostic.Kind getKind() { |
jjg@1073 | 578 | return d.getKind(); |
jjg@1073 | 579 | } |
jjg@1073 | 580 | |
jjg@1073 | 581 | public JavaFileObject getSource() { |
jjg@1073 | 582 | return unwrap(d.getSource()); |
jjg@1073 | 583 | } |
jjg@1073 | 584 | |
jjg@1073 | 585 | public long getPosition() { |
jjg@1073 | 586 | return d.getPosition(); |
jjg@1073 | 587 | } |
jjg@1073 | 588 | |
jjg@1073 | 589 | public long getStartPosition() { |
jjg@1073 | 590 | return d.getStartPosition(); |
jjg@1073 | 591 | } |
jjg@1073 | 592 | |
jjg@1073 | 593 | public long getEndPosition() { |
jjg@1073 | 594 | return d.getEndPosition(); |
jjg@1073 | 595 | } |
jjg@1073 | 596 | |
jjg@1073 | 597 | public long getLineNumber() { |
jjg@1073 | 598 | return d.getLineNumber(); |
jjg@1073 | 599 | } |
jjg@1073 | 600 | |
jjg@1073 | 601 | public long getColumnNumber() { |
jjg@1073 | 602 | return d.getColumnNumber(); |
jjg@1073 | 603 | } |
jjg@1073 | 604 | |
jjg@1073 | 605 | public String getCode() { |
jjg@1073 | 606 | return d.getCode(); |
jjg@1073 | 607 | } |
jjg@1073 | 608 | |
jjg@1073 | 609 | public String getMessage(Locale locale) { |
jjg@1073 | 610 | return d.getMessage(locale); |
jjg@1073 | 611 | } |
mcimadamore@1077 | 612 | |
mcimadamore@1077 | 613 | public String toString() { |
mcimadamore@1077 | 614 | return d.toString(); |
mcimadamore@1077 | 615 | } |
jjg@1073 | 616 | } |
jjg@1073 | 617 | |
jjg@946 | 618 | protected class WrappedTaskListener implements TaskListener { |
jjg@946 | 619 | protected TaskListener clientTaskListener; |
jjg@946 | 620 | WrappedTaskListener(TaskListener clientTaskListener) { |
jjg@946 | 621 | clientTaskListener.getClass(); // null check |
jjg@946 | 622 | this.clientTaskListener = clientTaskListener; |
jjg@946 | 623 | } |
jjg@946 | 624 | |
jjg@946 | 625 | @Override |
jjg@946 | 626 | public void started(TaskEvent ev) { |
jjg@946 | 627 | try { |
jjg@946 | 628 | clientTaskListener.started(ev); |
jjg@946 | 629 | } catch (ClientCodeException e) { |
jjg@946 | 630 | throw e; |
jjg@946 | 631 | } catch (RuntimeException e) { |
jjg@946 | 632 | throw new ClientCodeException(e); |
jjg@946 | 633 | } catch (Error e) { |
jjg@946 | 634 | throw new ClientCodeException(e); |
jjg@946 | 635 | } |
jjg@946 | 636 | } |
jjg@946 | 637 | |
jjg@946 | 638 | @Override |
jjg@946 | 639 | public void finished(TaskEvent ev) { |
jjg@946 | 640 | try { |
jjg@946 | 641 | clientTaskListener.finished(ev); |
jjg@946 | 642 | } catch (ClientCodeException e) { |
jjg@946 | 643 | throw e; |
jjg@946 | 644 | } catch (RuntimeException e) { |
jjg@946 | 645 | throw new ClientCodeException(e); |
jjg@946 | 646 | } catch (Error e) { |
jjg@946 | 647 | throw new ClientCodeException(e); |
jjg@946 | 648 | } |
jjg@946 | 649 | } |
jjg@946 | 650 | } |
jjg@946 | 651 | |
jjg@946 | 652 | // </editor-fold> |
jjg@946 | 653 | } |