@Test public void testGetJavaFileForOutput() throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, null); try (MemoryFileManager memoryFileManager = new MemoryFileManager(standardFileManager, null)) { JavaFileObject javaFileObject = memoryFileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, "XXX", JavaFileObject.Kind.CLASS, null); assertThat(javaFileObject).isInstanceOf(MemoryFileManager.ClassMemoryJavaFileObject.class); String name = memoryFileManager.inferBinaryName(StandardLocation.CLASS_OUTPUT, javaFileObject); assertThat(name).isEqualTo(javaFileObject.getName()); } }
@Override public JavaFileObject getJavaFileForOutput( JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { if (kind == JavaFileObject.Kind.CLASS) { ClassMemoryJavaFileObject file = new ClassMemoryJavaFileObject(className); mapNameToClasses.put(className, file); return file; } return super.getJavaFileForOutput(location, className, kind, sibling); }
MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> { @Override public JavaFileObject getJavaFileForOutput( JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { if (kind == JavaFileObject.Kind.CLASS) { ClassMemoryJavaFileObject file = new ClassMemoryJavaFileObject(className); mapNameToClasses.put(className, file); return file; } return super.getJavaFileForOutput(location, className, kind, sibling); } }
MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> { @Override public JavaFileObject getJavaFileForOutput( JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { if (kind == JavaFileObject.Kind.CLASS) { ClassMemoryJavaFileObject file = new ClassMemoryJavaFileObject(className); mapNameToClasses.put(className, file); return file; } return super.getJavaFileForOutput(location, className, kind, sibling); } MemoryFileManager(JavaFileManager fileManager, ClassLoader parentClassLoader); }
MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> { @Override public JavaFileObject getJavaFileForOutput( JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { if (kind == JavaFileObject.Kind.CLASS) { ClassMemoryJavaFileObject file = new ClassMemoryJavaFileObject(className); mapNameToClasses.put(className, file); return file; } return super.getJavaFileForOutput(location, className, kind, sibling); } MemoryFileManager(JavaFileManager fileManager, ClassLoader parentClassLoader); JavaFileObject createSourceFileObject(Object origin, String name, String code); ClassLoader getClassLoader(JavaFileManager.Location location); @Override Iterable<JavaFileObject> list(
            JavaFileManager.Location location,
            String packageName,
            Set<JavaFileObject.Kind> kinds,
            boolean recurse); @Override String inferBinaryName(JavaFileManager.Location location, JavaFileObject file); @Override JavaFileObject getJavaFileForOutput(
            JavaFileManager.Location location,
            String className,
            JavaFileObject.Kind kind,
            FileObject sibling); }
MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> { @Override public JavaFileObject getJavaFileForOutput( JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { if (kind == JavaFileObject.Kind.CLASS) { ClassMemoryJavaFileObject file = new ClassMemoryJavaFileObject(className); mapNameToClasses.put(className, file); return file; } return super.getJavaFileForOutput(location, className, kind, sibling); } MemoryFileManager(JavaFileManager fileManager, ClassLoader parentClassLoader); JavaFileObject createSourceFileObject(Object origin, String name, String code); ClassLoader getClassLoader(JavaFileManager.Location location); @Override Iterable<JavaFileObject> list(
            JavaFileManager.Location location,
            String packageName,
            Set<JavaFileObject.Kind> kinds,
            boolean recurse); @Override String inferBinaryName(JavaFileManager.Location location, JavaFileObject file); @Override JavaFileObject getJavaFileForOutput(
            JavaFileManager.Location location,
            String className,
            JavaFileObject.Kind kind,
            FileObject sibling);  }