本文整理汇总了Java中javax.tools.JavaFileObject.delete方法的典型用法代码示例。如果您正苦于以下问题:Java JavaFileObject.delete方法的具体用法?Java JavaFileObject.delete怎么用?Java JavaFileObject.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.JavaFileObject
的用法示例。
在下文中一共展示了JavaFileObject.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeClass
import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/**
* Emit a class file for a given class.
*
* @param c The class from which a class file is generated.
*/
public JavaFileObject writeClass(ClassSymbol c)
throws IOException, PoolOverflow, StringOverflow {
JavaFileObject outFile
= fileManager.getJavaFileForOutput(CLASS_OUTPUT,
c.flatname.toString(),
JavaFileObject.Kind.CLASS,
c.sourcefile);
OutputStream out = outFile.openOutputStream();
try {
writeClassFile(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: writeClass
import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/** Emit a class file for a given class.
* @param c The class from which a class file is generated.
*/
public JavaFileObject writeClass(ClassSymbol c)
throws IOException, PoolOverflow, StringOverflow
{
JavaFileObject outFile
= fileManager.getJavaFileForOutput(CLASS_OUTPUT,
c.flatname.toString(),
JavaFileObject.Kind.CLASS,
c.sourcefile);
OutputStream out = outFile.openOutputStream();
try {
writeClassFile(out, c);
if (verbose)
log.printVerbose("wrote.file", outFile);
out.close();
out = null;
} finally {
if (out != null) {
// if we are propagating an exception, delete the file
out.close();
outFile.delete();
outFile = null;
}
}
return outFile; // may be null if write failed
}
示例3: writeJavaFile
import javax.tools.JavaFileObject; //导入方法依赖的package包/类
private boolean writeJavaFile(JavaFile javaFile) {
StringBuilder builder = new StringBuilder();
JavaFileObject filerSourceFile = null;
try {
builder.append(LICENSE_HEADER);
javaFile.writeTo(builder);
String fileName = javaFile.packageName.isEmpty() ? javaFile.typeSpec.name : javaFile.packageName + "." + javaFile.typeSpec.name;
List<Element> originatingElements = javaFile.typeSpec.originatingElements;
filerSourceFile = mFiler.createSourceFile(fileName, originatingElements.toArray(new Element[originatingElements.size()]));
try (Writer writer = filerSourceFile.openWriter()) {
writer.write(builder.toString());
}
return true;
} catch (Exception e) {
mMessager.printMessage(Diagnostic.Kind.ERROR, "Couldn't generate classes " + javaFile.packageName + '.' + javaFile.typeSpec.name);
e.printStackTrace();
if (filerSourceFile != null) {
filerSourceFile.delete();
}
return false;
}
}
示例4: writeClass
import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/** Emit a class file for a given class.
* @param c The class from which a class file is generated.
*/
public JavaFileObject writeClass(ClassSymbol c)
throws IOException, PoolOverflow, StringOverflow
{
String name = (c.owner.kind == MDL ? c.name : c.flatname).toString();
Location outLocn;
if (multiModuleMode) {
ModuleSymbol msym = c.owner.kind == MDL ? (ModuleSymbol) c.owner : c.packge().modle;
outLocn = fileManager.getLocationForModule(CLASS_OUTPUT, msym.name.toString());
} else {
outLocn = CLASS_OUTPUT;
}
JavaFileObject outFile
= fileManager.getJavaFileForOutput(outLocn,
name,
JavaFileObject.Kind.CLASS,
c.sourcefile);
OutputStream out = outFile.openOutputStream();
try {
writeClassFile(out, c);
if (verbose)
log.printVerbose("wrote.file", outFile);
out.close();
out = null;
} finally {
if (out != null) {
// if we are propagating an exception, delete the file
out.close();
outFile.delete();
outFile = null;
}
}
return outFile; // may be null if write failed
}