test/tools/javac/api/TestClientCodeWrapper.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
aoqi@0 25 * @test
aoqi@0 26 * @bug 6437138 6482554
aoqi@0 27 * @summary JSR 199: Compiler doesn't diagnose crash in user code
aoqi@0 28 * @library ../lib
aoqi@0 29 * @build JavacTestingAbstractProcessor TestClientCodeWrapper
aoqi@0 30 * @run main TestClientCodeWrapper
aoqi@0 31 */
aoqi@0 32
aoqi@0 33 import java.io.*;
aoqi@0 34 import java.lang.reflect.Method;
aoqi@0 35 import java.net.URI;
aoqi@0 36 import java.util.*;
aoqi@0 37 import javax.annotation.processing.*;
aoqi@0 38 import javax.lang.model.*;
aoqi@0 39 import javax.lang.model.element.*;
aoqi@0 40 import javax.tools.*;
aoqi@0 41 import com.sun.source.util.*;
aoqi@0 42 import com.sun.tools.javac.api.*;
aoqi@0 43 import javax.tools.JavaFileObject.Kind;
aoqi@0 44
aoqi@0 45 public class TestClientCodeWrapper extends JavacTestingAbstractProcessor {
aoqi@0 46 public static void main(String... args) throws Exception {
aoqi@0 47 new TestClientCodeWrapper().run();
aoqi@0 48 }
aoqi@0 49
aoqi@0 50 /**
aoqi@0 51 * Run a series of compilations, each with a different user-provided object
aoqi@0 52 * configured to throw an exception when a specific method is invoked.
aoqi@0 53 * Then, verify the exception is thrown as expected.
aoqi@0 54 *
aoqi@0 55 * Some methods are not invoked from the compiler, and are excluded from the test.
aoqi@0 56 */
aoqi@0 57 void run() throws Exception {
aoqi@0 58 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
aoqi@0 59 defaultFileManager = compiler.getStandardFileManager(null, null, null);
aoqi@0 60
aoqi@0 61 for (Method m: getMethodsExcept(JavaFileManager.class, "close", "getJavaFileForInput")) {
aoqi@0 62 test(m);
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 for (Method m: getMethodsExcept(FileObject.class, "delete")) {
aoqi@0 66 test(m);
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 for (Method m: getMethods(JavaFileObject.class)) {
aoqi@0 70 test(m);
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 for (Method m: getMethodsExcept(Processor.class, "getCompletions")) {
aoqi@0 74 test(m);
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 for (Method m: DiagnosticListener.class.getDeclaredMethods()) {
aoqi@0 78 test(m);
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 for (Method m: TaskListener.class.getDeclaredMethods()) {
aoqi@0 82 test(m);
aoqi@0 83 }
aoqi@0 84
aoqi@0 85 if (errors > 0)
aoqi@0 86 throw new Exception(errors + " errors occurred");
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 /** Get a sorted set of the methods declared on a class. */
aoqi@0 90 Set<Method> getMethods(Class<?> clazz) {
aoqi@0 91 return getMethodsExcept(clazz, new String[0]);
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 /** Get a sorted set of the methods declared on a class, excluding
aoqi@0 95 * specified methods by name. */
aoqi@0 96 Set<Method> getMethodsExcept(Class<?> clazz, String... exclude) {
aoqi@0 97 Set<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
aoqi@0 98 public int compare(Method m1, Method m2) {
aoqi@0 99 return m1.toString().compareTo(m2.toString());
aoqi@0 100 }
aoqi@0 101 });
aoqi@0 102 Set<String> e = new HashSet<String>(Arrays.asList(exclude));
aoqi@0 103 for (Method m: clazz.getDeclaredMethods()) {
aoqi@0 104 if (!e.contains(m.getName()))
aoqi@0 105 methods.add(m);
aoqi@0 106 }
aoqi@0 107 return methods;
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 /**
aoqi@0 111 * Test a method in a user supplied component, to verify javac's handling
aoqi@0 112 * of any exceptions thrown by that method.
aoqi@0 113 */
aoqi@0 114 void test(Method m) throws Exception {
aoqi@0 115 testNum++;
aoqi@0 116
aoqi@0 117 File extDirs = new File("empty-extdirs");
aoqi@0 118 extDirs.mkdirs();
aoqi@0 119
aoqi@0 120 File testClasses = new File("test" + testNum);
aoqi@0 121 testClasses.mkdirs();
aoqi@0 122 defaultFileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(testClasses));
aoqi@0 123
aoqi@0 124 System.err.println("test " + testNum + ": "
aoqi@0 125 + m.getDeclaringClass().getSimpleName() + "." + m.getName());
aoqi@0 126
aoqi@0 127 StringWriter sw = new StringWriter();
aoqi@0 128 PrintWriter pw = new PrintWriter(sw);
aoqi@0 129
aoqi@0 130 List<String> javacOptions = Arrays.asList(
aoqi@0 131 "-extdirs", extDirs.getPath(), // for use by filemanager handleOption
aoqi@0 132 "-processor", TestClientCodeWrapper.class.getName()
aoqi@0 133 );
aoqi@0 134
aoqi@0 135 List<String> classes = Collections.emptyList();
aoqi@0 136
aoqi@0 137 JavacTool tool = JavacTool.create();
aoqi@0 138 try {
aoqi@0 139 JavacTask task = tool.getTask(pw,
aoqi@0 140 getFileManager(m, defaultFileManager),
aoqi@0 141 getDiagnosticListener(m, pw),
aoqi@0 142 javacOptions,
aoqi@0 143 classes,
aoqi@0 144 getCompilationUnits(m));
aoqi@0 145
aoqi@0 146 if (isDeclaredIn(m, Processor.class))
aoqi@0 147 task.setProcessors(getProcessors(m));
aoqi@0 148
aoqi@0 149 if (isDeclaredIn(m, TaskListener.class))
aoqi@0 150 task.setTaskListener(getTaskListener(m, pw));
aoqi@0 151
aoqi@0 152 boolean ok = task.call();
aoqi@0 153 error("compilation " + (ok ? "succeeded" : "failed") + " unexpectedly");
aoqi@0 154 } catch (RuntimeException e) {
aoqi@0 155 System.err.println("caught " + e);
aoqi@0 156 if (e.getClass() == RuntimeException.class) {
aoqi@0 157 Throwable cause = e.getCause();
aoqi@0 158 if (cause instanceof UserError) {
aoqi@0 159 String expect = m.getName();
aoqi@0 160 String found = cause.getMessage();
aoqi@0 161 checkEqual("exception messaqe", expect, found);
aoqi@0 162 } else {
aoqi@0 163 cause.printStackTrace(System.err);
aoqi@0 164 error("Unexpected exception: " + cause);
aoqi@0 165 }
aoqi@0 166 } else {
aoqi@0 167 e.printStackTrace(System.err);
aoqi@0 168 error("Unexpected exception: " + e);
aoqi@0 169 }
aoqi@0 170 }
aoqi@0 171
aoqi@0 172 pw.close();
aoqi@0 173 String out = sw.toString();
aoqi@0 174 System.err.println(out);
aoqi@0 175 }
aoqi@0 176
aoqi@0 177 /** Get a file manager to use for the test compilation. */
aoqi@0 178 JavaFileManager getFileManager(Method m, JavaFileManager defaultFileManager) {
aoqi@0 179 return isDeclaredIn(m, JavaFileManager.class, FileObject.class, JavaFileObject.class)
aoqi@0 180 ? new UserFileManager(m, defaultFileManager)
aoqi@0 181 : defaultFileManager;
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 /** Get a diagnostic listener to use for the test compilation. */
aoqi@0 185 DiagnosticListener<JavaFileObject> getDiagnosticListener(Method m, PrintWriter out) {
aoqi@0 186 return isDeclaredIn(m, DiagnosticListener.class)
aoqi@0 187 ? new UserDiagnosticListener(m, out)
aoqi@0 188 : null;
aoqi@0 189 }
aoqi@0 190
aoqi@0 191 /** Get a set of file objects to use for the test compilation. */
aoqi@0 192 Iterable<? extends JavaFileObject> getCompilationUnits(Method m) {
aoqi@0 193 File testSrc = new File(System.getProperty("test.src"));
aoqi@0 194 File thisSrc = new File(testSrc, TestClientCodeWrapper.class.getName() + ".java");
aoqi@0 195 Iterable<? extends JavaFileObject> files = defaultFileManager.getJavaFileObjects(thisSrc);
aoqi@0 196 if (isDeclaredIn(m, FileObject.class, JavaFileObject.class))
aoqi@0 197 return Arrays.asList(new UserFileObject(m, files.iterator().next()));
aoqi@0 198 else
aoqi@0 199 return files;
aoqi@0 200 }
aoqi@0 201
aoqi@0 202 /** Get a set of annotation processors to use for the test compilation. */
aoqi@0 203 Iterable<? extends Processor> getProcessors(Method m) {
aoqi@0 204 return Arrays.asList(new UserProcessor(m));
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 /** Get a task listener to use for the test compilation. */
aoqi@0 208 TaskListener getTaskListener(Method m, PrintWriter out) {
aoqi@0 209 return new UserTaskListener(m, out);
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 /** Check if two values are .equal, and report an error if not. */
aoqi@0 213 <T> void checkEqual(String label, T expect, T found) {
aoqi@0 214 if (!expect.equals(found))
aoqi@0 215 error("Unexpected value for " + label + ": " + found + "; expected: " + expect);
aoqi@0 216 }
aoqi@0 217
aoqi@0 218 /** Report an error. */
aoqi@0 219 void error(String msg) {
aoqi@0 220 System.err.println("Error: " + msg);
aoqi@0 221 errors++;
aoqi@0 222 }
aoqi@0 223
aoqi@0 224 /** Check if a method is declared in any of a set of classes */
aoqi@0 225 static boolean isDeclaredIn(Method m, Class<?>... classes) {
aoqi@0 226 Class<?> dc = m.getDeclaringClass();
aoqi@0 227 for (Class<?> c: classes) {
aoqi@0 228 if (c == dc) return true;
aoqi@0 229 }
aoqi@0 230 return false;
aoqi@0 231 }
aoqi@0 232
aoqi@0 233 /** Throw an intentional error if the method has a given name. */
aoqi@0 234 static void throwUserExceptionIfNeeded(Method m, String name) {
aoqi@0 235 if (m != null && m.getName().equals(name))
aoqi@0 236 throw new UserError(name);
aoqi@0 237 }
aoqi@0 238
aoqi@0 239 StandardJavaFileManager defaultFileManager;
aoqi@0 240 int testNum;
aoqi@0 241 int errors;
aoqi@0 242
aoqi@0 243 //--------------------------------------------------------------------------
aoqi@0 244
aoqi@0 245 /**
aoqi@0 246 * Processor used to trigger use of methods not normally used by javac.
aoqi@0 247 */
aoqi@0 248 @Override
aoqi@0 249 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
aoqi@0 250 boolean firstRound = false;
aoqi@0 251 for (Element e: roundEnv.getRootElements()) {
aoqi@0 252 if (e.getSimpleName().contentEquals(TestClientCodeWrapper.class.getSimpleName()))
aoqi@0 253 firstRound = true;
aoqi@0 254 }
aoqi@0 255 if (firstRound) {
aoqi@0 256 try {
aoqi@0 257 FileObject f1 = filer.getResource(StandardLocation.CLASS_PATH, "",
aoqi@0 258 TestClientCodeWrapper.class.getName() + ".java");
aoqi@0 259 f1.openInputStream().close();
aoqi@0 260 f1.openReader(false).close();
aoqi@0 261
aoqi@0 262 FileObject f2 = filer.createResource(
aoqi@0 263 StandardLocation.CLASS_OUTPUT, "", "f2.txt", (Element[]) null);
aoqi@0 264 f2.openOutputStream().close();
aoqi@0 265
aoqi@0 266 FileObject f3 = filer.createResource(
aoqi@0 267 StandardLocation.CLASS_OUTPUT, "", "f3.txt", (Element[]) null);
aoqi@0 268 f3.openWriter().close();
aoqi@0 269
aoqi@0 270 JavaFileObject f4 = filer.createSourceFile("f4", (Element[]) null);
aoqi@0 271 f4.openWriter().close();
aoqi@0 272 f4.getNestingKind();
aoqi@0 273 f4.getAccessLevel();
aoqi@0 274
aoqi@0 275 messager.printMessage(Diagnostic.Kind.NOTE, "informational note",
aoqi@0 276 roundEnv.getRootElements().iterator().next());
aoqi@0 277
aoqi@0 278 } catch (IOException e) {
aoqi@0 279 throw new UserError(e);
aoqi@0 280 }
aoqi@0 281 }
aoqi@0 282 return true;
aoqi@0 283 }
aoqi@0 284
aoqi@0 285 //--------------------------------------------------------------------------
aoqi@0 286
aoqi@0 287 // <editor-fold defaultstate="collapsed" desc="User classes">
aoqi@0 288
aoqi@0 289 static class UserError extends Error {
aoqi@0 290 private static final long serialVersionUID = 1L;
aoqi@0 291 UserError(String msg) {
aoqi@0 292 super(msg);
aoqi@0 293 }
aoqi@0 294 UserError(Throwable t) {
aoqi@0 295 super(t);
aoqi@0 296 }
aoqi@0 297 }
aoqi@0 298
aoqi@0 299 static class UserFileManager extends ForwardingJavaFileManager<JavaFileManager> {
aoqi@0 300 Method fileManagerMethod;
aoqi@0 301 Method fileObjectMethod;
aoqi@0 302
aoqi@0 303 UserFileManager(Method m, JavaFileManager delegate) {
aoqi@0 304 super(delegate);
aoqi@0 305 if (isDeclaredIn(m, JavaFileManager.class)) {
aoqi@0 306 fileManagerMethod = m;
aoqi@0 307 } else if (isDeclaredIn(m, FileObject.class, JavaFileObject.class)) {
aoqi@0 308 fileObjectMethod = m;
aoqi@0 309 } else
aoqi@0 310 assert false;
aoqi@0 311 }
aoqi@0 312
aoqi@0 313 @Override
aoqi@0 314 public ClassLoader getClassLoader(Location location) {
aoqi@0 315 throwUserExceptionIfNeeded(fileManagerMethod, "getClassLoader");
aoqi@0 316 return super.getClassLoader(location);
aoqi@0 317 }
aoqi@0 318
aoqi@0 319 @Override
aoqi@0 320 public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException {
aoqi@0 321 throwUserExceptionIfNeeded(fileManagerMethod, "list");
aoqi@0 322 return wrap(super.list(location, packageName, kinds, recurse));
aoqi@0 323 }
aoqi@0 324
aoqi@0 325 @Override
aoqi@0 326 public String inferBinaryName(Location location, JavaFileObject file) {
aoqi@0 327 throwUserExceptionIfNeeded(fileManagerMethod, "inferBinaryName");
aoqi@0 328 return super.inferBinaryName(location, unwrap(file));
aoqi@0 329 }
aoqi@0 330
aoqi@0 331 @Override
aoqi@0 332 public boolean isSameFile(FileObject a, FileObject b) {
aoqi@0 333 throwUserExceptionIfNeeded(fileManagerMethod, "isSameFile");
aoqi@0 334 return super.isSameFile(unwrap(a), unwrap(b));
aoqi@0 335 }
aoqi@0 336
aoqi@0 337 @Override
aoqi@0 338 public boolean handleOption(String current, Iterator<String> remaining) {
aoqi@0 339 throwUserExceptionIfNeeded(fileManagerMethod, "handleOption");
aoqi@0 340 return super.handleOption(current, remaining);
aoqi@0 341 }
aoqi@0 342
aoqi@0 343 @Override
aoqi@0 344 public boolean hasLocation(Location location) {
aoqi@0 345 throwUserExceptionIfNeeded(fileManagerMethod, "hasLocation");
aoqi@0 346 return super.hasLocation(location);
aoqi@0 347 }
aoqi@0 348
aoqi@0 349 @Override
aoqi@0 350 public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
aoqi@0 351 throwUserExceptionIfNeeded(fileManagerMethod, "getJavaFileForInput");
aoqi@0 352 return wrap(super.getJavaFileForInput(location, className, kind));
aoqi@0 353 }
aoqi@0 354
aoqi@0 355 @Override
aoqi@0 356 public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
aoqi@0 357 throwUserExceptionIfNeeded(fileManagerMethod, "getJavaFileForOutput");
aoqi@0 358 return wrap(super.getJavaFileForOutput(location, className, kind, sibling));
aoqi@0 359 }
aoqi@0 360
aoqi@0 361 @Override
aoqi@0 362 public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
aoqi@0 363 throwUserExceptionIfNeeded(fileManagerMethod, "getFileForInput");
aoqi@0 364 return wrap(super.getFileForInput(location, packageName, relativeName));
aoqi@0 365 }
aoqi@0 366
aoqi@0 367 @Override
aoqi@0 368 public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException {
aoqi@0 369 throwUserExceptionIfNeeded(fileManagerMethod, "getFileForOutput");
aoqi@0 370 return wrap(super.getFileForOutput(location, packageName, relativeName, sibling));
aoqi@0 371 }
aoqi@0 372
aoqi@0 373 @Override
aoqi@0 374 public void flush() throws IOException {
aoqi@0 375 throwUserExceptionIfNeeded(fileManagerMethod, "flush");
aoqi@0 376 super.flush();
aoqi@0 377 }
aoqi@0 378
aoqi@0 379 @Override
aoqi@0 380 public void close() throws IOException {
aoqi@0 381 throwUserExceptionIfNeeded(fileManagerMethod, "close");
aoqi@0 382 super.close();
aoqi@0 383 }
aoqi@0 384
aoqi@0 385 @Override
aoqi@0 386 public int isSupportedOption(String option) {
aoqi@0 387 throwUserExceptionIfNeeded(fileManagerMethod, "isSupportedOption");
aoqi@0 388 return super.isSupportedOption(option);
aoqi@0 389 }
aoqi@0 390
aoqi@0 391 public FileObject wrap(FileObject fo) {
aoqi@0 392 if (fileObjectMethod == null)
aoqi@0 393 return fo;
aoqi@0 394 return new UserFileObject(fileObjectMethod, (JavaFileObject)fo);
aoqi@0 395 }
aoqi@0 396
aoqi@0 397 FileObject unwrap(FileObject fo) {
aoqi@0 398 if (fo instanceof UserFileObject)
aoqi@0 399 return ((UserFileObject) fo).unwrap();
aoqi@0 400 else
aoqi@0 401 return fo;
aoqi@0 402 }
aoqi@0 403
aoqi@0 404 public JavaFileObject wrap(JavaFileObject fo) {
aoqi@0 405 if (fileObjectMethod == null)
aoqi@0 406 return fo;
aoqi@0 407 return new UserFileObject(fileObjectMethod, fo);
aoqi@0 408 }
aoqi@0 409
aoqi@0 410 public Iterable<JavaFileObject> wrap(Iterable<? extends JavaFileObject> list) {
aoqi@0 411 List<JavaFileObject> wrapped = new ArrayList<JavaFileObject>();
aoqi@0 412 for (JavaFileObject fo : list)
aoqi@0 413 wrapped.add(wrap(fo));
aoqi@0 414 return Collections.unmodifiableList(wrapped);
aoqi@0 415 }
aoqi@0 416
aoqi@0 417 JavaFileObject unwrap(JavaFileObject fo) {
aoqi@0 418 if (fo instanceof UserFileObject)
aoqi@0 419 return ((UserFileObject) fo).unwrap();
aoqi@0 420 else
aoqi@0 421 return fo;
aoqi@0 422 }
aoqi@0 423 }
aoqi@0 424
aoqi@0 425 static class UserFileObject extends ForwardingJavaFileObject<JavaFileObject> {
aoqi@0 426 Method method;
aoqi@0 427
aoqi@0 428 UserFileObject(Method m, JavaFileObject delegate) {
aoqi@0 429 super(delegate);
aoqi@0 430 assert isDeclaredIn(m, FileObject.class, JavaFileObject.class);
aoqi@0 431 this.method = m;
aoqi@0 432 }
aoqi@0 433
aoqi@0 434 JavaFileObject unwrap() {
aoqi@0 435 return fileObject;
aoqi@0 436 }
aoqi@0 437
aoqi@0 438 @Override
aoqi@0 439 public Kind getKind() {
aoqi@0 440 throwUserExceptionIfNeeded(method, "getKind");
aoqi@0 441 return super.getKind();
aoqi@0 442 }
aoqi@0 443
aoqi@0 444 @Override
aoqi@0 445 public boolean isNameCompatible(String simpleName, Kind kind) {
aoqi@0 446 throwUserExceptionIfNeeded(method, "isNameCompatible");
aoqi@0 447 return super.isNameCompatible(simpleName, kind);
aoqi@0 448 }
aoqi@0 449
aoqi@0 450 @Override
aoqi@0 451 public NestingKind getNestingKind() {
aoqi@0 452 throwUserExceptionIfNeeded(method, "getNestingKind");
aoqi@0 453 return super.getNestingKind();
aoqi@0 454 }
aoqi@0 455
aoqi@0 456 @Override
aoqi@0 457 public Modifier getAccessLevel() {
aoqi@0 458 throwUserExceptionIfNeeded(method, "getAccessLevel");
aoqi@0 459 return super.getAccessLevel();
aoqi@0 460 }
aoqi@0 461
aoqi@0 462 @Override
aoqi@0 463 public URI toUri() {
aoqi@0 464 throwUserExceptionIfNeeded(method, "toUri");
aoqi@0 465 return super.toUri();
aoqi@0 466 }
aoqi@0 467
aoqi@0 468 @Override
aoqi@0 469 public String getName() {
aoqi@0 470 throwUserExceptionIfNeeded(method, "getName");
aoqi@0 471 return super.getName();
aoqi@0 472 }
aoqi@0 473
aoqi@0 474 @Override
aoqi@0 475 public InputStream openInputStream() throws IOException {
aoqi@0 476 throwUserExceptionIfNeeded(method, "openInputStream");
aoqi@0 477 return super.openInputStream();
aoqi@0 478 }
aoqi@0 479
aoqi@0 480 @Override
aoqi@0 481 public OutputStream openOutputStream() throws IOException {
aoqi@0 482 throwUserExceptionIfNeeded(method, "openOutputStream");
aoqi@0 483 return super.openOutputStream();
aoqi@0 484 }
aoqi@0 485
aoqi@0 486 @Override
aoqi@0 487 public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
aoqi@0 488 throwUserExceptionIfNeeded(method, "openReader");
aoqi@0 489 return super.openReader(ignoreEncodingErrors);
aoqi@0 490 }
aoqi@0 491
aoqi@0 492 @Override
aoqi@0 493 public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
aoqi@0 494 throwUserExceptionIfNeeded(method, "getCharContent");
aoqi@0 495 return super.getCharContent(ignoreEncodingErrors);
aoqi@0 496 }
aoqi@0 497
aoqi@0 498 @Override
aoqi@0 499 public Writer openWriter() throws IOException {
aoqi@0 500 throwUserExceptionIfNeeded(method, "openWriter");
aoqi@0 501 return super.openWriter();
aoqi@0 502 }
aoqi@0 503
aoqi@0 504 @Override
aoqi@0 505 public long getLastModified() {
aoqi@0 506 throwUserExceptionIfNeeded(method, "getLastModified");
aoqi@0 507 return super.getLastModified();
aoqi@0 508 }
aoqi@0 509
aoqi@0 510 @Override
aoqi@0 511 public boolean delete() {
aoqi@0 512 throwUserExceptionIfNeeded(method, "delete");
aoqi@0 513 return super.delete();
aoqi@0 514 }
aoqi@0 515
aoqi@0 516 }
aoqi@0 517
aoqi@0 518 static class UserProcessor extends JavacTestingAbstractProcessor {
aoqi@0 519 Method method;
aoqi@0 520
aoqi@0 521 UserProcessor(Method m) {
aoqi@0 522 assert isDeclaredIn(m, Processor.class);
aoqi@0 523 method = m;
aoqi@0 524 }
aoqi@0 525
aoqi@0 526 @Override
aoqi@0 527 public Set<String> getSupportedOptions() {
aoqi@0 528 throwUserExceptionIfNeeded(method, "getSupportedOptions");
aoqi@0 529 return super.getSupportedOptions();
aoqi@0 530 }
aoqi@0 531
aoqi@0 532 @Override
aoqi@0 533 public Set<String> getSupportedAnnotationTypes() {
aoqi@0 534 throwUserExceptionIfNeeded(method, "getSupportedAnnotationTypes");
aoqi@0 535 return super.getSupportedAnnotationTypes();
aoqi@0 536 }
aoqi@0 537
aoqi@0 538 @Override
aoqi@0 539 public SourceVersion getSupportedSourceVersion() {
aoqi@0 540 throwUserExceptionIfNeeded(method, "getSupportedSourceVersion");
aoqi@0 541 return super.getSupportedSourceVersion();
aoqi@0 542 }
aoqi@0 543
aoqi@0 544 @Override
aoqi@0 545 public void init(ProcessingEnvironment processingEnv) {
aoqi@0 546 throwUserExceptionIfNeeded(method, "init");
aoqi@0 547 super.init(processingEnv);
aoqi@0 548 }
aoqi@0 549
aoqi@0 550 @Override
aoqi@0 551 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
aoqi@0 552 throwUserExceptionIfNeeded(method, "process");
aoqi@0 553 return true;
aoqi@0 554 }
aoqi@0 555
aoqi@0 556 @Override
aoqi@0 557 public Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
aoqi@0 558 throwUserExceptionIfNeeded(method, "getCompletions");
aoqi@0 559 return super.getCompletions(element, annotation, member, userText);
aoqi@0 560 }
aoqi@0 561 }
aoqi@0 562
aoqi@0 563 static class UserDiagnosticListener implements DiagnosticListener<JavaFileObject> {
aoqi@0 564 Method method;
aoqi@0 565 PrintWriter out;
aoqi@0 566
aoqi@0 567 UserDiagnosticListener(Method m, PrintWriter out) {
aoqi@0 568 assert isDeclaredIn(m, DiagnosticListener.class);
aoqi@0 569 this.method = m;
aoqi@0 570 this.out = out;
aoqi@0 571 }
aoqi@0 572
aoqi@0 573 @Override
aoqi@0 574 public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
aoqi@0 575 throwUserExceptionIfNeeded(method, "report");
aoqi@0 576 out.println("report: " + diagnostic);
aoqi@0 577 }
aoqi@0 578 }
aoqi@0 579
aoqi@0 580 static class UserTaskListener implements TaskListener {
aoqi@0 581 Method method;
aoqi@0 582 PrintWriter out;
aoqi@0 583
aoqi@0 584 UserTaskListener(Method m, PrintWriter out) {
aoqi@0 585 assert isDeclaredIn(m, TaskListener.class);
aoqi@0 586 this.method = m;
aoqi@0 587 this.out = out;
aoqi@0 588 }
aoqi@0 589
aoqi@0 590 @Override
aoqi@0 591 public void started(TaskEvent e) {
aoqi@0 592 throwUserExceptionIfNeeded(method, "started");
aoqi@0 593 out.println("started: " + e);
aoqi@0 594 }
aoqi@0 595
aoqi@0 596 @Override
aoqi@0 597 public void finished(TaskEvent e) {
aoqi@0 598 throwUserExceptionIfNeeded(method, "finished");
aoqi@0 599 out.println("finished: " + e);
aoqi@0 600 }
aoqi@0 601 }
aoqi@0 602
aoqi@0 603 // </editor-fold>
aoqi@0 604 }

mercurial