test/tools/javac/file/T7068437.java

Fri, 08 Feb 2013 09:12:37 +0000

author
vromero
date
Fri, 08 Feb 2013 09:12:37 +0000
changeset 1555
762d0af062f5
parent 0
959103a6100f
permissions
-rw-r--r--

7166455: javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
Reviewed-by: mcimadamore

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
aoqi@0 25 * @test
aoqi@0 26 * @bug 7068437
aoqi@0 27 * @summary Filer.getResource(SOURCE_OUTPUT, ...) no longer works in JDK 7 w/o -s
aoqi@0 28 */
aoqi@0 29
aoqi@0 30 import java.io.FileNotFoundException;
aoqi@0 31 import java.io.IOException;
aoqi@0 32 import java.io.Writer;
aoqi@0 33 import java.util.Arrays;
aoqi@0 34 import java.util.Collections;
aoqi@0 35 import java.util.Map;
aoqi@0 36 import java.util.Set;
aoqi@0 37 import javax.annotation.processing.AbstractProcessor;
aoqi@0 38 import javax.annotation.processing.Filer;
aoqi@0 39 import javax.annotation.processing.Messager;
aoqi@0 40 import javax.annotation.processing.RoundEnvironment;
aoqi@0 41 import javax.annotation.processing.SupportedAnnotationTypes;
aoqi@0 42 import javax.annotation.processing.SupportedOptions;
aoqi@0 43 import javax.annotation.processing.SupportedSourceVersion;
aoqi@0 44 import javax.lang.model.SourceVersion;
aoqi@0 45 import javax.lang.model.element.TypeElement;
aoqi@0 46 import javax.tools.Diagnostic.Kind;
aoqi@0 47 import javax.tools.JavaCompiler;
aoqi@0 48 import javax.tools.JavaCompiler.CompilationTask;
aoqi@0 49 import javax.tools.StandardLocation;
aoqi@0 50 import javax.tools.ToolProvider;
aoqi@0 51
aoqi@0 52 public class T7068437 {
aoqi@0 53 public static void main(String[] args) throws Exception {
aoqi@0 54 new T7068437().run();
aoqi@0 55 }
aoqi@0 56
aoqi@0 57 void run() throws Exception {
aoqi@0 58 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
aoqi@0 59 System.err.println("using " + compiler.getClass()
aoqi@0 60 + " from " + compiler.getClass().getProtectionDomain().getCodeSource());
aoqi@0 61
aoqi@0 62 CompilationTask task = compiler.getTask(null, null, null,
aoqi@0 63 Collections.singleton("-proc:only"),
aoqi@0 64 Collections.singleton("java.lang.Object"),
aoqi@0 65 null);
aoqi@0 66 task.setProcessors(Collections.singleton(new Proc()));
aoqi@0 67 check("compilation", task.call());
aoqi@0 68
aoqi@0 69 task = compiler.getTask(null, null, null,
aoqi@0 70 Arrays.asList("-proc:only", "-AexpectFile"),
aoqi@0 71 Collections.singleton("java.lang.Object"),
aoqi@0 72 null);
aoqi@0 73 task.setProcessors(Collections.singleton(new Proc()));
aoqi@0 74 check("compilation", task.call());
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 void check(String msg, boolean ok) {
aoqi@0 78 System.err.println(msg + ": " + (ok ? "ok" : "failed"));
aoqi@0 79 if (!ok)
aoqi@0 80 throw new AssertionError(msg);
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 @SupportedAnnotationTypes("*")
aoqi@0 84 @SupportedOptions("expectFile")
aoqi@0 85 private static class Proc extends AbstractProcessor {
aoqi@0 86 int count;
aoqi@0 87
aoqi@0 88 @Override
aoqi@0 89 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
aoqi@0 90 if (roundEnv.processingOver() || count++ > 0) {
aoqi@0 91 return false;
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 Filer filer = processingEnv.getFiler();
aoqi@0 95 Messager messager = processingEnv.getMessager();
aoqi@0 96 Map<String, String> options = processingEnv.getOptions();
aoqi@0 97 System.err.println(options);
aoqi@0 98 boolean expectFile = options.containsKey("expectFile");
aoqi@0 99
aoqi@0 100 System.err.println("running Proc: expectFile=" + expectFile);
aoqi@0 101
aoqi@0 102 boolean found;
aoqi@0 103 try {
aoqi@0 104 messager.printMessage(Kind.NOTE, "found previous content of length " +
aoqi@0 105 filer.getResource(StandardLocation.SOURCE_OUTPUT, "p", "C.java").getCharContent(false).length());
aoqi@0 106 found = true;
aoqi@0 107 } catch (FileNotFoundException x) {
aoqi@0 108 messager.printMessage(Kind.NOTE, "not previously there");
aoqi@0 109 found = false;
aoqi@0 110 } catch (IOException x) {
aoqi@0 111 messager.printMessage(Kind.ERROR, "while reading: " + x);
aoqi@0 112 found = false;
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 if (expectFile && !found) {
aoqi@0 116 messager.printMessage(Kind.ERROR, "expected file but file not found");
aoqi@0 117 }
aoqi@0 118
aoqi@0 119 try {
aoqi@0 120 Writer w = filer.createSourceFile("p.C").openWriter();
aoqi@0 121 w.write("/* hello! */ package p; class C {}");
aoqi@0 122 w.close();
aoqi@0 123 messager.printMessage(Kind.NOTE, "wrote new content");
aoqi@0 124 } catch (IOException x) {
aoqi@0 125 messager.printMessage(Kind.ERROR, "while writing: " + x);
aoqi@0 126 }
aoqi@0 127
aoqi@0 128 return true;
aoqi@0 129 }
aoqi@0 130
aoqi@0 131 @Override
aoqi@0 132 public SourceVersion getSupportedSourceVersion() {
aoqi@0 133 return SourceVersion.latest();
aoqi@0 134 }
aoqi@0 135 }
aoqi@0 136 }

mercurial