|
1 /* |
|
2 * Copyright (c) 2019, 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 8223942 |
|
27 * @summary Missing methods in ClientCodeWrapper$WrappedJavaFileManager |
|
28 * @modules jdk.compiler/com.sun.tools.javac.api |
|
29 * jdk.compiler/com.sun.tools.javac.util |
|
30 */ |
|
31 |
|
32 import java.lang.reflect.*; |
|
33 import java.io.*; |
|
34 |
|
35 import javax.tools.*; |
|
36 import java.nio.charset.StandardCharsets; |
|
37 import com.sun.tools.javac.api.JavacTaskImpl; |
|
38 |
|
39 public class ClientCodeWrappersShouldOverrideAllMethodsTest { |
|
40 public static void main(String[] args) { |
|
41 ClientCodeWrappersShouldOverrideAllMethodsTest clientCodeWrappersShouldOverrideAllMethodsTest = new ClientCodeWrappersShouldOverrideAllMethodsTest(); |
|
42 clientCodeWrappersShouldOverrideAllMethodsTest.testWrappersForJavaFileManager(); |
|
43 clientCodeWrappersShouldOverrideAllMethodsTest.testWrappersForStandardJavaFileManager(); |
|
44 } |
|
45 |
|
46 void testWrappersForJavaFileManager() { |
|
47 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
|
48 StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, StandardCharsets.UTF_8); |
|
49 UserFileManager fileManager = new UserFileManager(standardFileManager); |
|
50 JavacTaskImpl task = (JavacTaskImpl)compiler.getTask(null, fileManager, null, null, null, null); |
|
51 JavaFileManager wrappedFM = task.getContext().get(JavaFileManager.class); |
|
52 checkAllMethodsOverridenInWrapperClass(wrappedFM.getClass(), JavaFileManager.class); |
|
53 } |
|
54 |
|
55 void testWrappersForStandardJavaFileManager() { |
|
56 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
|
57 StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, StandardCharsets.UTF_8); |
|
58 UserStandardJavaFileManager fileManager = new UserStandardJavaFileManager(standardFileManager); |
|
59 JavacTaskImpl task = (JavacTaskImpl)compiler.getTask(null, fileManager, null, null, null, null); |
|
60 JavaFileManager wrappedFM = task.getContext().get(JavaFileManager.class); |
|
61 checkAllMethodsOverridenInWrapperClass(wrappedFM.getClass(), StandardJavaFileManager.class); |
|
62 } |
|
63 |
|
64 void checkAllMethodsOverridenInWrapperClass(Class<?> subClass, Class<?> superClass) { |
|
65 Method[] allMethods = subClass.getMethods(); |
|
66 for (Method m : allMethods) { |
|
67 if (m.getDeclaringClass() == superClass) { |
|
68 throw new AssertionError(String.format("method %s not overriden by javac provided wrapper class", m.getName())); |
|
69 } |
|
70 } |
|
71 } |
|
72 |
|
73 static class UserFileManager extends ForwardingJavaFileManager<JavaFileManager> { |
|
74 UserFileManager(JavaFileManager delegate) { |
|
75 super(delegate); |
|
76 } |
|
77 } |
|
78 |
|
79 static class UserStandardJavaFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> implements StandardJavaFileManager { |
|
80 StandardJavaFileManager delegate; |
|
81 |
|
82 UserStandardJavaFileManager(StandardJavaFileManager delegate) { |
|
83 super(delegate); |
|
84 this.delegate = delegate; |
|
85 } |
|
86 |
|
87 public Iterable<? extends File> getLocation(Location location) { return delegate.getLocation(location);} |
|
88 |
|
89 public void setLocation(Location location, Iterable<? extends File> files) throws IOException { |
|
90 delegate.setLocation(location, files); |
|
91 } |
|
92 |
|
93 public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) { |
|
94 return delegate.getJavaFileObjects(names); |
|
95 } |
|
96 |
|
97 public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) { |
|
98 return delegate.getJavaFileObjectsFromStrings(names); |
|
99 } |
|
100 |
|
101 public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) { |
|
102 return delegate.getJavaFileObjectsFromFiles(files); |
|
103 } |
|
104 |
|
105 public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { |
|
106 return delegate.getJavaFileObjects(files); |
|
107 } |
|
108 } |
|
109 } |