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

Wed, 17 Apr 2013 15:54:24 +0200

author
jlahoda
date
Wed, 17 Apr 2013 15:54:24 +0200
changeset 1704
ed918a442b83
parent 1413
bdcef2ef52d2
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8008174: DocTree API should provide start and end positions for tree nodes
Summary: Adding DocSourcePositions to allow access to DocTree starting/ending position
Reviewed-by: jjg, darcy
Contributed-by: Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>, Jan Lahoda <jlahoda@netbeans.org>

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

mercurial