4632N/A/*
4632N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/A/*
4632N/A * @test
4632N/A * @bug 6935638
4632N/A * @summary -implicit:none prevents compilation with annotation processing
4632N/A */
4632N/A
4632N/Aimport java.io.*;
4632N/Aimport java.util.*;
4632N/Aimport javax.annotation.processing.*;
4632N/Aimport javax.lang.model.*;
4632N/Aimport javax.lang.model.element.*;
4632N/A
4632N/A
4632N/A@SupportedAnnotationTypes("*")
4632N/Apublic class TestImplicitNone extends AbstractProcessor {
4632N/A public static void main(String... args) throws Exception {
4632N/A new TestImplicitNone().run();
4632N/A }
4632N/A
4632N/A void run() throws Exception {
4632N/A File classesDir = new File("tmp", "classes");
4632N/A classesDir.mkdirs();
4632N/A File test_java = new File(new File("tmp", "src"), "Test.java");
4632N/A writeFile(test_java, "class Test { }");
4632N/A
4632N/A // build up list of options and files to be compiled
4632N/A List<String> opts = new ArrayList<String>();
4632N/A List<File> files = new ArrayList<File>();
4632N/A
4632N/A opts.add("-d");
4632N/A opts.add(classesDir.getPath());
4632N/A opts.add("-processorpath");
4632N/A opts.add(System.getProperty("test.classes"));
4632N/A opts.add("-implicit:none");
4632N/A opts.add("-processor");
4632N/A opts.add(TestImplicitNone.class.getName());
4632N/A files.add(test_java);
4632N/A
4632N/A compile(opts, files);
4632N/A
4632N/A File test_class = new File(classesDir, "Test.class");
4632N/A if (!test_class.exists())
4632N/A throw new Exception("Test.class not generated");
4632N/A }
4632N/A
4632N/A /** Compile files with options provided. */
4632N/A void compile(List<String> opts, List<File> files) throws Exception {
4632N/A System.err.println("javac: " + opts + " " + files);
4632N/A List<String> args = new ArrayList<String>();
4632N/A args.addAll(opts);
4632N/A for (File f: files)
4632N/A args.add(f.getPath());
4632N/A StringWriter sw = new StringWriter();
4632N/A PrintWriter pw = new PrintWriter(sw);
4632N/A int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
4632N/A pw.flush();
4632N/A if (sw.getBuffer().length() > 0)
4632N/A System.err.println(sw.toString());
4632N/A if (rc != 0)
4632N/A throw new Exception("compilation failed: rc=" + rc);
4632N/A }
4632N/A
4632N/A /** Write a file with a given body. */
4632N/A void writeFile(File f, String body) throws Exception {
4632N/A if (f.getParentFile() != null)
4632N/A f.getParentFile().mkdirs();
4632N/A Writer out = new FileWriter(f);
4632N/A try {
4632N/A out.write(body);
4632N/A } finally {
4632N/A out.close();
4632N/A }
4632N/A }
4632N/A
4632N/A //----- annotation processor methods -----
4632N/A
4632N/A public boolean process(Set<? extends TypeElement> annotations,
4632N/A RoundEnvironment roundEnv) {
4632N/A return true;
4632N/A }
4632N/A
4632N/A @Override
4632N/A public SourceVersion getSupportedSourceVersion() {
4632N/A return SourceVersion.latest();
4632N/A }
4632N/A}
4632N/A