|
Java example source code file (TestSuppression.java)
The TestSuppression.java Java example source code
/*
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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 6403465
* @summary javac should defer diagnostics until it can be determined they are persistent
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.TypeElement;
import javax.tools.*;
import com.sun.source.util.JavacTask;
import com.sun.tools.javac.api.ClientCodeWrapper;
import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.util.JCDiagnostic;
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
public class TestSuppression {
public static void main(String... args) throws Exception {
new TestSuppression().run(args);
}
enum WarningKind { NO, YES };
String[] cases = {
// missing class C
"class X { C c; }",
"class X { C foo() { return null; } }",
"class X { void foo(C c) { } }",
"class X extends C { }",
"class X<T extends C> { }",
// missing interface I
"class X implements I { }",
"interface X extends I { }",
// missing exception E
"class X { void m() throws E { } }",
// missing method m
"class X extends C { int i = m(); }",
// missing field f
"class X extends C { int i = f; }"
};
void run(String... args) throws Exception {
for (String c: cases) {
for (WarningKind wk: WarningKind.values()) {
for (int g = 1; g <= 3; g++) {
try {
test(c, wk, g);
} catch (Throwable t) {
error("caught: " + t);
}
if (errors > 0) throw new AssertionError();
}
}
}
System.err.println(count + " test cases");
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void test(String src, WarningKind wk, int gen) throws Exception {
count++;
System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" +src);
File testDir = new File("test" + count);
File srcDir = createDir(testDir, "src");
File gensrcDir = createDir(testDir, "gensrc");
File classesDir = createDir(testDir, "classes");
File x = writeFile(new File(srcDir, "X.java"), src);
DiagListener dl = new DiagListener();
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
fm.setLocation(StandardLocation.CLASS_PATH,
Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
List<String> args = new ArrayList
Other Java examples (source code examples)Here is a short list of links related to this Java TestSuppression.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.