langtools/test/tools/javac/T6873849.java
author jjg
Fri, 21 Aug 2009 11:25:45 -0700
changeset 3660 ee583c342a41
child 5520 86e4b9a9da40
permissions -rw-r--r--
6873849: suppress notes generated by javac Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3660
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
     1
/*
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
     2
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
     4
 *
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
     8
 *
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    13
 * accompanied this code).
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    14
 *
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    18
 *
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    21
 * have any questions.
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    22
 */
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    23
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    24
import java.io.File;
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    25
import java.io.PrintWriter;
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    26
import java.io.StringWriter;
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    27
import java.util.ArrayList;
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    28
import java.util.List;
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    29
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    30
/*
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    31
 * @test
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    32
 * @bug 6873849
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    33
 * @summary suppress notes generated by javac
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    34
 */
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    35
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    36
public class T6873849 {
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    37
    public static void main(String... args) throws Exception {
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    38
        new T6873849().run();
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    39
    }
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    40
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    41
    public void run() throws Exception {
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    42
        test(null, "- compiler.note.unchecked.filename: T6873849.java" + newline +
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    43
                    "- compiler.note.unchecked.recompile" + newline);
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    44
        test("-XDsuppressNotes", "");
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    45
    }
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    46
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    47
    void test(String opt, String expect) throws Exception {
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    48
        List<String> args = new ArrayList<String>();
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    49
        if (opt != null)
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    50
            args.add(opt);
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    51
        args.add("-d");
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    52
        args.add(testClasses.getPath());
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    53
        args.add("-XDrawDiagnostics");
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    54
        args.add(new File(testSrc, "T6873849.java").getPath());
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    55
        StringWriter sw = new StringWriter();
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    56
        PrintWriter pw = new PrintWriter(sw);
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    57
        System.err.println("compile: " + args);
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    58
        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    59
        pw.close();
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    60
        String out = sw.toString();
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    61
        System.out.println(out);
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    62
        if (rc != 0)
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    63
            throw new Exception("compilation failed unexpectedly");
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    64
        if (!out.equals(expect))
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    65
            throw new Exception("unexpected output from compiler");
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    66
    }
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    67
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    68
    void m(List t) {
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    69
        // force a note about unchecked usage
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    70
        t.add(new Object());
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    71
    }
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    72
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    73
    private File testSrc = new File(System.getProperty("test.src", "."));
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    74
    private File testClasses = new File(System.getProperty("test.classes", "."));
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    75
    private String newline = System.getProperty("line.separator");
ee583c342a41 6873849: suppress notes generated by javac
jjg
parents:
diff changeset
    76
}