本文整理汇总了Java中javax.tools.FileObject.openWriter方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.openWriter方法的具体用法?Java FileObject.openWriter怎么用?Java FileObject.openWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.FileObject
的用法示例。
在下文中一共展示了FileObject.openWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import javax.tools.FileObject; //导入方法依赖的package包/类
/** Emit a class file for a given class.
* @param c The class from which a class file is generated.
*/
public FileObject write(ClassSymbol c)
throws IOException
{
String className = c.flatName().toString();
FileObject outFile
= fileManager.getFileForOutput(StandardLocation.NATIVE_HEADER_OUTPUT,
"", className.replaceAll("[.$]", "_") + ".h", null);
Writer out = outFile.openWriter();
try {
write(out, c);
if (verbose)
log.printVerbose("wrote.file", outFile);
out.close();
out = null;
} finally {
if (out != null) {
// if we are propogating an exception, delete the file
out.close();
outFile.delete();
outFile = null;
}
}
return outFile; // may be null if write failed
}
示例2: outputResults
import javax.tools.FileObject; //导入方法依赖的package包/类
@Override
protected void outputResults() throws IOException {
// Begin writing output file.
FileObject src = createOutputFileObject(OUTPUT_FILE_NAME);
Writer writer = src.openWriter();
writer.write(String.format(OUTPUT_HEADER, YaVersion.YOUNG_ANDROID_VERSION,
YaVersion.BLOCKS_LANGUAGE_VERSION));
// Components are already sorted.
for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
ComponentInfo component = entry.getValue();
outputComponent(writer, component);
}
writer.write(OUTPUT_FOOTER);
// Close output file.
writer.flush();
writer.close();
messager.printMessage(Diagnostic.Kind.NOTE, "Wrote file " + src.toUri());
}
示例3: outputResults
import javax.tools.FileObject; //导入方法依赖的package包/类
@Override
protected void outputResults() throws IOException {
StringBuilder sb = new StringBuilder();
sb.append('[');
String separator = "";
// Components are already sorted.
for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
ComponentInfo component = entry.getValue();
sb.append(separator);
outputComponent(component, sb);
separator = ",\n";
}
sb.append(']');
FileObject src = createOutputFileObject(OUTPUT_FILE_NAME);
Writer writer = src.openWriter();
writer.write(sb.toString());
writer.flush();
writer.close();
messager.printMessage(Diagnostic.Kind.NOTE, "Wrote file " + src.toUri());
}
示例4: outputResults
import javax.tools.FileObject; //导入方法依赖的package包/类
protected final void outputResults() throws IOException {
// Begin writing output file.
FileObject src = createOutputFileObject(OUTPUT_FILE_NAME);
Writer writer = src.openWriter();
// Output table at top showing components by category.
outputCategories(writer);
// Components are already sorted.
for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
ComponentInfo component = entry.getValue();
outputComponent(writer, component);
}
// Close output file
writer.flush();
writer.close();
messager.printMessage(Diagnostic.Kind.NOTE, "Wrote file " + src.toUri());
}
示例5: writeFile
import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeFile(String root, Path mainPath, Path file) {
LOG.debug("Writing file {} relatively to {}", file, mainPath);
Path relativePath = mainPath.relativize(file).getParent();
String packageName = ofNullable(relativePath)
.map(Path::toString)
.map(s -> prefixPackage(root, s))
.orElse(root);
packageName = replace(replace(packageName, "-", "_"), File.pathSeparator, ".");
LOG.debug("Computed package name '{}'", packageName);
FileObject fileObject = fileManager.createResource(packageName, file.getFileName().toString());
try (Writer writer = fileObject.openWriter(); Reader reader = Files.newBufferedReader(file)) {
IOUtils.copy(reader, writer);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例6: write
import javax.tools.FileObject; //导入方法依赖的package包/类
public static void write(ObjectWriter objectWriter, FileObject fileObject, Object object) {
try (Writer writer = fileObject.openWriter()) {
objectWriter.writeValue(writer, object);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例7: generateFile
import javax.tools.FileObject; //导入方法依赖的package包/类
public void generateFile() throws IOException {
FileObject fileObject = filer.createResource(StandardLocation.SOURCE_OUTPUT, "", "em.fragment.bnd");
try (Writer writer = fileObject.openWriter()) {
if (entry != null && !entry.trim().isEmpty()) {
writer.write(entry + "\n");
writer.write("Import-Package: !*");
}
}
}
示例8: generateFile
import javax.tools.FileObject; //导入方法依赖的package包/类
public void generateFile() throws IOException {
FileObject fileObject = filer.createResource(StandardLocation.SOURCE_OUTPUT, "", "em.activator.bnd");
try (Writer writer = fileObject.openWriter()) {
if (activator != null) {
writer.write("Bundle-Activator: " + activator + "\n");
}
if (extensionActivator != null) {
writer.write("ExtensionBundle-Activator: " + extensionActivator + "\n");
}
}
}
示例9: generateClass
import javax.tools.FileObject; //导入方法依赖的package包/类
/**
* Generates the Java source for the target factory.
* The XML representation must be in cache.
* @param ctx
* @throws TransformerException
* @throws IOException
*/
void generateClass(ModelContext ctx) throws TransformerException, IOException {
Transformer transformer = ctx.getTransformerFactory().newTransformer(new StreamSource(getClassTemplate(ctx)));
FileObject fo = ctx.getFiler().createSourceFile(getFullName(), (Element[])null);
PrintWriter out = new PrintWriter(fo.openWriter());
transformer.transform(new DOMSource(getDOM(ctx)), new StreamResult(out));
out.close();
}
示例10: generateClass
import javax.tools.FileObject; //导入方法依赖的package包/类
void generateClass(ModelContext ctx) throws IOException, TransformerException {
Transformer transformer = ctx.getTransformerFactory().newTransformer(new StreamSource(ctx.getLibraryClassTemplate()));
FileObject fo = ctx.getFiler().createSourceFile(fullName, (javax.lang.model.element.Element[])null);
PrintWriter out = new PrintWriter(fo.openWriter());
transformer.transform(new DOMSource(getDOM(ctx, XMLUtils.docBuilder)), new StreamResult(out));
out.close();
}
示例11: generateModule
import javax.tools.FileObject; //导入方法依赖的package包/类
private void generateModule(ModelContext ctx, ModuleModel module) throws IOException, TransformerException {
Transformer transformer = ctx.getTransformerFactory().newTransformer(new StreamSource(ctx.getModuleClassTemplate()));
transformer.setParameter("full-name", module.getFullName());
FileObject fo = ctx.getFiler().createSourceFile(getPackageName() + '.' + prefix + module.getSimpleName(), (Element[])null);
PrintWriter out = new PrintWriter(fo.openWriter());
transformer.transform(new DOMSource(getDOM(ctx)), new StreamResult(out));
out.close();
}
示例12: writeResource
import javax.tools.FileObject; //导入方法依赖的package包/类
/**
* Write <query>.sql to resources folder
*
* @param queryDesc information on query
*/
private void writeResource(QueryDesc queryDesc) {
Filer filer = processingEnv.getFiler();
try {
FileObject o = filer.createResource(StandardLocation.CLASS_OUTPUT,
queryDesc.getPackageName() + ".sql", queryDesc.getMethodNameFirstUpper() + ".sql");
Writer w = o.openWriter();
w.append(queryDesc.getQuery());
w.flush();
w.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例13: writePackageJson
import javax.tools.FileObject; //导入方法依赖的package包/类
private void writePackageJson() throws IOException {
String packageJson = PackageJsonGenerator.packageJsonFor(model.getModuleInfo(), model);
FileObject package_json_file_object = ModuleResourceHelper.createResource(env, model.getModuleInfo(), "package.json");
try (PrintWriter out = new PrintWriterWithLogging(package_json_file_object.openWriter(), "package.json")) {
out.println(packageJson);
}
}
示例14: writeTypes
import javax.tools.FileObject; //导入方法依赖的package包/类
public void writeTypes() throws IOException {
TSModuleInfo module=model.getModuleInfo();
TSNameSpace nameSpace = convertToNameSpace(model.getTsTypesByModule(module));
FileObject dts_file_object = ModuleResourceHelper.createResource(env, module, model.fileByOutputType());
try (PrintWriter out = new PrintWriterWithLogging(dts_file_object.openWriter(), model.fileByOutputType())) {
writeHeader(module, out);
writeUMD(module, out);
writeNamespace(module, nameSpace, out);
}
}
示例15: processClass
import javax.tools.FileObject; //导入方法依赖的package包/类
private void processClass(TypeElement typeElement) {
// Get some metadata about the class to be processed
BundlerClassInfo info = new BundlerClassInfo(typeElement);
// Log a message for each class we process
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,
"[EasyBundler] processing class " + info);
// Create a new Bundler and generate the source
Bundler bundler = new Bundler(processingEnvironment, info);
String javaSource = bundler.getBundlerClassSource();
try {
// Create a source file
FileObject file = processingEnvironment.getFiler()
.createSourceFile(bundler.getQualifiedBundlerClassName(), typeElement);
// Log a note for each class file created
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,
"[EasyBundler] Writing class file " + file.getName());
// Write the generated source
Writer writer = file.openWriter();
writer.write(javaSource);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}