src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 1413
bdcef2ef52d2
parent 0
959103a6100f
permissions
-rw-r--r--

merge

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

mercurial