source: trunk/openjdk/langtools/test/tools/javac/T6410706.java

Last change on this file was 278, checked in by dmik, 14 years ago

trunk: Merged in openjdk6 b22 from branches/vendor/oracle.

File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2006, 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 */
23
24/*
25 * @test
26 * @bug 6410706
27 * @summary CONFORMANCE Mandatory warnings in Tree API
28 */
29
30import java.io.File;
31import java.io.IOException;
32import java.util.Arrays;
33import javax.tools.Diagnostic;
34import javax.tools.DiagnosticListener;
35import javax.tools.JavaFileObject;
36import javax.tools.StandardJavaFileManager;
37import javax.tools.StandardLocation;
38import com.sun.source.util.JavacTask;
39import com.sun.tools.javac.api.JavacTool;
40
41public class T6410706 {
42 public static void main(String... args) throws IOException {
43 String testSrc = System.getProperty("test.src", ".");
44 String testClasses = System.getProperty("test.classes", ".");
45 JavacTool tool = JavacTool.create();
46 MyDiagListener dl = new MyDiagListener();
47 StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
48 fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
49 Iterable<? extends JavaFileObject> files =
50 fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
51 JavacTask task = tool.getTask(null, fm, dl, null, null, files);
52 task.parse();
53 task.analyze();
54 task.generate();
55
56 // expect 2 notes:
57 // Note: T6410706.java uses or overrides a deprecated API.
58 // Note: Recompile with -Xlint:deprecation for details.
59
60 if (dl.notes != 2)
61 throw new AssertionError(dl.notes + " notes given");
62 }
63
64 private static class MyDiagListener implements DiagnosticListener<JavaFileObject>
65 {
66 public void report(Diagnostic d) {
67 System.err.println(d);
68 if (d.getKind() == Diagnostic.Kind.NOTE)
69 notes++;
70 }
71
72 int notes;
73 }
74
75 Foo foo; // should generate deprecation warning
76}
77
78@Deprecated class Foo { }
Note: See TracBrowser for help on using the repository browser.