Warn5.java revision 891
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6993978
* @summary Project Coin: Annotation to reduce varargs warnings
* @author mcimadamore
* @run main Warn5
*/
public class Warn5 {
enum XlintOption {
NONE("none"),
ALL("all");
}
String getXlintOption() {
return "-Xlint:" + opt;
}
}
enum TrustMe {
DONT_TRUST(""),
TRUST("@java.lang.SafeVarargs");
}
}
enum SuppressLevel {
NONE,
return this == VARARGS ?
"@SuppressWarnings(\"varargs\")" :
"";
}
}
enum ModifierKind {
NONE(""),
FINAL("final"),
STATIC("static");
}
}
enum MethodKind {
METHOD("void m"),
CONSTRUCTOR("Test");
}
}
enum SourceLevel {
JDK_6("6"),
JDK_7("7");
}
}
enum SignatureKind {
VARARGS_X("#K <X>#N(X... x)", false, true),
VARARGS_STRING("#K #N(String... x)", true, true),
ARRAY_X("#K <X>#N(X[] x)", false, false),
ARRAY_STRING("#K #N(String[] x)", true, false);
boolean isReifiableArg;
boolean isVarargs;
this.isReifiableArg = isReifiableArg;
}
}
}
enum BodyKind {
ASSIGN("Object o = x;", true),
CAST("Object o = (Object)x;", true),
METH("test(x);", true),
PRINT("System.out.println(x.toString());", false),
ARRAY_ASSIGN("Object[] o = x;", true),
ARRAY_CAST("Object[] o = (Object[])x;", true),
ARRAY_METH("testArr(x);", true);
boolean hasAliasing;
this.hasAliasing = hasAliasing;
}
}
static class JavaSource extends SimpleJavaFileObject {
"import java.util.List;\n" +
"class Test {\n" +
" static void test(Object o) {}\n" +
" static void testArr(Object[] o) {}\n" +
" #T \n #S #M { #B }\n" +
"}\n";
}
return source;
}
}
sig,
body);
}
}
}
}
}
}
}
}
}
// Create a single file manager and reuse it for each compile to save time.
static void test(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel,
Arrays.asList(xlint.getXlintOption(), "-source", sourceLevel.sourceKey), null, Arrays.asList(source));
}
(methKind == MethodKind.CONSTRUCTOR || (methKind == MethodKind.METHOD && modKind != ModifierKind.NONE));
!meth.isReifiableArg &&
throw new Error("invalid diagnostics for source:\n" +
source.getCharContent(true) +
"\nExpected potentially unsafe body warning: " + hasPotentiallyUnsafeBody +
"\nExpected potentially polluting decl warning: " + hasPotentiallyPollutingDecl +
"\nExpected malformed anno error: " + hasMalformedAnnoInDecl +
"\nExpected redundant anno warning: " + hasRedundantAnnoInDecl +
}
}
boolean hasPotentiallyUnsafeBody = false;
boolean hasPotentiallyPollutingDecl = false;
boolean hasMalformedAnnoInDecl = false;
boolean hasRedundantAnnoInDecl = false;
hasPotentiallyUnsafeBody = true;
hasRedundantAnnoInDecl = true;
}
hasPotentiallyPollutingDecl = true;
hasMalformedAnnoInDecl = true;
}
}
}
}