@Test public void testBinaryOriginatingElements() throws Exception { Classpath namingEnvironment = createClasspath(); IErrorHandlingPolicy errorHandlingPolicy = DefaultErrorHandlingPolicies.exitAfterAllProblems(); IProblemFactory problemFactory = ProblemFactory.getProblemFactory(Locale.getDefault()); CompilerOptions compilerOptions = new CompilerOptions(); ICompilerRequestor requestor = null; Compiler compiler = new Compiler(namingEnvironment, errorHandlingPolicy, compilerOptions, requestor, problemFactory); EclipseFileManager fileManager = new EclipseFileManager(null, Charsets.UTF_8); File outputDir = temp.newFolder(); fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outputDir)); CompilerBuildContext context = null; Map<String, String> processorOptions = null; CompilerJdt incrementalCompiler = null; ProcessingEnvImpl env = new ProcessingEnvImpl(context, fileManager, processorOptions, compiler, incrementalCompiler); TypeElement typeElement = env.getElementUtils().getTypeElement("java.lang.Object"); FilerImpl filer = new FilerImpl(null , fileManager, null , null ); filer.createSourceFile("test.Source", typeElement); }
@Override public JavaFileObject createSourceFile(CharSequence name, Element... originatingElements) throws IOException { JavaFileObject sourceFile = fileManager.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null); if (!createdResources.add(sourceFile.toUri())) { throw new FilerException("Attempt to recreate file for type " + name); } return new JavaFileObjectImpl(sourceFile, new FileObjectDelegate() { private boolean closed = false; @Override protected void onClose(Output<File> generatedSource) { if (!closed) { closed = true; CompilationUnit unit = new CompilationUnit(null, generatedSource.getResource().getAbsolutePath(), null ); processingEnv.addNewUnit(unit); incrementalCompiler.addGeneratedSource(generatedSource); } } }); }
FilerImpl implements Filer { @Override public JavaFileObject createSourceFile(CharSequence name, Element... originatingElements) throws IOException { JavaFileObject sourceFile = fileManager.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null); if (!createdResources.add(sourceFile.toUri())) { throw new FilerException("Attempt to recreate file for type " + name); } return new JavaFileObjectImpl(sourceFile, new FileObjectDelegate() { private boolean closed = false; @Override protected void onClose(Output<File> generatedSource) { if (!closed) { closed = true; CompilationUnit unit = new CompilationUnit(null, generatedSource.getResource().getAbsolutePath(), null ); processingEnv.addNewUnit(unit); incrementalCompiler.addGeneratedSource(generatedSource); } } }); } }
FilerImpl implements Filer { @Override public JavaFileObject createSourceFile(CharSequence name, Element... originatingElements) throws IOException { JavaFileObject sourceFile = fileManager.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null); if (!createdResources.add(sourceFile.toUri())) { throw new FilerException("Attempt to recreate file for type " + name); } return new JavaFileObjectImpl(sourceFile, new FileObjectDelegate() { private boolean closed = false; @Override protected void onClose(Output<File> generatedSource) { if (!closed) { closed = true; CompilationUnit unit = new CompilationUnit(null, generatedSource.getResource().getAbsolutePath(), null ); processingEnv.addNewUnit(unit); incrementalCompiler.addGeneratedSource(generatedSource); } } }); } FilerImpl(CompilerBuildContext context, StandardJavaFileManager fileManager, CompilerJdt incrementalCompiler, ProcessingEnvImpl processingEnv); }
FilerImpl implements Filer { @Override public JavaFileObject createSourceFile(CharSequence name, Element... originatingElements) throws IOException { JavaFileObject sourceFile = fileManager.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null); if (!createdResources.add(sourceFile.toUri())) { throw new FilerException("Attempt to recreate file for type " + name); } return new JavaFileObjectImpl(sourceFile, new FileObjectDelegate() { private boolean closed = false; @Override protected void onClose(Output<File> generatedSource) { if (!closed) { closed = true; CompilationUnit unit = new CompilationUnit(null, generatedSource.getResource().getAbsolutePath(), null ); processingEnv.addNewUnit(unit); incrementalCompiler.addGeneratedSource(generatedSource); } } }); } FilerImpl(CompilerBuildContext context, StandardJavaFileManager fileManager, CompilerJdt incrementalCompiler, ProcessingEnvImpl processingEnv); @Override JavaFileObject createSourceFile(CharSequence name, Element... originatingElements); @Override JavaFileObject createClassFile(CharSequence name, Element... originatingElements); @Override FileObject createResource(Location location, CharSequence pkg, CharSequence relativeName, Element... originatingElements); @Override FileObject getResource(Location location, CharSequence pkg, CharSequence relativeName); void incrementalIterationReset(); Set<File> getWrittenFiles(); }
FilerImpl implements Filer { @Override public JavaFileObject createSourceFile(CharSequence name, Element... originatingElements) throws IOException { JavaFileObject sourceFile = fileManager.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null); if (!createdResources.add(sourceFile.toUri())) { throw new FilerException("Attempt to recreate file for type " + name); } return new JavaFileObjectImpl(sourceFile, new FileObjectDelegate() { private boolean closed = false; @Override protected void onClose(Output<File> generatedSource) { if (!closed) { closed = true; CompilationUnit unit = new CompilationUnit(null, generatedSource.getResource().getAbsolutePath(), null ); processingEnv.addNewUnit(unit); incrementalCompiler.addGeneratedSource(generatedSource); } } }); } FilerImpl(CompilerBuildContext context, StandardJavaFileManager fileManager, CompilerJdt incrementalCompiler, ProcessingEnvImpl processingEnv); @Override JavaFileObject createSourceFile(CharSequence name, Element... originatingElements); @Override JavaFileObject createClassFile(CharSequence name, Element... originatingElements); @Override FileObject createResource(Location location, CharSequence pkg, CharSequence relativeName, Element... originatingElements); @Override FileObject getResource(Location location, CharSequence pkg, CharSequence relativeName); void incrementalIterationReset(); Set<File> getWrittenFiles();  }