Mon, 16 Sep 2013 14:13:44 +0200
8021112: Spurious unchecked warning reported by javac
6480588: No way to suppress deprecation warnings when implementing deprecated interface
Summary: Fixing DeferredLintHandler configuration, so lint warnings are reported with correct @SuppressWarnings settings
Reviewed-by: jjg, vromero
1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
24 import java.io.*;
25 import java.lang.reflect.Constructor;
27 /**
28 * Test driver for MethodParameters testing.
29 * <p>
30 * The intended use of this driver is to run it, giving the name of
31 * a single class compiled with -parameters as argument. The driver
32 * will test the specified class, and any nested classes it finds.
33 * <p>
34 * Each class is tested in two way. By refelction, and by directly
35 * checking MethodParameters attributes in the classfile. The checking
36 * is done using two visitor classes {@link ClassFileVisitor} and
37 * {@link ReflectionVisitor}.
38 * <p>
39 * The {@code ReflectionVisitor} test logically belongs with library tests.
40 * we wish to reuse the same test-cases, so both test are committed together,
41 * under langtools. The tests, may be duplicated in the jdk repository.
42 */
43 public class Tester {
45 final static File classesdir = new File(System.getProperty("test.classes", "."));
47 /**
48 * The visitor classes that does the actual checking are referenced
49 * statically, to force compilations, without having to reference
50 * them in individual test cases.
51 * <p>
52 * This makes it easy to change the set of visitors, without
53 * complicating the design with dynamic discovery and compilation
54 * of visitor classes.
55 */
56 static final Class visitors[] = {
57 ClassFileVisitor.class,
58 ReflectionVisitor.class
59 };
61 /**
62 * Test-driver expect a single classname as argument.
63 */
64 public static void main(String... args) throws Exception {
65 if (args.length != 1) {
66 throw new Error("A single class name is expected as argument");
67 }
68 final String pattern = args[0] + ".*\\.class";
69 File files[] = classesdir.listFiles(new FileFilter() {
70 public boolean accept(File f) {
71 return f.getName().matches(pattern);
72 }
73 });
74 if (files.length == 0) {
75 File file = new File(classesdir, args[0] + ".class");
76 throw new Error(file.getPath() + " not found");
77 }
79 new Tester(args[0], files).run();
80 }
82 public Tester(String name, File files[]) {
83 this.classname = name;
84 this.files = files;
85 }
87 void run() throws Exception {
89 // Test with each visitor
90 for (Class<Visitor> vclass : visitors) {
91 try {
92 String vname = vclass.getName();
93 Constructor c = vclass.getConstructor(Tester.class);
95 info("\nRun " + vname + " for " + classname + "\n");
96 StringBuilder sb = new StringBuilder();
97 for (File f : files) {
98 String fname = f.getName();
99 fname = fname.substring(0, fname.length() - 6);
100 Visitor v = (Visitor) c.newInstance(this);
101 try {
102 v.visitClass(fname, f, sb);
103 } catch(Exception e) {
104 error("Uncaught exception in visitClass()");
105 e.printStackTrace();
106 }
107 }
108 info(sb.toString());
109 } catch(ReflectiveOperationException e) {
110 warn("Class " + vclass.getName() + " ignored, not a Visitor");
111 continue;
112 }
113 }
115 if(0 != warnings)
116 System.err.println("Test generated " + warnings + " warnings");
118 if(0 != errors)
119 throw new Exception("Tester test failed with " +
120 errors + " errors");
121 }
123 abstract static class Visitor {
124 Tester tester;
125 File classesdir;
127 public Visitor(Tester tester) {
128 this.tester = tester;
129 }
131 abstract void visitClass(final String classname, final File cfile,
132 final StringBuilder sb) throws Exception;
134 public void error(String msg) {
135 tester.error(msg);
136 }
138 public void warn(String msg) {
139 tester.warn(msg);
140 }
141 }
143 void error(String msg) {
144 System.err.println("Error: " + msg);
145 errors++;
146 }
148 void warn(String msg) {
149 System.err.println("Warning: " + msg);
150 warnings++;
151 }
153 void info(String msg) {
154 System.out.println(msg);
155 }
157 int errors;
158 int warnings;
159 String classname;
160 File files[];
161 }