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