Test.java revision 1465:b52a38d4536c
1275970Scy/* 2275970Scy * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3275970Scy * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4275970Scy * 5285612Sdelphij * This code is free software; you can redistribute it and/or modify it 6275970Scy * under the terms of the GNU General Public License version 2 only, as 7275970Scy * published by the Free Software Foundation. 8275970Scy * 9275970Scy * This code is distributed in the hope that it will be useful, but WITHOUT 10275970Scy * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11275970Scy * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12275970Scy * version 2 for more details (a copy is included in the LICENSE file that 13275970Scy * accompanied this code). 14275970Scy * 15275970Scy * You should have received a copy of the GNU General Public License version 16275970Scy * 2 along with this work; if not, write to the Free Software Foundation, 17275970Scy * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18275970Scy * 19275970Scy * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20275970Scy * or visit www.oracle.com if you need additional information or have any 21275970Scy * questions. 22275970Scy */ 23275970Scy 24275970Scy/* 25275970Scy * @test 26275970Scy * @bug 6987384 27275970Scy * @summary -XprintProcessorRoundsInfo message printed with different timing than previous 28275970Scy * @library /tools/javac/lib 29275970Scy * @build JavacTestingAbstractProcessor Test 30275970Scy * @compile/fail/ref=Test.out -XDrawDiagnostics -XprintProcessorInfo -Werror -proc:only -processor Test Test.java 31275970Scy */ 32275970Scy 33275970Scyimport java.io.*; 34275970Scyimport java.util.*; 35275970Scyimport javax.annotation.processing.*; 36275970Scyimport javax.lang.model.*; 37275970Scyimport javax.lang.model.element.*; 38275970Scyimport javax.lang.model.util.*; 39275970Scyimport javax.tools.*; 40275970Scy 41275970Scypublic class Test extends JavacTestingAbstractProcessor { 42275970Scy final int MAX_ROUNDS = 3; 43275970Scy int round = 0; 44275970Scy 45275970Scy @Override 46275970Scy public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 47275970Scy round++; 48275970Scy messager.printMessage(Diagnostic.Kind.NOTE, "round " + round); 49275970Scy if (round <= MAX_ROUNDS) 50275970Scy generateSource("Gen" + round); 51275970Scy if (roundEnv.processingOver()) 52275970Scy messager.printMessage(Diagnostic.Kind.WARNING, "last round"); 53275970Scy return true; 54275970Scy } 55275970Scy 56275970Scy void generateSource(String name) { 57275970Scy String text = "class " + name + " { }\n"; 58 59 // avoid try-with-resources so test can be run on older builds 60 try { 61 Writer out = filer.createSourceFile(name).openWriter(); 62 try { 63 out.write(text); 64 } finally { 65 out.close(); 66 } 67 } catch (IOException e) { 68 throw new Error(e); 69 } 70 } 71} 72 73 74 75