705N/A/*
931N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
705N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
705N/A *
705N/A * This code is free software; you can redistribute it and/or modify it
705N/A * under the terms of the GNU General Public License version 2 only, as
705N/A * published by the Free Software Foundation.
705N/A *
705N/A * This code is distributed in the hope that it will be useful, but WITHOUT
705N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
705N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
705N/A * version 2 for more details (a copy is included in the LICENSE file that
705N/A * accompanied this code).
705N/A *
705N/A * You should have received a copy of the GNU General Public License version
705N/A * 2 along with this work; if not, write to the Free Software Foundation,
705N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
705N/A *
705N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
705N/A * or visit www.oracle.com if you need additional information or have any
705N/A * questions.
705N/A */
705N/A
705N/A/*
705N/A * @test
705N/A * @bug 6988836
705N/A * @summary A new JavacElements is created for each round of annotation processing
705N/A * @library ../../../lib
705N/A * @build JavacTestingAbstractProcessor TestContext
705N/A * @compile/process -processor TestContext -XprintRounds TestContext
705N/A */
705N/A
705N/Aimport java.io.*;
705N/Aimport java.util.*;
705N/Aimport javax.annotation.processing.*;
705N/Aimport javax.lang.model.element.*;
705N/Aimport static javax.tools.Diagnostic.Kind.*;
705N/A
705N/Aimport com.sun.source.util.Trees;
705N/Aimport com.sun.tools.javac.api.JavacTrees;
705N/Aimport com.sun.tools.javac.model.JavacElements;
705N/Aimport com.sun.tools.javac.model.JavacTypes;
705N/Aimport com.sun.tools.javac.processing.JavacProcessingEnvironment;
705N/Aimport com.sun.tools.javac.util.Context;
705N/A
705N/Apublic class TestContext extends JavacTestingAbstractProcessor {
705N/A
705N/A Trees treeUtils;
705N/A int round = 0;
705N/A
705N/A @Override
705N/A public void init(ProcessingEnvironment pEnv) {
705N/A super.init(pEnv);
705N/A treeUtils = Trees.instance(processingEnv);
705N/A }
705N/A
705N/A @Override
705N/A public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
705N/A round++;
705N/A
705N/A JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
705N/A Context c = jpe.getContext();
705N/A check(c.get(JavacElements.class), eltUtils);
705N/A check(c.get(JavacTypes.class), typeUtils);
705N/A check(c.get(JavacTrees.class), treeUtils);
705N/A
705N/A final int MAXROUNDS = 3;
705N/A if (round < MAXROUNDS)
705N/A generateSource("Gen" + round);
705N/A
705N/A return true;
705N/A }
705N/A
705N/A <T> void check(T actual, T expected) {
705N/A// messager.printMessage(NOTE, "expect: " + expected);
705N/A// messager.printMessage(NOTE, "actual: " + actual);
705N/A
705N/A if (actual != expected) {
705N/A messager.printMessage(ERROR,
705N/A "round " + round + " unexpected value for " + expected.getClass().getName() + ": " + actual);
705N/A }
705N/A }
705N/A
705N/A void generateSource(String name) {
705N/A String text = "class " + name + " { }\n";
705N/A
705N/A try (Writer out = filer.createSourceFile(name).openWriter()) {
705N/A out.write(text);
705N/A } catch (IOException e) {
705N/A throw new Error(e);
705N/A }
705N/A }
705N/A
705N/A}
705N/A