langtools/test/tools/javac/processing/StopAfterError/StopAfterError.java
author jlahoda
Tue, 04 Oct 2016 17:40:29 +0200
changeset 41255 72fcbd6294cb
child 43646 017aba6e9260
permissions -rw-r--r--
8073844: fatal annotation processing errors do not stop compilation Summary: JavacProcessingEnvironment lets the should-stop policy decide when the compilation should stop. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41255
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
     1
/*
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
     4
 *
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
     8
 *
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    14
 *
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    18
 *
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    21
 * questions.
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    22
 */
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    23
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    24
/*
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    25
 * @test
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    26
 * @bug 8073844
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    27
 * @summary If an error is produced by an annotation processor, the code should not be Attred, \
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    28
 *          unless requested
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    29
 * @modules jdk.compiler
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    30
 * @compile StopAfterError.java
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    31
 * @compile/fail/ref=StopAfterError.out -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    32
 * @compile/fail/ref=StopAfterError.out -XDshould-stop.ifError=PROCESS -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    33
 * @compile/fail/ref=StopAfterErrorContinue.out -XDshould-stop.ifError=ATTR -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    34
 */
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    35
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    36
import java.util.Set;
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    37
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    38
import javax.annotation.processing.AbstractProcessor;
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    39
import javax.annotation.processing.RoundEnvironment;
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    40
import javax.annotation.processing.SupportedAnnotationTypes;
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    41
import javax.lang.model.SourceVersion;
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    42
import javax.lang.model.element.TypeElement;
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    43
import javax.tools.Diagnostic.Kind;
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    44
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    45
@SupportedAnnotationTypes("*")
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    46
public class StopAfterError extends AbstractProcessor {
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    47
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    48
    @Override
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    49
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    50
        if (roundEnv.processingOver()) {
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    51
            processingEnv.getMessager().printMessage(Kind.ERROR, "Stop!");
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    52
        }
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    53
        return false;
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    54
    }
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    55
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    56
    @Override
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    57
    public SourceVersion getSupportedSourceVersion() {
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    58
        return SourceVersion.latestSupported();
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    59
    }
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    60
72fcbd6294cb 8073844: fatal annotation processing errors do not stop compilation
jlahoda
parents:
diff changeset
    61
}