test/tools/javac/api/6731573/T6731573.java

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 554
9d9f26857129
child 1733
e39669aea0bd
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

     1 /*
     2  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug     6731573
    27  * @summary diagnostic output should optionally include source line
    28  * @author  Maurizio Cimadamore
    29  * @library ../lib
    30  */
    32 import java.io.*;
    33 import java.util.*;
    34 import javax.tools.*;
    36 public class T6731573 extends ToolTester {
    38     enum DiagnosticType {
    39         BASIC(null) {
    40             boolean shouldDisplaySource(SourceLine sourceLine) {
    41                 return sourceLine != SourceLine.DISABLED;
    42             }
    43         },
    44         RAW("-XDrawDiagnostics") {
    45             boolean shouldDisplaySource(SourceLine sourceLine) {
    46                 return sourceLine == SourceLine.ENABLED;
    47             }
    48         };
    50         String optValue;
    52         DiagnosticType(String optValue) {
    53             this.optValue = optValue;
    54         }
    56         abstract boolean shouldDisplaySource(SourceLine sourceLine);
    57     }
    59     enum SourceLine {
    60         STANDARD(null),
    61         ENABLED("-XDshowSource=true"),
    62         DISABLED("-XDshowSource=false");
    64         String optValue;
    66         SourceLine(String optValue) {
    67             this.optValue = optValue;
    68         }
    69     }
    71     void checkErrorLine(String output, boolean expected, List<String> options) {
    72         System.err.println("\noptions = "+options);
    73         System.err.println(output);
    74         boolean errLinePresent = output.contains("^");
    75         if (errLinePresent != expected) {
    76             throw new AssertionError("Error in diagnostic: error line" +
    77                     (expected ? "" : " not") + " expected but" +
    78                     (errLinePresent ? "" : " not") + " found");
    79         }
    80     }
    82     void exec(DiagnosticType diagType, SourceLine sourceLine) {
    83         final Iterable<? extends JavaFileObject> compilationUnits =
    84             fm.getJavaFileObjects(new File(test_src, "Erroneous.java"));
    85         StringWriter pw = new StringWriter();
    86         ArrayList<String> options = new ArrayList<String>();
    87         if (diagType.optValue != null)
    88             options.add(diagType.optValue);
    89         if (sourceLine.optValue != null)
    90             options.add(sourceLine.optValue);
    91         task = tool.getTask(pw, fm, null, options, null, compilationUnits);
    92         task.call();
    93         checkErrorLine(pw.toString(),
    94                 diagType.shouldDisplaySource(sourceLine),
    95                 options);
    96     }
    98     void test() {
    99         for (DiagnosticType dt : DiagnosticType.values()) {
   100             for (SourceLine sl : SourceLine.values()) {
   101                 exec(dt, sl);
   102             }
   103         }
   104     }
   106     public static void main(String... args) throws Exception {
   107         new T6731573().test();
   108     }
   109 }

mercurial