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

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

mercurial