author | jjg |
Thu, 10 Jun 2010 16:08:01 -0700 | |
changeset 5847 | 1908176fd6e3 |
parent 5846 | 6df0e6bcb388 |
child 7643 | a067a0cda531 |
permissions | -rw-r--r-- |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
1 |
/* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
4 |
* |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
8 |
* |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
13 |
* accompanied this code). |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
14 |
* |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
18 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
21 |
* questions. |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
22 |
*/ |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
23 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
24 |
/** |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
25 |
* @test |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
26 |
* @bug 6945418 |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
27 |
* @summary Project Coin: Simplified Varargs Method Invocation |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
28 |
* @author mcimadamore |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
29 |
* @run main Warn4 |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
30 |
*/ |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
31 |
import com.sun.source.util.JavacTask; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
32 |
import java.net.URI; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
33 |
import java.util.Arrays; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
34 |
import java.util.Set; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
35 |
import java.util.HashSet; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
36 |
import javax.tools.Diagnostic; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
37 |
import javax.tools.JavaCompiler; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
38 |
import javax.tools.JavaFileObject; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
39 |
import javax.tools.SimpleJavaFileObject; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
40 |
import javax.tools.ToolProvider; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
41 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
42 |
public class Warn4 { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
43 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
44 |
final static Warning[] error = null; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
45 |
final static Warning[] none = new Warning[] {}; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
46 |
final static Warning[] vararg = new Warning[] { Warning.VARARGS }; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
47 |
final static Warning[] unchecked = new Warning[] { Warning.UNCHECKED }; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
48 |
final static Warning[] both = new Warning[] { Warning.VARARGS, Warning.UNCHECKED }; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
49 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
50 |
enum Warning { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
51 |
UNCHECKED("unchecked"), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
52 |
VARARGS("varargs"); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
53 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
54 |
String category; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
55 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
56 |
Warning(String category) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
57 |
this.category = category; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
58 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
59 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
60 |
boolean isEnabled(XlintOption xlint, SuppressLevel suppressLevel) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
61 |
return Arrays.asList(xlint.enabledWarnings).contains(this); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
62 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
63 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
64 |
boolean isSuppressed(SuppressLevel suppressLevel) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
65 |
return Arrays.asList(suppressLevel.suppressedWarnings).contains(VARARGS); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
66 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
67 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
68 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
69 |
enum XlintOption { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
70 |
NONE(), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
71 |
UNCHECKED(Warning.UNCHECKED), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
72 |
VARARGS(Warning.VARARGS), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
73 |
ALL(Warning.UNCHECKED, Warning.VARARGS); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
74 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
75 |
Warning[] enabledWarnings; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
76 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
77 |
XlintOption(Warning... enabledWarnings) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
78 |
this.enabledWarnings = enabledWarnings; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
79 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
80 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
81 |
String getXlintOption() { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
82 |
StringBuilder buf = new StringBuilder(); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
83 |
String sep = ""; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
84 |
for (Warning w : enabledWarnings) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
85 |
buf.append(sep); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
86 |
buf.append(w.category); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
87 |
sep=","; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
88 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
89 |
return "-Xlint:" + |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
90 |
(this == NONE ? "none" : buf.toString()); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
91 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
92 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
93 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
94 |
enum SuppressLevel { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
95 |
NONE(), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
96 |
UNCHECKED(Warning.UNCHECKED), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
97 |
VARARGS(Warning.VARARGS), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
98 |
ALL(Warning.UNCHECKED, Warning.VARARGS); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
99 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
100 |
Warning[] suppressedWarnings; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
101 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
102 |
SuppressLevel(Warning... suppressedWarnings) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
103 |
this.suppressedWarnings = suppressedWarnings; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
104 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
105 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
106 |
String getSuppressAnnotation() { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
107 |
StringBuilder buf = new StringBuilder(); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
108 |
String sep = ""; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
109 |
for (Warning w : suppressedWarnings) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
110 |
buf.append(sep); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
111 |
buf.append("\""); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
112 |
buf.append(w.category); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
113 |
buf.append("\""); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
114 |
sep=","; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
115 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
116 |
return this == NONE ? "" : |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
117 |
"@SuppressWarnings({" + buf.toString() + "})"; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
118 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
119 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
120 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
121 |
enum Signature { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
122 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
123 |
EXTENDS_TVAR("<Z> void #name(List<? extends Z>#arity arg) { #body }", |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
124 |
new Warning[][] {both, both, both, both, error, both, both, both, error}), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
125 |
SUPER_TVAR("<Z> void #name(List<? super Z>#arity arg) { #body }", |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
126 |
new Warning[][] {error, both, error, both, error, error, both, both, error}), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
127 |
UNBOUND("void #name(List<?>#arity arg) { #body }", |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
128 |
new Warning[][] {none, none, none, none, none, none, none, none, error}), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
129 |
INVARIANT_TVAR("<Z> void #name(List<Z>#arity arg) { #body }", |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
130 |
new Warning[][] {both, both, both, both, error, both, both, both, error}), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
131 |
TVAR("<Z> void #name(Z#arity arg) { #body }", |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
132 |
new Warning[][] {both, both, both, both, both, both, both, both, vararg}), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
133 |
EXTENDS("void #name(List<? extends String>#arity arg) { #body }", |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
134 |
new Warning[][] {error, error, error, error, error, both, error, both, error}), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
135 |
SUPER("void #name(List<? super String>#arity arg) { #body }", |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
136 |
new Warning[][] {error, error, error, error, error, error, both, both, error}), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
137 |
INVARIANT("void #name(List<String>#arity arg) { #body }", |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
138 |
new Warning[][] {error, error, error, error, error, error, error, both, error}), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
139 |
UNPARAMETERIZED("void #name(String#arity arg) { #body }", |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
140 |
new Warning[][] {error, error, error, error, error, error, error, error, none}); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
141 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
142 |
String template; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
143 |
Warning[][] warnings; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
144 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
145 |
Signature(String template, Warning[][] warnings) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
146 |
this.template = template; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
147 |
this.warnings = warnings; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
148 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
149 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
150 |
boolean isApplicableTo(Signature other) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
151 |
return warnings[other.ordinal()] != null; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
152 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
153 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
154 |
boolean giveUnchecked(Signature other) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
155 |
return warnings[other.ordinal()] == unchecked || |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
156 |
warnings[other.ordinal()] == both; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
157 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
158 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
159 |
boolean giveVarargs(Signature other) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
160 |
return warnings[other.ordinal()] == vararg || |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
161 |
warnings[other.ordinal()] == both; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
162 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
163 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
164 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
165 |
public static void main(String... args) throws Exception { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
166 |
for (XlintOption xlint : XlintOption.values()) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
167 |
for (SuppressLevel suppressLevel : SuppressLevel.values()) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
168 |
for (Signature vararg_meth : Signature.values()) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
169 |
for (Signature client_meth : Signature.values()) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
170 |
if (vararg_meth.isApplicableTo(client_meth)) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
171 |
test(xlint, |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
172 |
suppressLevel, |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
173 |
vararg_meth, |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
174 |
client_meth); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
175 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
176 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
177 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
178 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
179 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
180 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
181 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
182 |
static void test(XlintOption xlint, SuppressLevel suppressLevel, |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
183 |
Signature vararg_meth, Signature client_meth) throws Exception { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
184 |
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
185 |
JavaSource source = new JavaSource(suppressLevel, vararg_meth, client_meth); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
186 |
DiagnosticChecker dc = new DiagnosticChecker(); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
187 |
JavacTask ct = (JavacTask)tool.getTask(null, null, dc, |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
188 |
Arrays.asList(xlint.getXlintOption()), null, Arrays.asList(source)); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
189 |
ct.generate(); //to get mandatory notes |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
190 |
check(dc.warnings, |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
191 |
dc.notes, |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
192 |
new boolean[] {vararg_meth.giveUnchecked(client_meth), |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
193 |
vararg_meth.giveVarargs(client_meth)}, |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
194 |
source, xlint, suppressLevel); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
195 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
196 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
197 |
static void check(Set<Warning> warnings, Set<Warning> notes, boolean[] warnArr, JavaSource source, XlintOption xlint, SuppressLevel suppressLevel) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
198 |
boolean badOutput = false; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
199 |
for (Warning wkind : Warning.values()) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
200 |
badOutput |= (warnArr[wkind.ordinal()] && !wkind.isSuppressed(suppressLevel)) != |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
201 |
(wkind.isEnabled(xlint, suppressLevel) ? |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
202 |
warnings.contains(wkind) : |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
203 |
notes.contains(wkind)); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
204 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
205 |
if (badOutput) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
206 |
throw new Error("invalid diagnostics for source:\n" + |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
207 |
source.getCharContent(true) + |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
208 |
"\nOptions: " + xlint.getXlintOption() + |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
209 |
"\nExpected unchecked warning: " + warnArr[0] + |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
210 |
"\nExpected unsafe vararg warning: " + warnArr[1] + |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
211 |
"\nWarnings: " + warnings + |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
212 |
"\nNotes: " + notes); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
213 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
214 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
215 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
216 |
static class JavaSource extends SimpleJavaFileObject { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
217 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
218 |
String source; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
219 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
220 |
public JavaSource(SuppressLevel suppressLevel, Signature vararg_meth, Signature client_meth) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
221 |
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
222 |
String meth1 = vararg_meth.template.replace("#arity", "..."); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
223 |
meth1 = meth1.replace("#name", "m"); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
224 |
meth1 = meth1.replace("#body", ""); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
225 |
meth1 = suppressLevel.getSuppressAnnotation() + meth1; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
226 |
String meth2 = client_meth.template.replace("#arity", ""); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
227 |
meth2 = meth2.replace("#name", "test"); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
228 |
meth2 = meth2.replace("#body", "m(arg);"); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
229 |
source = "import java.util.List;\n" + |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
230 |
"class Test {\n" + meth1 + |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
231 |
"\n" + meth2 + "\n}\n"; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
232 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
233 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
234 |
@Override |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
235 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
236 |
return source; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
237 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
238 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
239 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
240 |
static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
241 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
242 |
Set<Warning> warnings = new HashSet<>(); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
243 |
Set<Warning> notes = new HashSet<>(); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
244 |
|
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
245 |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
246 |
if (diagnostic.getKind() == Diagnostic.Kind.MANDATORY_WARNING || |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
247 |
diagnostic.getKind() == Diagnostic.Kind.WARNING) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
248 |
warnings.add(diagnostic.getCode().contains("varargs") ? |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
249 |
Warning.VARARGS : |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
250 |
Warning.UNCHECKED); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
251 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
252 |
else if (diagnostic.getKind() == Diagnostic.Kind.NOTE) { |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
253 |
notes.add(diagnostic.getCode().contains("varargs") ? |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
254 |
Warning.VARARGS : |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
255 |
Warning.UNCHECKED); |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
256 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
257 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
258 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
diff
changeset
|
259 |
} |