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