jjg@946: /*
jjg@1210: * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
jjg@946: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@946: *
jjg@946: * This code is free software; you can redistribute it and/or modify it
jjg@946: * under the terms of the GNU General Public License version 2 only, as
jjg@946: * published by the Free Software Foundation. Oracle designates this
jjg@946: * particular file as subject to the "Classpath" exception as provided
jjg@946: * by Oracle in the LICENSE file that accompanied this code.
jjg@946: *
jjg@946: * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@946: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@946: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@946: * version 2 for more details (a copy is included in the LICENSE file that
jjg@946: * accompanied this code).
jjg@946: *
jjg@946: * You should have received a copy of the GNU General Public License version
jjg@946: * 2 along with this work; if not, write to the Free Software Foundation,
jjg@946: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@946: *
jjg@946: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@946: * or visit www.oracle.com if you need additional information or have any
jjg@946: * questions.
jjg@946: */
jjg@946:
jjg@946:
jjg@946: package com.sun.tools.javac.api;
jjg@946:
jjg@946: import java.io.IOException;
jjg@946: import java.io.InputStream;
jjg@946: import java.io.OutputStream;
jjg@946: import java.io.Reader;
jjg@946: import java.io.Writer;
jjg@1210: import java.lang.annotation.ElementType;
jjg@1210: import java.lang.annotation.Retention;
jjg@1210: import java.lang.annotation.RetentionPolicy;
jjg@1210: import java.lang.annotation.Target;
jjg@946: import java.net.URI;
jjg@946: import java.util.ArrayList;
jjg@1210: import java.util.Collection;
jjg@946: import java.util.Collections;
jjg@946: import java.util.HashMap;
jjg@946: import java.util.Iterator;
jjg@946: import java.util.List;
jjg@1073: import java.util.Locale;
jjg@946: import java.util.Map;
jjg@946: import java.util.Set;
jjg@946:
jjg@1210: import javax.lang.model.element.Modifier;
jjg@946: import javax.lang.model.element.NestingKind;
jjg@946: import javax.tools.Diagnostic;
jjg@1210: import javax.tools.DiagnosticListener;
jjg@946: import javax.tools.FileObject;
jjg@946: import javax.tools.JavaFileManager;
jjg@946: import javax.tools.JavaFileManager.Location;
jjg@946: import javax.tools.JavaFileObject;
jjg@1210: import javax.tools.JavaFileObject.Kind;
jjg@946:
jjg@946: import com.sun.source.util.TaskEvent;
jjg@946: import com.sun.source.util.TaskListener;
jjg@946: import com.sun.tools.javac.util.ClientCodeException;
jjg@946: import com.sun.tools.javac.util.Context;
jjg@1073: import com.sun.tools.javac.util.JCDiagnostic;
jjg@946:
jjg@946: /**
jjg@946: * Wrap objects to enable unchecked exceptions to be caught and handled.
jjg@946: *
jjg@946: * For each method, exceptions are handled as follows:
jjg@946: *
jjg@946: * - Checked exceptions are left alone and propogate upwards in the
jjg@946: * obvious way, since they are an expected aspect of the method's
jjg@946: * specification.
jjg@946: *
- Unchecked exceptions which have already been caught and wrapped in
jjg@946: * ClientCodeException are left alone to continue propogating upwards.
jjg@946: *
- All other unchecked exceptions (i.e. subtypes of RuntimeException
jjg@946: * and Error) and caught, and rethrown as a ClientCodeException with
jjg@946: * its cause set to the original exception.
jjg@946: *
jjg@946: *
jjg@946: * The intent is that ClientCodeException can be caught at an appropriate point
jjg@946: * in the program and can be distinguished from any unanticipated unchecked
jjg@946: * exceptions arising in the main body of the code (i.e. bugs.) When the
jjg@946: * ClientCodeException has been caught, either a suitable message can be
jjg@946: * generated, or if appropriate, the original cause can be rethrown.
jjg@946: *
jjg@946: * This is NOT part of any supported API.
jjg@946: * If you write code that depends on this, you do so at your own risk.
jjg@946: * This code and its internal interfaces are subject to change or
jjg@946: * deletion without notice.
jjg@946: */
jjg@946: public class ClientCodeWrapper {
jjg@946: @Retention(RetentionPolicy.RUNTIME)
jjg@946: @Target(ElementType.TYPE)
jjg@946: public @interface Trusted { }
jjg@946:
jjg@946: public static ClientCodeWrapper instance(Context context) {
jjg@946: ClientCodeWrapper instance = context.get(ClientCodeWrapper.class);
jjg@946: if (instance == null)
jjg@946: instance = new ClientCodeWrapper(context);
jjg@946: return instance;
jjg@946: }
jjg@946:
jjg@946: /**
jjg@946: * A map to cache the results of whether or not a specific classes can
jjg@946: * be "trusted", and thus does not need to be wrapped.
jjg@946: */
jjg@946: Map, Boolean> trustedClasses;
jjg@946:
jjg@946: protected ClientCodeWrapper(Context context) {
jjg@946: trustedClasses = new HashMap, Boolean>();
jjg@946: }
jjg@946:
jjg@946: public JavaFileManager wrap(JavaFileManager fm) {
jjg@946: if (isTrusted(fm))
jjg@946: return fm;
jjg@946: return new WrappedJavaFileManager(fm);
jjg@946: }
jjg@946:
jjg@946: public FileObject wrap(FileObject fo) {
jjg@946: if (isTrusted(fo))
jjg@946: return fo;
jjg@946: return new WrappedFileObject(fo);
jjg@946: }
jjg@946:
jjg@946: FileObject unwrap(FileObject fo) {
jjg@946: if (fo instanceof WrappedFileObject)
jjg@946: return ((WrappedFileObject) fo).clientFileObject;
jjg@946: else
jjg@946: return fo;
jjg@946: }
jjg@946:
jjg@946: public JavaFileObject wrap(JavaFileObject fo) {
jjg@946: if (isTrusted(fo))
jjg@946: return fo;
jjg@946: return new WrappedJavaFileObject(fo);
jjg@946: }
jjg@946:
jjg@946: public Iterable wrapJavaFileObjects(Iterable extends JavaFileObject> list) {
jjg@946: List wrapped = new ArrayList();
jjg@946: for (JavaFileObject fo : list)
jjg@946: wrapped.add(wrap(fo));
jjg@946: return Collections.unmodifiableList(wrapped);
jjg@946: }
jjg@946:
jjg@946: JavaFileObject unwrap(JavaFileObject fo) {
jjg@946: if (fo instanceof WrappedJavaFileObject)
jjg@946: return ((JavaFileObject) ((WrappedJavaFileObject) fo).clientFileObject);
jjg@946: else
jjg@946: return fo;
jjg@946: }
jjg@946:
jjg@1413: public DiagnosticListener wrap(DiagnosticListener dl) {
jjg@946: if (isTrusted(dl))
jjg@946: return dl;
jjg@946: return new WrappedDiagnosticListener(dl);
jjg@946: }
jjg@946:
jjg@946: TaskListener wrap(TaskListener tl) {
jjg@946: if (isTrusted(tl))
jjg@946: return tl;
jjg@946: return new WrappedTaskListener(tl);
jjg@946: }
jjg@946:
jjg@1210: TaskListener unwrap(TaskListener l) {
jjg@1210: if (l instanceof WrappedTaskListener)
jjg@1210: return ((WrappedTaskListener) l).clientTaskListener;
jjg@1210: else
jjg@1210: return l;
jjg@1210: }
jjg@1210:
jjg@1210: Collection unwrap(Collection extends TaskListener> listeners) {
jjg@1210: Collection c = new ArrayList(listeners.size());
jjg@1210: for (TaskListener l: listeners)
jjg@1210: c.add(unwrap(l));
jjg@1210: return c;
jjg@1210: }
jjg@1210:
jjg@1073: @SuppressWarnings("unchecked")
jjg@1073: private Diagnostic unwrap(final Diagnostic diagnostic) {
jjg@1073: if (diagnostic instanceof JCDiagnostic) {
jjg@1073: JCDiagnostic d = (JCDiagnostic) diagnostic;
jjg@1073: return (Diagnostic) new DiagnosticSourceUnwrapper(d);
jjg@1073: } else {
jjg@1073: return diagnostic;
jjg@1073: }
jjg@1073: }
jjg@1073:
jjg@946: protected boolean isTrusted(Object o) {
jjg@946: Class> c = o.getClass();
jjg@946: Boolean trusted = trustedClasses.get(c);
jjg@946: if (trusted == null) {
jjg@946: trusted = c.getName().startsWith("com.sun.tools.javac.")
jjg@946: || c.isAnnotationPresent(Trusted.class);
jjg@946: trustedClasses.put(c, trusted);
jjg@946: }
jjg@946: return trusted;
jjg@946: }
jjg@946:
jjg@1210: private String wrappedToString(Class> wrapperClass, Object wrapped) {
jjg@1210: return wrapperClass.getSimpleName() + "[" + wrapped + "]";
jjg@1210: }
jjg@1210:
jjg@946: //
jjg@946:
jjg@946: // FIXME: all these classes should be converted to use multi-catch when
jjg@946: // that is available in the bootstrap compiler.
jjg@946:
jjg@946: protected class WrappedJavaFileManager implements JavaFileManager {
jjg@946: protected JavaFileManager clientJavaFileManager;
jjg@946: WrappedJavaFileManager(JavaFileManager clientJavaFileManager) {
jjg@946: clientJavaFileManager.getClass(); // null check
jjg@946: this.clientJavaFileManager = clientJavaFileManager;
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public ClassLoader getClassLoader(Location location) {
jjg@946: try {
jjg@946: return clientJavaFileManager.getClassLoader(location);
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public Iterable list(Location location, String packageName, Set kinds, boolean recurse) throws IOException {
jjg@946: try {
jjg@946: return wrapJavaFileObjects(clientJavaFileManager.list(location, packageName, kinds, recurse));
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public String inferBinaryName(Location location, JavaFileObject file) {
jjg@946: try {
jjg@946: return clientJavaFileManager.inferBinaryName(location, unwrap(file));
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public boolean isSameFile(FileObject a, FileObject b) {
jjg@946: try {
jjg@946: return clientJavaFileManager.isSameFile(unwrap(a), unwrap(b));
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public boolean handleOption(String current, Iterator remaining) {
jjg@946: try {
jjg@946: return clientJavaFileManager.handleOption(current, remaining);
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public boolean hasLocation(Location location) {
jjg@946: try {
jjg@946: return clientJavaFileManager.hasLocation(location);
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
jjg@946: try {
jjg@946: return wrap(clientJavaFileManager.getJavaFileForInput(location, className, kind));
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
jjg@946: try {
jjg@946: return wrap(clientJavaFileManager.getJavaFileForOutput(location, className, kind, unwrap(sibling)));
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
jjg@946: try {
jjg@946: return wrap(clientJavaFileManager.getFileForInput(location, packageName, relativeName));
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException {
jjg@946: try {
jjg@946: return wrap(clientJavaFileManager.getFileForOutput(location, packageName, relativeName, unwrap(sibling)));
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public void flush() throws IOException {
jjg@946: try {
jjg@946: clientJavaFileManager.flush();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public void close() throws IOException {
jjg@946: try {
jjg@946: clientJavaFileManager.close();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public int isSupportedOption(String option) {
jjg@946: try {
jjg@946: return clientJavaFileManager.isSupportedOption(option);
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@1210:
jjg@1210: @Override
jjg@1210: public String toString() {
jjg@1210: return wrappedToString(getClass(), clientJavaFileManager);
jjg@1210: }
jjg@946: }
jjg@946:
jjg@946: protected class WrappedFileObject implements FileObject {
jjg@946: protected FileObject clientFileObject;
jjg@946: WrappedFileObject(FileObject clientFileObject) {
jjg@946: clientFileObject.getClass(); // null check
jjg@946: this.clientFileObject = clientFileObject;
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public URI toUri() {
jjg@946: try {
jjg@946: return clientFileObject.toUri();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public String getName() {
jjg@946: try {
jjg@946: return clientFileObject.getName();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public InputStream openInputStream() throws IOException {
jjg@946: try {
jjg@946: return clientFileObject.openInputStream();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public OutputStream openOutputStream() throws IOException {
jjg@946: try {
jjg@946: return clientFileObject.openOutputStream();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
jjg@946: try {
jjg@946: return clientFileObject.openReader(ignoreEncodingErrors);
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
jjg@946: try {
jjg@946: return clientFileObject.getCharContent(ignoreEncodingErrors);
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public Writer openWriter() throws IOException {
jjg@946: try {
jjg@946: return clientFileObject.openWriter();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public long getLastModified() {
jjg@946: try {
jjg@946: return clientFileObject.getLastModified();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public boolean delete() {
jjg@946: try {
jjg@946: return clientFileObject.delete();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@1210:
jjg@1210: @Override
jjg@1210: public String toString() {
jjg@1210: return wrappedToString(getClass(), clientFileObject);
jjg@1210: }
jjg@946: }
jjg@946:
jjg@946: protected class WrappedJavaFileObject extends WrappedFileObject implements JavaFileObject {
jjg@946: WrappedJavaFileObject(JavaFileObject clientJavaFileObject) {
jjg@946: super(clientJavaFileObject);
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public Kind getKind() {
jjg@946: try {
jjg@946: return ((JavaFileObject)clientFileObject).getKind();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public boolean isNameCompatible(String simpleName, Kind kind) {
jjg@946: try {
jjg@946: return ((JavaFileObject)clientFileObject).isNameCompatible(simpleName, kind);
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public NestingKind getNestingKind() {
jjg@946: try {
jjg@946: return ((JavaFileObject)clientFileObject).getNestingKind();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public Modifier getAccessLevel() {
jjg@946: try {
jjg@946: return ((JavaFileObject)clientFileObject).getAccessLevel();
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@1210:
jjg@1210: @Override
jjg@1210: public String toString() {
jjg@1210: return wrappedToString(getClass(), clientFileObject);
jjg@1210: }
jjg@946: }
jjg@946:
jjg@1073: protected class WrappedDiagnosticListener implements DiagnosticListener {
jjg@946: protected DiagnosticListener clientDiagnosticListener;
jjg@946: WrappedDiagnosticListener(DiagnosticListener clientDiagnosticListener) {
jjg@946: clientDiagnosticListener.getClass(); // null check
jjg@946: this.clientDiagnosticListener = clientDiagnosticListener;
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public void report(Diagnostic extends T> diagnostic) {
jjg@946: try {
jjg@1073: clientDiagnosticListener.report(unwrap(diagnostic));
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@1210:
jjg@1210: @Override
jjg@1210: public String toString() {
jjg@1210: return wrappedToString(getClass(), clientDiagnosticListener);
jjg@1210: }
jjg@946: }
jjg@946:
jjg@1073: public class DiagnosticSourceUnwrapper implements Diagnostic {
jjg@1073: public final JCDiagnostic d;
jjg@1073:
jjg@1073: DiagnosticSourceUnwrapper(JCDiagnostic d) {
jjg@1073: this.d = d;
jjg@1073: }
jjg@1073:
jjg@1073: public Diagnostic.Kind getKind() {
jjg@1073: return d.getKind();
jjg@1073: }
jjg@1073:
jjg@1073: public JavaFileObject getSource() {
jjg@1073: return unwrap(d.getSource());
jjg@1073: }
jjg@1073:
jjg@1073: public long getPosition() {
jjg@1073: return d.getPosition();
jjg@1073: }
jjg@1073:
jjg@1073: public long getStartPosition() {
jjg@1073: return d.getStartPosition();
jjg@1073: }
jjg@1073:
jjg@1073: public long getEndPosition() {
jjg@1073: return d.getEndPosition();
jjg@1073: }
jjg@1073:
jjg@1073: public long getLineNumber() {
jjg@1073: return d.getLineNumber();
jjg@1073: }
jjg@1073:
jjg@1073: public long getColumnNumber() {
jjg@1073: return d.getColumnNumber();
jjg@1073: }
jjg@1073:
jjg@1073: public String getCode() {
jjg@1073: return d.getCode();
jjg@1073: }
jjg@1073:
jjg@1073: public String getMessage(Locale locale) {
jjg@1073: return d.getMessage(locale);
jjg@1073: }
mcimadamore@1077:
jjg@1210: @Override
mcimadamore@1077: public String toString() {
mcimadamore@1077: return d.toString();
mcimadamore@1077: }
jjg@1073: }
jjg@1073:
jjg@946: protected class WrappedTaskListener implements TaskListener {
jjg@946: protected TaskListener clientTaskListener;
jjg@946: WrappedTaskListener(TaskListener clientTaskListener) {
jjg@946: clientTaskListener.getClass(); // null check
jjg@946: this.clientTaskListener = clientTaskListener;
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public void started(TaskEvent ev) {
jjg@946: try {
jjg@946: clientTaskListener.started(ev);
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@946:
jjg@946: @Override
jjg@946: public void finished(TaskEvent ev) {
jjg@946: try {
jjg@946: clientTaskListener.finished(ev);
jjg@946: } catch (ClientCodeException e) {
jjg@946: throw e;
jjg@946: } catch (RuntimeException e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: } catch (Error e) {
jjg@946: throw new ClientCodeException(e);
jjg@946: }
jjg@946: }
jjg@1210:
jjg@1210: @Override
jjg@1210: public String toString() {
jjg@1210: return wrappedToString(getClass(), clientTaskListener);
jjg@1210: }
jjg@946: }
jjg@946:
jjg@946: //
jjg@946: }