8223942: Missing methods in ClientCodeWrapper$WrappedJavaFileManager
Reviewed-by: jjg
This commit is contained in:
parent
bacc6655b8
commit
d69bc696f2
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -46,6 +46,7 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
@ -417,6 +418,17 @@ public class ClientCodeWrapper {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return wrappedToString(getClass(), clientJavaFileManager);
|
return wrappedToString(getClass(), clientJavaFileManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override @DefinedBy(Api.COMPILER)
|
||||||
|
public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException {
|
||||||
|
try {
|
||||||
|
return clientJavaFileManager.getServiceLoader(location, service);
|
||||||
|
} catch (ClientCodeException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (RuntimeException | Error e) {
|
||||||
|
throw new ClientCodeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class WrappedStandardJavaFileManager extends WrappedJavaFileManager
|
protected class WrappedStandardJavaFileManager extends WrappedJavaFileManager
|
||||||
@ -568,6 +580,18 @@ public class ClientCodeWrapper {
|
|||||||
throw new ClientCodeException(e);
|
throw new ClientCodeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override @DefinedBy(Api.COMPILER)
|
||||||
|
public void setLocationForModule(Location location, String moduleName, Collection<? extends Path> paths) throws IOException {
|
||||||
|
try {
|
||||||
|
System.out.println("invoking wrapped setLocationForModule");
|
||||||
|
((StandardJavaFileManager)clientJavaFileManager).setLocationForModule(location, moduleName, paths);
|
||||||
|
} catch (ClientCodeException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (RuntimeException | Error e) {
|
||||||
|
throw new ClientCodeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class WrappedFileObject implements FileObject {
|
protected class WrappedFileObject implements FileObject {
|
||||||
|
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019, 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 8223942
|
||||||
|
* @summary Missing methods in ClientCodeWrapper$WrappedJavaFileManager
|
||||||
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
|
* jdk.compiler/com.sun.tools.javac.util
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
import javax.tools.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import com.sun.tools.javac.api.JavacTaskImpl;
|
||||||
|
|
||||||
|
public class ClientCodeWrappersShouldOverrideAllMethodsTest {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ClientCodeWrappersShouldOverrideAllMethodsTest clientCodeWrappersShouldOverrideAllMethodsTest = new ClientCodeWrappersShouldOverrideAllMethodsTest();
|
||||||
|
clientCodeWrappersShouldOverrideAllMethodsTest.testWrappersForJavaFileManager();
|
||||||
|
clientCodeWrappersShouldOverrideAllMethodsTest.testWrappersForStandardJavaFileManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
void testWrappersForJavaFileManager() {
|
||||||
|
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||||
|
StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, StandardCharsets.UTF_8);
|
||||||
|
UserFileManager fileManager = new UserFileManager(standardFileManager);
|
||||||
|
JavacTaskImpl task = (JavacTaskImpl)compiler.getTask(null, fileManager, null, null, null, null);
|
||||||
|
JavaFileManager wrappedFM = task.getContext().get(JavaFileManager.class);
|
||||||
|
checkAllMethodsOverridenInWrapperClass(wrappedFM.getClass(), JavaFileManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testWrappersForStandardJavaFileManager() {
|
||||||
|
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||||
|
StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, StandardCharsets.UTF_8);
|
||||||
|
UserStandardJavaFileManager fileManager = new UserStandardJavaFileManager(standardFileManager);
|
||||||
|
JavacTaskImpl task = (JavacTaskImpl)compiler.getTask(null, fileManager, null, null, null, null);
|
||||||
|
JavaFileManager wrappedFM = task.getContext().get(JavaFileManager.class);
|
||||||
|
checkAllMethodsOverridenInWrapperClass(wrappedFM.getClass(), StandardJavaFileManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkAllMethodsOverridenInWrapperClass(Class<?> subClass, Class<?> superClass) {
|
||||||
|
Method[] allMethods = subClass.getMethods();
|
||||||
|
for (Method m : allMethods) {
|
||||||
|
if (m.getDeclaringClass() == superClass) {
|
||||||
|
throw new AssertionError(String.format("method %s not overriden by javac provided wrapper class", m.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class UserFileManager extends ForwardingJavaFileManager<JavaFileManager> {
|
||||||
|
UserFileManager(JavaFileManager delegate) {
|
||||||
|
super(delegate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class UserStandardJavaFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> implements StandardJavaFileManager {
|
||||||
|
StandardJavaFileManager delegate;
|
||||||
|
|
||||||
|
UserStandardJavaFileManager(StandardJavaFileManager delegate) {
|
||||||
|
super(delegate);
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<? extends File> getLocation(Location location) { return delegate.getLocation(location);}
|
||||||
|
|
||||||
|
public void setLocation(Location location, Iterable<? extends File> files) throws IOException {
|
||||||
|
delegate.setLocation(location, files);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
|
||||||
|
return delegate.getJavaFileObjects(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
|
||||||
|
return delegate.getJavaFileObjectsFromStrings(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
|
||||||
|
return delegate.getJavaFileObjectsFromFiles(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
|
||||||
|
return delegate.getJavaFileObjects(files);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user