author | jlahoda |
Fri, 15 Feb 2019 12:09:53 +0100 | |
changeset 53773 | 454d54d8af1c |
permissions | -rw-r--r-- |
53773
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
1 |
/* |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
4 |
* |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
8 |
* |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
14 |
* |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
18 |
* |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
22 |
*/ |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
23 |
|
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
24 |
/* |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
25 |
* @test |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
26 |
* @bug 8217381 |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
27 |
* @summary Check error are convenient when AP generates a source file and |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
28 |
* an error in the same round |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
29 |
* @library /tools/javac/lib |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
30 |
* @modules jdk.compiler |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
31 |
* @build JavacTestingAbstractProcessor GenerateAndError |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
32 |
* @compile/fail/ref=GenerateAndError.out -XDrawDiagnostics -processor GenerateAndError GenerateAndErrorTest.java |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
33 |
*/ |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
34 |
|
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
35 |
import java.io.IOException; |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
36 |
import java.io.Writer; |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
37 |
import java.util.*; |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
38 |
|
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
39 |
import javax.annotation.processing.*; |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
40 |
import javax.lang.model.element.*; |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
41 |
import javax.tools.Diagnostic.Kind; |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
42 |
|
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
43 |
public class GenerateAndError extends JavacTestingAbstractProcessor { |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
44 |
int round = 0; |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
45 |
@Override |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
46 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
47 |
if (round++ == 0) { |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
48 |
try (Writer w = processingEnv.getFiler().createSourceFile("Extra").openWriter()) { |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
49 |
w.write("public class Extra {}"); |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
50 |
} catch (IOException ex) { |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
51 |
throw new IllegalStateException(ex); |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
52 |
} |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
53 |
processingEnv.getMessager().printMessage(Kind.ERROR, "error"); |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
54 |
} |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
55 |
return false; |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
56 |
} |
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
diff
changeset
|
57 |
} |