try { JavaFileObject file = filer.createClassFile(((TypeElement) element).getQualifiedName() + AbstractParserGenerator.CLASS_NAME_SUFFIX, element); final OutputStream out = file.openOutputStream(); try { out.write(newClass); try { JavaFileObject file = filer.createClassFile(((TypeElement) element).getQualifiedName() + AbstractParserGenerator.CLASS_NAME_SUFFIX, element); final OutputStream out = file.openOutputStream(); try { out.write(newClass);
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String qualifiedClassName = toQualifiedClassName(pkg, fileName); LOGGER.debug("Generating class: {}", qualifiedClassName); Element[] classOriginatingElements = originatingElements.getClassOriginatingElements(qualifiedClassName); try { JavaFileObject sourceFile; if (classOriginatingElements.length == 0) { LOGGER.info("Generating class with no originating element: {}", qualifiedClassName); } sourceFile = filer.createSourceFile(qualifiedClassName, classOriginatingElements); return sourceFile.openOutputStream(); } catch (FilerException e) { LOGGER.error("Could not generate source file for {} due to error: {}", qualifiedClassName, e.getMessage()); /* * This exception is expected, when some files are created twice. We cannot * delete existing files, unless using a dirty hack. Files a created twice when * the same file is created from different annotation rounds. Happens when * renaming classes, and for Background executor. It also probably means I * didn't fully understand how annotation processing works. If anyone can point * me out... */ return VOID_OUTPUT_STREAM; } }
/** * Note that none of the parameters are in this method are used. * {@inheritDoc} */ @Override public OutputStream openBinary(final JPackage pkg, final String fileName) throws IOException { this.out = fileObject.openOutputStream(); return out; }
/** * Note that none of the parameters are in this method are used. * {@inheritDoc} */ @Override public OutputStream openBinary(final JPackage pkg, final String fileName) throws IOException { this.out = fileObject.openOutputStream(); return out; }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { this.filer = OperationProcessor.super.processingEnv.getFiler(); if(fileName.endsWith(".java")){ fileName = fileName.substring(0, fileName.length() - ".java".length()); } JavaFileObject sourceFile = this.filer.createSourceFile(pkg.name() + "." + fileName); return sourceFile.openOutputStream(); }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String className = fileName.substring(0, fileName.length() - JAVA_SOURCE_SUFFIX.length()); if (!fileName.endsWith(JAVA_SOURCE_SUFFIX)) throw new IllegalStateException("Unexpected file name passed to code writer: " + fileName); JavaFileObject fileObject = filer.createSourceFile(pkg.name() + "." + className); OutputStream stream = fileObject.openOutputStream(); closeables.add(stream); return stream; }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { outputStream = processingEnv.getFiler().createSourceFile(pkg.name() + "." + StringUtils.removeEnd(fileName, ".java")).openOutputStream(); return outputStream; }
@Override public OutputStream openBinary(JPackage jPackage, String filename) throws IOException { String fullQualifiedClassName = fullyQualifiedClassName(jPackage, filename); JavaFileObject fileObject = filer.createSourceFile(fullQualifiedClassName, originatingElements); outputStream = fileObject.openOutputStream(); return outputStream; }
private void writeSearchIndexFile() throws IOException { Map<String, Object> model = new HashMap<>(); model.put("metaData", searchIndexDeclarations); JavaFileObject sourceFile = filer.createSourceFile(SEARCH_INDEX_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(SEARCH_INDEX_TEMPLATE, model, output); output.flush(); output.close(); }
private void writeBeanFactoryFile() throws Exception { Map<String, Object> model = new HashMap<>(); model.put("extensions", discoveredBeanFactories); model.put("categoryClasses", categoryClasses); JavaFileObject sourceFile = filer.createSourceFile(BEAN_FACTORY_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(BEAN_FACTORY_TEMPLATE, model, output); output.flush(); output.close(); }
private void writeAccessControlFile() throws Exception { Map<String, Object> model = new HashMap<>(); model.put("metaData", requiredResourcesDeclarations); model.put("operations", bootstrapOperations); JavaFileObject sourceFile = filer.createSourceFile(REQUIRED_RESOURCES_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(REQUIRED_RESOURCES_TEMPLATE, model, output); output.flush(); output.close(); }
private void writeRuntimeFile() throws Exception { Map<String, Object> model = new HashMap<>(); model.put("runtimeMenuItemExtensions", runtimeExtensions); JavaFileObject sourceFile = filer.createSourceFile(RUNTIME_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(RUNTIME_TEMPLATE, model, output); output.flush(); output.close(); }
private void writeSubsystemFile() throws Exception{ Map<String, Object> model = new HashMap<>(); model.put("subsystemExtensions", subsystemDeclararions); JavaFileObject sourceFile = filer.createSourceFile(SUBSYSTEM_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(SUBSYSTEM_TEMPLATE, model, output); output.flush(); output.close(); }
private void writeSubsystemFile() throws Exception { Map<String, Object> model = new HashMap<>(); model.put("subsystemExtensions", subsystemDeclararions); JavaFileObject sourceFile = filer.createSourceFile(SUBSYSTEM_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(SUBSYSTEM_TEMPLATE, model, output); output.flush(); output.close(); }
private void writeRuntimeFile() throws Exception { Map<String, Object> model = new HashMap<>(); model.put("runtimeMenuItemExtensions", runtimeExtensions); JavaFileObject sourceFile = filer.createSourceFile(RUNTIME_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(RUNTIME_TEMPLATE, model, output); output.flush(); output.close(); }
private void writeGinjectorFile() throws Exception { Map<String, Object> model = new HashMap<>(); model.put("extensions", discoveredExtensions); JavaFileObject sourceFile = filer.createSourceFile(EXTENSION_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(EXTENSION_TEMPLATE, model, output); output.flush(); output.close(); }
private void writeBeanFactoryFile() throws Exception{ Map<String, Object> model = new HashMap<>(); model.put("extensions", discoveredBeanFactories); model.put("categoryClasses", categoryClasses); JavaFileObject sourceFile = filer.createSourceFile(BEAN_FACTORY_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(BEAN_FACTORY_TEMPLATE, model, output); output.flush(); output.close(); }
private void writeVersionInfo() throws IOException { Map<String, String> options = processingEnv.getOptions(); String version = options.containsKey("version") ? options.get("version") : "n/a"; Map<String, Object> model = new HashMap<String, Object>(); model.put("version", version); JavaFileObject sourceFile = filer.createSourceFile(VERSION_INFO_FILENAME); OutputStream output = sourceFile.openOutputStream(); new TemplateProcessor().process(VERSION_INFO_TEMPLATE, model, output); output.flush(); output.close(); } }
@Override public OutputStream openBinary(JPackage jPackage, String fileName) throws IOException { //generate a source file based on package and fileName String qualified = toQualifiedClassName(jPackage, fileName); JavaFileObject sourceFile = filer.createSourceFile(qualified, originating.getOriginatingElements(qualified)); OutputStream os = sourceFile.openOutputStream(); openStreams.add(os); return os; }
/** * Returns an OutputStream for writing Java source code to be compiled. * * @param qualifiedName The fully qualified name of the class to write. * * @throws IOException */ public OutputStream getToBeCompiledSourceFileStream(String qualifiedName) throws IOException { JavaFileObject jfo = getWritableJavaFileObjectForToBeCompiledSource(qualifiedName); jfo.delete(); return jfo.openOutputStream(); }