test/tools/javac/api/TestClientCodeWrapper.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/api/TestClientCodeWrapper.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,604 @@
     1.4 +/*
     1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 6437138 6482554
    1.30 + * @summary JSR 199: Compiler doesn't diagnose crash in user code
    1.31 + * @library ../lib
    1.32 + * @build JavacTestingAbstractProcessor TestClientCodeWrapper
    1.33 + * @run main TestClientCodeWrapper
    1.34 + */
    1.35 +
    1.36 +import java.io.*;
    1.37 +import java.lang.reflect.Method;
    1.38 +import java.net.URI;
    1.39 +import java.util.*;
    1.40 +import javax.annotation.processing.*;
    1.41 +import javax.lang.model.*;
    1.42 +import javax.lang.model.element.*;
    1.43 +import javax.tools.*;
    1.44 +import com.sun.source.util.*;
    1.45 +import com.sun.tools.javac.api.*;
    1.46 +import javax.tools.JavaFileObject.Kind;
    1.47 +
    1.48 +public class TestClientCodeWrapper extends JavacTestingAbstractProcessor {
    1.49 +    public static void main(String... args) throws Exception {
    1.50 +        new TestClientCodeWrapper().run();
    1.51 +    }
    1.52 +
    1.53 +    /**
    1.54 +     * Run a series of compilations, each with a different user-provided object
    1.55 +     * configured to throw an exception when a specific method is invoked.
    1.56 +     * Then, verify the exception is thrown as expected.
    1.57 +     *
    1.58 +     * Some methods are not invoked from the compiler, and are excluded from the test.
    1.59 +     */
    1.60 +    void run() throws Exception {
    1.61 +        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    1.62 +        defaultFileManager = compiler.getStandardFileManager(null, null, null);
    1.63 +
    1.64 +        for (Method m: getMethodsExcept(JavaFileManager.class, "close", "getJavaFileForInput")) {
    1.65 +            test(m);
    1.66 +        }
    1.67 +
    1.68 +        for (Method m: getMethodsExcept(FileObject.class, "delete")) {
    1.69 +            test(m);
    1.70 +        }
    1.71 +
    1.72 +        for (Method m: getMethods(JavaFileObject.class)) {
    1.73 +            test(m);
    1.74 +        }
    1.75 +
    1.76 +        for (Method m: getMethodsExcept(Processor.class, "getCompletions")) {
    1.77 +            test(m);
    1.78 +        }
    1.79 +
    1.80 +        for (Method m: DiagnosticListener.class.getDeclaredMethods()) {
    1.81 +            test(m);
    1.82 +        }
    1.83 +
    1.84 +        for (Method m: TaskListener.class.getDeclaredMethods()) {
    1.85 +            test(m);
    1.86 +        }
    1.87 +
    1.88 +        if (errors > 0)
    1.89 +            throw new Exception(errors + " errors occurred");
    1.90 +    }
    1.91 +
    1.92 +    /** Get a sorted set of the methods declared on a class. */
    1.93 +    Set<Method> getMethods(Class<?> clazz) {
    1.94 +        return getMethodsExcept(clazz, new String[0]);
    1.95 +    }
    1.96 +
    1.97 +    /** Get a sorted set of the methods declared on a class, excluding
    1.98 +     *  specified methods by name. */
    1.99 +    Set<Method> getMethodsExcept(Class<?> clazz, String... exclude) {
   1.100 +        Set<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
   1.101 +            public int compare(Method m1, Method m2) {
   1.102 +                return m1.toString().compareTo(m2.toString());
   1.103 +            }
   1.104 +        });
   1.105 +        Set<String> e = new HashSet<String>(Arrays.asList(exclude));
   1.106 +        for (Method m: clazz.getDeclaredMethods()) {
   1.107 +            if (!e.contains(m.getName()))
   1.108 +                methods.add(m);
   1.109 +        }
   1.110 +        return methods;
   1.111 +    }
   1.112 +
   1.113 +    /**
   1.114 +     * Test a method in a user supplied component, to verify javac's handling
   1.115 +     * of any exceptions thrown by that method.
   1.116 +     */
   1.117 +    void test(Method m) throws Exception {
   1.118 +        testNum++;
   1.119 +
   1.120 +        File extDirs = new File("empty-extdirs");
   1.121 +        extDirs.mkdirs();
   1.122 +
   1.123 +        File testClasses = new File("test" + testNum);
   1.124 +        testClasses.mkdirs();
   1.125 +        defaultFileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(testClasses));
   1.126 +
   1.127 +        System.err.println("test " + testNum + ": "
   1.128 +                + m.getDeclaringClass().getSimpleName() + "." + m.getName());
   1.129 +
   1.130 +        StringWriter sw = new StringWriter();
   1.131 +        PrintWriter pw = new PrintWriter(sw);
   1.132 +
   1.133 +        List<String> javacOptions = Arrays.asList(
   1.134 +                "-extdirs", extDirs.getPath(), // for use by filemanager handleOption
   1.135 +                "-processor", TestClientCodeWrapper.class.getName()
   1.136 +                );
   1.137 +
   1.138 +        List<String> classes = Collections.emptyList();
   1.139 +
   1.140 +        JavacTool tool = JavacTool.create();
   1.141 +        try {
   1.142 +            JavacTask task = tool.getTask(pw,
   1.143 +                    getFileManager(m, defaultFileManager),
   1.144 +                    getDiagnosticListener(m, pw),
   1.145 +                    javacOptions,
   1.146 +                    classes,
   1.147 +                    getCompilationUnits(m));
   1.148 +
   1.149 +            if (isDeclaredIn(m, Processor.class))
   1.150 +                task.setProcessors(getProcessors(m));
   1.151 +
   1.152 +            if (isDeclaredIn(m, TaskListener.class))
   1.153 +                task.setTaskListener(getTaskListener(m, pw));
   1.154 +
   1.155 +            boolean ok = task.call();
   1.156 +            error("compilation " + (ok ? "succeeded" : "failed") + " unexpectedly");
   1.157 +        } catch (RuntimeException e) {
   1.158 +            System.err.println("caught " + e);
   1.159 +            if (e.getClass() == RuntimeException.class) {
   1.160 +                Throwable cause = e.getCause();
   1.161 +                if (cause instanceof UserError) {
   1.162 +                    String expect = m.getName();
   1.163 +                    String found = cause.getMessage();
   1.164 +                    checkEqual("exception messaqe", expect, found);
   1.165 +                } else {
   1.166 +                    cause.printStackTrace(System.err);
   1.167 +                    error("Unexpected exception: " + cause);
   1.168 +                }
   1.169 +            } else {
   1.170 +                e.printStackTrace(System.err);
   1.171 +                error("Unexpected exception: " + e);
   1.172 +            }
   1.173 +        }
   1.174 +
   1.175 +        pw.close();
   1.176 +        String out = sw.toString();
   1.177 +        System.err.println(out);
   1.178 +    }
   1.179 +
   1.180 +    /** Get a file manager to use for the test compilation. */
   1.181 +    JavaFileManager getFileManager(Method m, JavaFileManager defaultFileManager) {
   1.182 +        return isDeclaredIn(m, JavaFileManager.class, FileObject.class, JavaFileObject.class)
   1.183 +                ? new UserFileManager(m, defaultFileManager)
   1.184 +                : defaultFileManager;
   1.185 +    }
   1.186 +
   1.187 +    /** Get a diagnostic listener to use for the test compilation. */
   1.188 +    DiagnosticListener<JavaFileObject> getDiagnosticListener(Method m, PrintWriter out) {
   1.189 +        return isDeclaredIn(m, DiagnosticListener.class)
   1.190 +                ? new UserDiagnosticListener(m, out)
   1.191 +                : null;
   1.192 +    }
   1.193 +
   1.194 +    /** Get a set of file objects to use for the test compilation. */
   1.195 +    Iterable<? extends JavaFileObject> getCompilationUnits(Method m) {
   1.196 +        File testSrc = new File(System.getProperty("test.src"));
   1.197 +        File thisSrc = new File(testSrc, TestClientCodeWrapper.class.getName() + ".java");
   1.198 +        Iterable<? extends JavaFileObject> files = defaultFileManager.getJavaFileObjects(thisSrc);
   1.199 +        if (isDeclaredIn(m, FileObject.class, JavaFileObject.class))
   1.200 +            return Arrays.asList(new UserFileObject(m, files.iterator().next()));
   1.201 +        else
   1.202 +            return files;
   1.203 +    }
   1.204 +
   1.205 +    /** Get a set of annotation processors to use for the test compilation. */
   1.206 +    Iterable<? extends Processor> getProcessors(Method m) {
   1.207 +        return Arrays.asList(new UserProcessor(m));
   1.208 +    }
   1.209 +
   1.210 +    /** Get a task listener to use for the test compilation. */
   1.211 +    TaskListener getTaskListener(Method m, PrintWriter out) {
   1.212 +        return new UserTaskListener(m, out);
   1.213 +    }
   1.214 +
   1.215 +    /** Check if two values are .equal, and report an error if not. */
   1.216 +    <T> void checkEqual(String label, T expect, T found) {
   1.217 +        if (!expect.equals(found))
   1.218 +            error("Unexpected value for " + label + ": " + found + "; expected: " + expect);
   1.219 +    }
   1.220 +
   1.221 +    /** Report an error. */
   1.222 +    void error(String msg) {
   1.223 +        System.err.println("Error: " + msg);
   1.224 +        errors++;
   1.225 +    }
   1.226 +
   1.227 +    /** Check if a method is declared in any of a set of classes */
   1.228 +    static boolean isDeclaredIn(Method m, Class<?>... classes) {
   1.229 +        Class<?> dc = m.getDeclaringClass();
   1.230 +        for (Class<?> c: classes) {
   1.231 +            if (c == dc) return true;
   1.232 +        }
   1.233 +        return false;
   1.234 +    }
   1.235 +
   1.236 +    /** Throw an intentional error if the method has a given name. */
   1.237 +    static void throwUserExceptionIfNeeded(Method m, String name) {
   1.238 +        if (m != null && m.getName().equals(name))
   1.239 +            throw new UserError(name);
   1.240 +    }
   1.241 +
   1.242 +    StandardJavaFileManager defaultFileManager;
   1.243 +    int testNum;
   1.244 +    int errors;
   1.245 +
   1.246 +    //--------------------------------------------------------------------------
   1.247 +
   1.248 +    /**
   1.249 +     * Processor used to trigger use of methods not normally used by javac.
   1.250 +     */
   1.251 +    @Override
   1.252 +    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   1.253 +        boolean firstRound = false;
   1.254 +        for (Element e: roundEnv.getRootElements()) {
   1.255 +            if (e.getSimpleName().contentEquals(TestClientCodeWrapper.class.getSimpleName()))
   1.256 +                firstRound = true;
   1.257 +        }
   1.258 +        if (firstRound) {
   1.259 +            try {
   1.260 +                FileObject f1 = filer.getResource(StandardLocation.CLASS_PATH, "",
   1.261 +                    TestClientCodeWrapper.class.getName() + ".java");
   1.262 +                f1.openInputStream().close();
   1.263 +                f1.openReader(false).close();
   1.264 +
   1.265 +                FileObject f2 = filer.createResource(
   1.266 +                        StandardLocation.CLASS_OUTPUT, "", "f2.txt", (Element[]) null);
   1.267 +                f2.openOutputStream().close();
   1.268 +
   1.269 +                FileObject f3 = filer.createResource(
   1.270 +                        StandardLocation.CLASS_OUTPUT, "", "f3.txt", (Element[]) null);
   1.271 +                f3.openWriter().close();
   1.272 +
   1.273 +                JavaFileObject f4 = filer.createSourceFile("f4", (Element[]) null);
   1.274 +                f4.openWriter().close();
   1.275 +                f4.getNestingKind();
   1.276 +                f4.getAccessLevel();
   1.277 +
   1.278 +                messager.printMessage(Diagnostic.Kind.NOTE, "informational note",
   1.279 +                        roundEnv.getRootElements().iterator().next());
   1.280 +
   1.281 +            } catch (IOException e) {
   1.282 +                throw new UserError(e);
   1.283 +            }
   1.284 +        }
   1.285 +        return true;
   1.286 +    }
   1.287 +
   1.288 +    //--------------------------------------------------------------------------
   1.289 +
   1.290 +    // <editor-fold defaultstate="collapsed" desc="User classes">
   1.291 +
   1.292 +    static class UserError extends Error {
   1.293 +        private static final long serialVersionUID = 1L;
   1.294 +        UserError(String msg) {
   1.295 +            super(msg);
   1.296 +        }
   1.297 +        UserError(Throwable t) {
   1.298 +            super(t);
   1.299 +        }
   1.300 +    }
   1.301 +
   1.302 +    static class UserFileManager extends ForwardingJavaFileManager<JavaFileManager> {
   1.303 +        Method fileManagerMethod;
   1.304 +        Method fileObjectMethod;
   1.305 +
   1.306 +        UserFileManager(Method m, JavaFileManager delegate) {
   1.307 +            super(delegate);
   1.308 +            if (isDeclaredIn(m, JavaFileManager.class)) {
   1.309 +                fileManagerMethod = m;
   1.310 +            } else if (isDeclaredIn(m, FileObject.class, JavaFileObject.class)) {
   1.311 +                fileObjectMethod = m;
   1.312 +            } else
   1.313 +                assert false;
   1.314 +        }
   1.315 +
   1.316 +        @Override
   1.317 +        public ClassLoader getClassLoader(Location location) {
   1.318 +            throwUserExceptionIfNeeded(fileManagerMethod, "getClassLoader");
   1.319 +            return super.getClassLoader(location);
   1.320 +        }
   1.321 +
   1.322 +        @Override
   1.323 +        public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException {
   1.324 +            throwUserExceptionIfNeeded(fileManagerMethod, "list");
   1.325 +            return wrap(super.list(location, packageName, kinds, recurse));
   1.326 +        }
   1.327 +
   1.328 +        @Override
   1.329 +        public String inferBinaryName(Location location, JavaFileObject file) {
   1.330 +            throwUserExceptionIfNeeded(fileManagerMethod, "inferBinaryName");
   1.331 +            return super.inferBinaryName(location, unwrap(file));
   1.332 +        }
   1.333 +
   1.334 +        @Override
   1.335 +        public boolean isSameFile(FileObject a, FileObject b) {
   1.336 +            throwUserExceptionIfNeeded(fileManagerMethod, "isSameFile");
   1.337 +            return super.isSameFile(unwrap(a), unwrap(b));
   1.338 +        }
   1.339 +
   1.340 +        @Override
   1.341 +        public boolean handleOption(String current, Iterator<String> remaining) {
   1.342 +            throwUserExceptionIfNeeded(fileManagerMethod, "handleOption");
   1.343 +            return super.handleOption(current, remaining);
   1.344 +        }
   1.345 +
   1.346 +        @Override
   1.347 +        public boolean hasLocation(Location location) {
   1.348 +            throwUserExceptionIfNeeded(fileManagerMethod, "hasLocation");
   1.349 +            return super.hasLocation(location);
   1.350 +        }
   1.351 +
   1.352 +        @Override
   1.353 +        public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
   1.354 +            throwUserExceptionIfNeeded(fileManagerMethod, "getJavaFileForInput");
   1.355 +            return wrap(super.getJavaFileForInput(location, className, kind));
   1.356 +        }
   1.357 +
   1.358 +        @Override
   1.359 +        public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
   1.360 +            throwUserExceptionIfNeeded(fileManagerMethod, "getJavaFileForOutput");
   1.361 +            return wrap(super.getJavaFileForOutput(location, className, kind, sibling));
   1.362 +        }
   1.363 +
   1.364 +        @Override
   1.365 +        public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
   1.366 +            throwUserExceptionIfNeeded(fileManagerMethod, "getFileForInput");
   1.367 +            return wrap(super.getFileForInput(location, packageName, relativeName));
   1.368 +        }
   1.369 +
   1.370 +        @Override
   1.371 +        public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException {
   1.372 +            throwUserExceptionIfNeeded(fileManagerMethod, "getFileForOutput");
   1.373 +            return wrap(super.getFileForOutput(location, packageName, relativeName, sibling));
   1.374 +        }
   1.375 +
   1.376 +        @Override
   1.377 +        public void flush() throws IOException {
   1.378 +            throwUserExceptionIfNeeded(fileManagerMethod, "flush");
   1.379 +            super.flush();
   1.380 +        }
   1.381 +
   1.382 +        @Override
   1.383 +        public void close() throws IOException {
   1.384 +            throwUserExceptionIfNeeded(fileManagerMethod, "close");
   1.385 +            super.close();
   1.386 +        }
   1.387 +
   1.388 +        @Override
   1.389 +        public int isSupportedOption(String option) {
   1.390 +            throwUserExceptionIfNeeded(fileManagerMethod, "isSupportedOption");
   1.391 +            return super.isSupportedOption(option);
   1.392 +        }
   1.393 +
   1.394 +        public FileObject wrap(FileObject fo) {
   1.395 +            if (fileObjectMethod == null)
   1.396 +                return fo;
   1.397 +            return new UserFileObject(fileObjectMethod, (JavaFileObject)fo);
   1.398 +        }
   1.399 +
   1.400 +        FileObject unwrap(FileObject fo) {
   1.401 +            if (fo instanceof UserFileObject)
   1.402 +                return ((UserFileObject) fo).unwrap();
   1.403 +            else
   1.404 +                return fo;
   1.405 +        }
   1.406 +
   1.407 +        public JavaFileObject wrap(JavaFileObject fo) {
   1.408 +            if (fileObjectMethod == null)
   1.409 +                return fo;
   1.410 +            return new UserFileObject(fileObjectMethod, fo);
   1.411 +        }
   1.412 +
   1.413 +        public Iterable<JavaFileObject> wrap(Iterable<? extends JavaFileObject> list) {
   1.414 +            List<JavaFileObject> wrapped = new ArrayList<JavaFileObject>();
   1.415 +            for (JavaFileObject fo : list)
   1.416 +                wrapped.add(wrap(fo));
   1.417 +            return Collections.unmodifiableList(wrapped);
   1.418 +        }
   1.419 +
   1.420 +        JavaFileObject unwrap(JavaFileObject fo) {
   1.421 +            if (fo instanceof UserFileObject)
   1.422 +                return ((UserFileObject) fo).unwrap();
   1.423 +            else
   1.424 +                return fo;
   1.425 +        }
   1.426 +    }
   1.427 +
   1.428 +    static class UserFileObject extends ForwardingJavaFileObject<JavaFileObject> {
   1.429 +        Method method;
   1.430 +
   1.431 +        UserFileObject(Method m, JavaFileObject delegate) {
   1.432 +            super(delegate);
   1.433 +            assert isDeclaredIn(m, FileObject.class, JavaFileObject.class);
   1.434 +            this.method = m;
   1.435 +        }
   1.436 +
   1.437 +        JavaFileObject unwrap() {
   1.438 +            return fileObject;
   1.439 +        }
   1.440 +
   1.441 +        @Override
   1.442 +        public Kind getKind() {
   1.443 +            throwUserExceptionIfNeeded(method, "getKind");
   1.444 +            return super.getKind();
   1.445 +        }
   1.446 +
   1.447 +        @Override
   1.448 +        public boolean isNameCompatible(String simpleName, Kind kind) {
   1.449 +            throwUserExceptionIfNeeded(method, "isNameCompatible");
   1.450 +            return super.isNameCompatible(simpleName, kind);
   1.451 +        }
   1.452 +
   1.453 +        @Override
   1.454 +        public NestingKind getNestingKind() {
   1.455 +            throwUserExceptionIfNeeded(method, "getNestingKind");
   1.456 +            return super.getNestingKind();
   1.457 +        }
   1.458 +
   1.459 +        @Override
   1.460 +        public Modifier getAccessLevel() {
   1.461 +            throwUserExceptionIfNeeded(method, "getAccessLevel");
   1.462 +            return super.getAccessLevel();
   1.463 +        }
   1.464 +
   1.465 +        @Override
   1.466 +        public URI toUri() {
   1.467 +            throwUserExceptionIfNeeded(method, "toUri");
   1.468 +            return super.toUri();
   1.469 +        }
   1.470 +
   1.471 +        @Override
   1.472 +        public String getName() {
   1.473 +            throwUserExceptionIfNeeded(method, "getName");
   1.474 +            return super.getName();
   1.475 +        }
   1.476 +
   1.477 +        @Override
   1.478 +        public InputStream openInputStream() throws IOException {
   1.479 +            throwUserExceptionIfNeeded(method, "openInputStream");
   1.480 +            return super.openInputStream();
   1.481 +        }
   1.482 +
   1.483 +        @Override
   1.484 +        public OutputStream openOutputStream() throws IOException {
   1.485 +            throwUserExceptionIfNeeded(method, "openOutputStream");
   1.486 +            return super.openOutputStream();
   1.487 +        }
   1.488 +
   1.489 +        @Override
   1.490 +        public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
   1.491 +            throwUserExceptionIfNeeded(method, "openReader");
   1.492 +            return super.openReader(ignoreEncodingErrors);
   1.493 +        }
   1.494 +
   1.495 +        @Override
   1.496 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   1.497 +            throwUserExceptionIfNeeded(method, "getCharContent");
   1.498 +            return super.getCharContent(ignoreEncodingErrors);
   1.499 +        }
   1.500 +
   1.501 +        @Override
   1.502 +        public Writer openWriter() throws IOException {
   1.503 +            throwUserExceptionIfNeeded(method, "openWriter");
   1.504 +            return super.openWriter();
   1.505 +        }
   1.506 +
   1.507 +        @Override
   1.508 +        public long getLastModified() {
   1.509 +            throwUserExceptionIfNeeded(method, "getLastModified");
   1.510 +            return super.getLastModified();
   1.511 +        }
   1.512 +
   1.513 +        @Override
   1.514 +        public boolean delete() {
   1.515 +            throwUserExceptionIfNeeded(method, "delete");
   1.516 +            return super.delete();
   1.517 +        }
   1.518 +
   1.519 +    }
   1.520 +
   1.521 +    static class UserProcessor extends JavacTestingAbstractProcessor {
   1.522 +        Method method;
   1.523 +
   1.524 +        UserProcessor(Method m) {
   1.525 +            assert isDeclaredIn(m, Processor.class);
   1.526 +            method = m;
   1.527 +        }
   1.528 +
   1.529 +        @Override
   1.530 +        public Set<String> getSupportedOptions() {
   1.531 +            throwUserExceptionIfNeeded(method, "getSupportedOptions");
   1.532 +            return super.getSupportedOptions();
   1.533 +        }
   1.534 +
   1.535 +        @Override
   1.536 +        public Set<String> getSupportedAnnotationTypes() {
   1.537 +            throwUserExceptionIfNeeded(method, "getSupportedAnnotationTypes");
   1.538 +            return super.getSupportedAnnotationTypes();
   1.539 +        }
   1.540 +
   1.541 +        @Override
   1.542 +        public SourceVersion getSupportedSourceVersion() {
   1.543 +            throwUserExceptionIfNeeded(method, "getSupportedSourceVersion");
   1.544 +            return super.getSupportedSourceVersion();
   1.545 +        }
   1.546 +
   1.547 +        @Override
   1.548 +        public void init(ProcessingEnvironment processingEnv) {
   1.549 +            throwUserExceptionIfNeeded(method, "init");
   1.550 +            super.init(processingEnv);
   1.551 +        }
   1.552 +
   1.553 +        @Override
   1.554 +        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   1.555 +            throwUserExceptionIfNeeded(method, "process");
   1.556 +            return true;
   1.557 +        }
   1.558 +
   1.559 +        @Override
   1.560 +        public Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
   1.561 +            throwUserExceptionIfNeeded(method, "getCompletions");
   1.562 +            return super.getCompletions(element, annotation, member, userText);
   1.563 +        }
   1.564 +    }
   1.565 +
   1.566 +    static class UserDiagnosticListener implements DiagnosticListener<JavaFileObject> {
   1.567 +        Method method;
   1.568 +        PrintWriter out;
   1.569 +
   1.570 +        UserDiagnosticListener(Method m, PrintWriter out) {
   1.571 +            assert isDeclaredIn(m, DiagnosticListener.class);
   1.572 +            this.method = m;
   1.573 +            this.out = out;
   1.574 +        }
   1.575 +
   1.576 +        @Override
   1.577 +        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
   1.578 +            throwUserExceptionIfNeeded(method, "report");
   1.579 +            out.println("report: " + diagnostic);
   1.580 +        }
   1.581 +    }
   1.582 +
   1.583 +    static class UserTaskListener implements TaskListener {
   1.584 +        Method method;
   1.585 +        PrintWriter out;
   1.586 +
   1.587 +        UserTaskListener(Method m, PrintWriter out) {
   1.588 +            assert isDeclaredIn(m, TaskListener.class);
   1.589 +            this.method = m;
   1.590 +            this.out = out;
   1.591 +        }
   1.592 +
   1.593 +        @Override
   1.594 +        public void started(TaskEvent e) {
   1.595 +            throwUserExceptionIfNeeded(method, "started");
   1.596 +            out.println("started: " + e);
   1.597 +        }
   1.598 +
   1.599 +        @Override
   1.600 +        public void finished(TaskEvent e) {
   1.601 +            throwUserExceptionIfNeeded(method, "finished");
   1.602 +            out.println("finished: " + e);
   1.603 +        }
   1.604 +    }
   1.605 +
   1.606 +    // </editor-fold>
   1.607 +}

mercurial