1/*
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 6987384
27 * @summary -XprintProcessorRoundsInfo message printed with different timing than previous
28 * @library /tools/javac/lib
29 * @modules java.compiler
30 *          jdk.compiler
31 * @build JavacTestingAbstractProcessor Test
32 * @compile/fail/ref=Test.out -XDrawDiagnostics -XprintProcessorInfo -Werror -proc:only -processor Test Test.java
33 */
34
35import java.io.*;
36import java.util.*;
37import javax.annotation.processing.*;
38import javax.lang.model.*;
39import javax.lang.model.element.*;
40import javax.lang.model.util.*;
41import javax.tools.*;
42
43public class Test extends JavacTestingAbstractProcessor {
44    final int MAX_ROUNDS = 3;
45    int round = 0;
46
47    @Override
48    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
49        round++;
50        messager.printMessage(Diagnostic.Kind.NOTE, "round " + round);
51        if (round <= MAX_ROUNDS)
52            generateSource("Gen" + round);
53        if (roundEnv.processingOver())
54            messager.printMessage(Diagnostic.Kind.WARNING, "last round");
55        return true;
56    }
57
58    void generateSource(String name) {
59        String text = "class " + name + " { }\n";
60
61        // avoid try-with-resources so test can be run on older builds
62        try {
63            Writer out = filer.createSourceFile(name).openWriter();
64            try {
65                out.write(text);
66            } finally {
67                out.close();
68            }
69        } catch (IOException e) {
70            throw new Error(e);
71        }
72    }
73}
74
75
76
77