Wed, 24 Sep 2014 11:38:26 -0700
Added tag jdk8u40-b07 for changeset 2fa3858a281f
duke@1 | 1 | /* |
jjg@1064 | 2 | * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. |
duke@1 | 8 | * |
duke@1 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 13 | * accompanied this code). |
duke@1 | 14 | * |
duke@1 | 15 | * You should have received a copy of the GNU General Public License version |
duke@1 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
duke@1 | 22 | */ |
duke@1 | 23 | |
duke@1 | 24 | /* |
duke@1 | 25 | * @test |
duke@1 | 26 | * @bug 6403468 |
duke@1 | 27 | * @summary Test that an erroneous return code results from raising an error. |
duke@1 | 28 | * @author Joseph D. Darcy |
darcy@1466 | 29 | * @library /tools/javac/lib |
jjg@1064 | 30 | * @build JavacTestingAbstractProcessor CompileFail |
duke@1 | 31 | * @compile TestReturnCode.java |
duke@1 | 32 | * |
jjg@1064 | 33 | * @compile -processor TestReturnCode -proc:only Foo.java |
jjg@1064 | 34 | * @run main CompileFail ERROR -processor TestReturnCode -proc:only -AErrorOnFirst Foo.java |
jjg@1064 | 35 | * @run main CompileFail ERROR -processor TestReturnCode -proc:only -AErrorOnLast Foo.java |
jjg@1064 | 36 | * @run main CompileFail ERROR -processor TestReturnCode -proc:only -AErrorOnLast -AErrorOnFirst Foo.java |
jjg@1064 | 37 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst Foo.java |
jjg@1064 | 38 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnFirst Foo.java |
jjg@1064 | 39 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnLast Foo.java |
jjg@1064 | 40 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnFirst -AErrorOnLast -AErrorOnFirst Foo.java |
jjg@1064 | 41 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast Foo.java |
jjg@1064 | 42 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnFirst Foo.java |
jjg@1064 | 43 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnLast Foo.java |
jjg@1064 | 44 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AErrorOnLast -AErrorOnFirst Foo.java |
jjg@1064 | 45 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst Foo.java |
jjg@1064 | 46 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnFirst Foo.java |
jjg@1064 | 47 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnLast Foo.java |
jjg@1064 | 48 | * @run main CompileFail SYSERR -processor TestReturnCode -proc:only -AExceptionOnLast -AExceptionOnFirst -AErrorOnLast -AErrorOnFirst Foo.java |
duke@1 | 49 | */ |
duke@1 | 50 | |
duke@1 | 51 | import java.util.Set; |
duke@1 | 52 | import java.util.HashSet; |
duke@1 | 53 | import java.util.Arrays; |
duke@1 | 54 | import javax.annotation.processing.*; |
duke@1 | 55 | import javax.lang.model.SourceVersion; |
duke@1 | 56 | import javax.lang.model.element.*; |
duke@1 | 57 | import javax.lang.model.util.*; |
duke@1 | 58 | import static javax.tools.Diagnostic.Kind.*; |
duke@1 | 59 | |
duke@1 | 60 | |
duke@1 | 61 | /** |
duke@1 | 62 | * This processor raises errors or throws exceptions on different |
duke@1 | 63 | * rounds to allow the return code to be test. |
duke@1 | 64 | */ |
duke@1 | 65 | @SupportedOptions({"ErrorOnFirst", |
duke@1 | 66 | "ErrorOnLast", |
duke@1 | 67 | "ExceptionOnFirst", |
duke@1 | 68 | "ExceptionOnLast"}) |
darcy@699 | 69 | public class TestReturnCode extends JavacTestingAbstractProcessor { |
duke@1 | 70 | |
duke@1 | 71 | private boolean errorOnFirst; |
duke@1 | 72 | private boolean errorOnLast; |
duke@1 | 73 | private boolean exceptionOnFirst; |
duke@1 | 74 | private boolean exceptionOnLast; |
duke@1 | 75 | |
duke@1 | 76 | public boolean process(Set<? extends TypeElement> annotations, |
duke@1 | 77 | RoundEnvironment roundEnv) { |
duke@1 | 78 | if (!roundEnv.processingOver()) { |
duke@1 | 79 | System.out.format("Variables: %b\t%b\t%b\t%b%n", |
duke@1 | 80 | errorOnFirst, |
duke@1 | 81 | errorOnLast, |
duke@1 | 82 | exceptionOnFirst, |
duke@1 | 83 | exceptionOnLast); |
duke@1 | 84 | if (errorOnFirst) |
duke@1 | 85 | messager.printMessage(ERROR, "Error on first round."); |
duke@1 | 86 | if (exceptionOnFirst) |
duke@1 | 87 | throw new RuntimeException("Exception on first round."); |
duke@1 | 88 | } else { |
duke@1 | 89 | if (errorOnLast) |
duke@1 | 90 | messager.printMessage(ERROR, "Error on last round."); |
duke@1 | 91 | if (exceptionOnLast) |
duke@1 | 92 | throw new RuntimeException("Exception on last round."); |
duke@1 | 93 | } |
duke@1 | 94 | return true; |
duke@1 | 95 | } |
duke@1 | 96 | |
duke@1 | 97 | @Override |
duke@1 | 98 | public void init(ProcessingEnvironment processingEnv) { |
duke@1 | 99 | super.init(processingEnv); |
duke@1 | 100 | Set<String> keySet = processingEnv.getOptions().keySet(); |
duke@1 | 101 | errorOnFirst = keySet.contains("ErrorOnFirst"); |
duke@1 | 102 | errorOnLast = keySet.contains("ErrorOnLast"); |
duke@1 | 103 | exceptionOnFirst = keySet.contains("ExceptionOnFirst"); |
duke@1 | 104 | exceptionOnLast = keySet.contains("ExceptionOnLast"); |
duke@1 | 105 | } |
duke@1 | 106 | } |