Java Code Examples for javax.tools.FileObject#delete()

The following examples show how to use javax.tools.FileObject#delete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JNIWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** 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
}
 
Example 2
Source File: JNIWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/** 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
}
 
Example 3
Source File: ConfigurationDocWriter.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
public void generateIncomingDocumentation(Connector connector, List<ConnectorAttribute> commonAttributes,
        List<ConnectorAttribute> incomingAttributes)
        throws IOException {
    FileObject resource = environment.getFiler()
            .createResource(StandardLocation.CLASS_OUTPUT, "",
                    "META-INF/connector/" + connector.value() + "-incoming.adoc");
    resource.delete();
    try (PrintWriter out = new PrintWriter(resource.openWriter())) {
        out.println(".Incoming Attributes of the '" + connector.value() + "' connector");
        writeTableBegin(out);
        commonAttributes.forEach(att -> {
            if (!att.hiddenFromDocumentation()) {
                generateLine(att, out);
            }
        });
        incomingAttributes.forEach(att -> {
            if (!att.hiddenFromDocumentation()) {
                generateLine(att, out);
            }
        });
        out.println("|===");
    }
}
 
Example 4
Source File: ConfigurationDocWriter.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
public void generateOutgoingDocumentation(Connector connector, List<ConnectorAttribute> commonAttributes,
        List<ConnectorAttribute> incomingAttributes)
        throws IOException {
    FileObject resource = environment.getFiler()
            .createResource(StandardLocation.CLASS_OUTPUT, "",
                    "META-INF/connector/" + connector.value() + "-outgoing.adoc");
    resource.delete();

    // merge and sort the attributes
    List<ConnectorAttribute> list = new ArrayList<>(commonAttributes);
    list.addAll(incomingAttributes);
    list.sort(Comparator.comparing(ConnectorAttribute::name));

    try (PrintWriter out = new PrintWriter(resource.openWriter())) {
        out.println(".Outgoing Attributes of the '" + connector.value() + "' connector");
        writeTableBegin(out);
        list.forEach(att -> {
            if (!att.hiddenFromDocumentation()) {
                generateLine(att, out);
            }
        });
        out.println("|===");
    }
}
 
Example 5
Source File: JNIWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** 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
}
 
Example 6
Source File: JNIWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/** 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
}
 
Example 7
Source File: JNIWriter.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** 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
}
 
Example 8
Source File: JNIWriter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** 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
}
 
Example 9
Source File: JNIWriter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** 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
}
 
Example 10
Source File: JNIWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** 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();
    Location outLocn;
    if (multiModuleMode) {
        ModuleSymbol msym = c.owner.kind == MDL ? (ModuleSymbol) c.owner : c.packge().modle;
        outLocn = fileManager.getLocationForModule(StandardLocation.NATIVE_HEADER_OUTPUT, msym.name.toString());
    } else {
        outLocn = StandardLocation.NATIVE_HEADER_OUTPUT;
    }
    FileObject outFile
        = fileManager.getFileForOutput(outLocn,
            "", className.replaceAll("[.$]", "_") + ".h", null);
    PrintWriter out = new PrintWriter(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
}
 
Example 11
Source File: JNIWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** 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();
    Location outLocn;
    if (multiModuleMode) {
        ModuleSymbol msym = c.owner.kind == MDL ? (ModuleSymbol) c.owner : c.packge().modle;
        outLocn = fileManager.getLocationForModule(StandardLocation.NATIVE_HEADER_OUTPUT, msym.name.toString());
    } else {
        outLocn = StandardLocation.NATIVE_HEADER_OUTPUT;
    }
    FileObject outFile
        = fileManager.getFileForOutput(outLocn,
            "", className.replaceAll("[.$]", "_") + ".h", null);
    PrintWriter out = new PrintWriter(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
}