6873849: suppress notes generated by javac

Fri, 21 Aug 2009 11:25:45 -0700

author
jjg
date
Fri, 21 Aug 2009 11:25:45 -0700
changeset 376
61c1f735df67
parent 375
2ce3597237f0
child 377
d9febdd5ae21

6873849: suppress notes generated by javac
Reviewed-by: darcy

src/share/classes/com/sun/tools/javac/util/Log.java file | annotate | diff | comparison | revisions
test/tools/javac/T6873849.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Wed Aug 19 17:12:36 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Fri Aug 21 11:25:45 2009 -0700
     1.3 @@ -78,6 +78,10 @@
     1.4       */
     1.5      public boolean emitWarnings;
     1.6  
     1.7 +    /** Switch: suppress note messages.
     1.8 +     */
     1.9 +    public boolean suppressNotes;
    1.10 +
    1.11      /** Print stack trace on errors?
    1.12       */
    1.13      public boolean dumpOnError;
    1.14 @@ -121,6 +125,7 @@
    1.15          this.dumpOnError = options.get("-doe") != null;
    1.16          this.promptOnError = options.get("-prompt") != null;
    1.17          this.emitWarnings = options.get("-Xlint:none") == null;
    1.18 +        this.suppressNotes = options.get("suppressNotes") != null;
    1.19          this.MaxErrors = getIntOption(options, "-Xmaxerrs", 100);
    1.20          this.MaxWarnings = getIntOption(options, "-Xmaxwarns", 100);
    1.21  
    1.22 @@ -324,7 +329,7 @@
    1.23              // Print out notes only when we are permitted to report warnings
    1.24              // Notes are only generated at the end of a compilation, so should be small
    1.25              // in number.
    1.26 -            if (emitWarnings || diagnostic.isMandatory()) {
    1.27 +            if ((emitWarnings || diagnostic.isMandatory()) && !suppressNotes) {
    1.28                  writeDiagnostic(diagnostic);
    1.29              }
    1.30              break;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/T6873849.java	Fri Aug 21 11:25:45 2009 -0700
     2.3 @@ -0,0 +1,76 @@
     2.4 +/*
     2.5 + * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.24 + * have any questions.
    2.25 + */
    2.26 +
    2.27 +import java.io.File;
    2.28 +import java.io.PrintWriter;
    2.29 +import java.io.StringWriter;
    2.30 +import java.util.ArrayList;
    2.31 +import java.util.List;
    2.32 +
    2.33 +/*
    2.34 + * @test
    2.35 + * @bug 6873849
    2.36 + * @summary suppress notes generated by javac
    2.37 + */
    2.38 +
    2.39 +public class T6873849 {
    2.40 +    public static void main(String... args) throws Exception {
    2.41 +        new T6873849().run();
    2.42 +    }
    2.43 +
    2.44 +    public void run() throws Exception {
    2.45 +        test(null, "- compiler.note.unchecked.filename: T6873849.java" + newline +
    2.46 +                    "- compiler.note.unchecked.recompile" + newline);
    2.47 +        test("-XDsuppressNotes", "");
    2.48 +    }
    2.49 +
    2.50 +    void test(String opt, String expect) throws Exception {
    2.51 +        List<String> args = new ArrayList<String>();
    2.52 +        if (opt != null)
    2.53 +            args.add(opt);
    2.54 +        args.add("-d");
    2.55 +        args.add(testClasses.getPath());
    2.56 +        args.add("-XDrawDiagnostics");
    2.57 +        args.add(new File(testSrc, "T6873849.java").getPath());
    2.58 +        StringWriter sw = new StringWriter();
    2.59 +        PrintWriter pw = new PrintWriter(sw);
    2.60 +        System.err.println("compile: " + args);
    2.61 +        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
    2.62 +        pw.close();
    2.63 +        String out = sw.toString();
    2.64 +        System.out.println(out);
    2.65 +        if (rc != 0)
    2.66 +            throw new Exception("compilation failed unexpectedly");
    2.67 +        if (!out.equals(expect))
    2.68 +            throw new Exception("unexpected output from compiler");
    2.69 +    }
    2.70 +
    2.71 +    void m(List t) {
    2.72 +        // force a note about unchecked usage
    2.73 +        t.add(new Object());
    2.74 +    }
    2.75 +
    2.76 +    private File testSrc = new File(System.getProperty("test.src", "."));
    2.77 +    private File testClasses = new File(System.getProperty("test.classes", "."));
    2.78 +    private String newline = System.getProperty("line.separator");
    2.79 +}

mercurial