mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 10:34:38 +02:00
8073844: fatal annotation processing errors do not stop compilation
JavacProcessingEnvironment lets the should-stop policy decide when the compilation should stop. Reviewed-by: jjg
This commit is contained in:
parent
c58a8aae3e
commit
279b6faa56
5 changed files with 76 additions and 6 deletions
|
@ -1336,7 +1336,6 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||||
|
|
||||||
errorStatus = errorStatus || (compiler.errorCount() > 0);
|
errorStatus = errorStatus || (compiler.errorCount() > 0);
|
||||||
|
|
||||||
if (!errorStatus)
|
|
||||||
round.finalCompiler();
|
round.finalCompiler();
|
||||||
|
|
||||||
if (newSourceFiles.size() > 0)
|
if (newSourceFiles.size() > 0)
|
||||||
|
@ -1350,10 +1349,8 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||||
if (!taskListener.isEmpty())
|
if (!taskListener.isEmpty())
|
||||||
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
|
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
|
||||||
|
|
||||||
if (errorStatus) {
|
if (errorStatus && compiler.errorCount() == 0) {
|
||||||
if (compiler.errorCount() == 0)
|
|
||||||
compiler.log.nerrors++;
|
compiler.log.nerrors++;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compiler.enterTreesIfNeeded(roots);
|
compiler.enterTreesIfNeeded(roots);
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8073844
|
||||||
|
* @summary If an error is produced by an annotation processor, the code should not be Attred, \
|
||||||
|
* unless requested
|
||||||
|
* @modules jdk.compiler
|
||||||
|
* @compile StopAfterError.java
|
||||||
|
* @compile/fail/ref=StopAfterError.out -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java
|
||||||
|
* @compile/fail/ref=StopAfterError.out -XDshould-stop.ifError=PROCESS -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java
|
||||||
|
* @compile/fail/ref=StopAfterErrorContinue.out -XDshould-stop.ifError=ATTR -XDrawDiagnostics -processor StopAfterError StopAfterErrorAux.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.processing.AbstractProcessor;
|
||||||
|
import javax.annotation.processing.RoundEnvironment;
|
||||||
|
import javax.annotation.processing.SupportedAnnotationTypes;
|
||||||
|
import javax.lang.model.SourceVersion;
|
||||||
|
import javax.lang.model.element.TypeElement;
|
||||||
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
|
||||||
|
@SupportedAnnotationTypes("*")
|
||||||
|
public class StopAfterError extends AbstractProcessor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||||
|
if (roundEnv.processingOver()) {
|
||||||
|
processingEnv.getMessager().printMessage(Kind.ERROR, "Stop!");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SourceVersion getSupportedSourceVersion() {
|
||||||
|
return SourceVersion.latestSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
- compiler.err.proc.messager: Stop!
|
||||||
|
1 error
|
|
@ -0,0 +1,6 @@
|
||||||
|
/* /nodynamiccopyright/ */
|
||||||
|
class StopAfterErrorAux {
|
||||||
|
public void test() {
|
||||||
|
should not; get here;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
- compiler.err.proc.messager: Stop!
|
||||||
|
StopAfterErrorAux.java:4:9: compiler.err.cant.resolve.location: kindname.class, should, , , (compiler.misc.location: kindname.class, StopAfterErrorAux, null)
|
||||||
|
StopAfterErrorAux.java:4:21: compiler.err.cant.resolve.location: kindname.class, get, , , (compiler.misc.location: kindname.class, StopAfterErrorAux, null)
|
||||||
|
3 errors
|
Loading…
Add table
Add a link
Reference in a new issue