@Test public void testList() throws IOException, ClassNotFoundException { 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); Iterable<JavaFileObject> result = memoryFileManager.list( StandardLocation.CLASS_OUTPUT, "", new HashSet<>(Arrays.asList(JavaFileObject.Kind.CLASS)), true); assertThat(result).containsExactly(javaFileObject); } }
@Override public Iterable<JavaFileObject> list( JavaFileManager.Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException { Iterable<JavaFileObject> list = super.list(location, packageName, kinds, recurse); if (location == CLASS_OUTPUT) { Collection<? extends JavaFileObject> generatedClasses = memoryClasses(); return () -> new CompositeIterator<JavaFileObject>( list.iterator(), generatedClasses.iterator()); } return list; }
MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> { @Override public Iterable<JavaFileObject> list( JavaFileManager.Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException { Iterable<JavaFileObject> list = super.list(location, packageName, kinds, recurse); if (location == CLASS_OUTPUT) { Collection<? extends JavaFileObject> generatedClasses = memoryClasses(); return () -> new CompositeIterator<JavaFileObject>( list.iterator(), generatedClasses.iterator()); } return list; } }
MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> { @Override public Iterable<JavaFileObject> list( JavaFileManager.Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException { Iterable<JavaFileObject> list = super.list(location, packageName, kinds, recurse); if (location == CLASS_OUTPUT) { Collection<? extends JavaFileObject> generatedClasses = memoryClasses(); return () -> new CompositeIterator<JavaFileObject>( list.iterator(), generatedClasses.iterator()); } return list; } MemoryFileManager(JavaFileManager fileManager, ClassLoader parentClassLoader); }
MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> { @Override public Iterable<JavaFileObject> list( JavaFileManager.Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException { Iterable<JavaFileObject> list = super.list(location, packageName, kinds, recurse); if (location == CLASS_OUTPUT) { Collection<? extends JavaFileObject> generatedClasses = memoryClasses(); return () -> new CompositeIterator<JavaFileObject>( list.iterator(), generatedClasses.iterator()); } return list; } 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 Iterable<JavaFileObject> list( JavaFileManager.Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException { Iterable<JavaFileObject> list = super.list(location, packageName, kinds, recurse); if (location == CLASS_OUTPUT) { Collection<? extends JavaFileObject> generatedClasses = memoryClasses(); return () -> new CompositeIterator<JavaFileObject>( list.iterator(), generatedClasses.iterator()); } return list; } 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);  }