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

The following examples show how to use javax.tools.FileObject#openReader() . 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: AnnotationProcessorUtil.java    From kumuluzee with MIT License 6 votes vote down vote up
private static FileObject readOldFile(Set<String> content, String resourceName, Filer filer) throws IOException {
    Reader reader = null;
    try {
        final FileObject resource = filer.getResource(StandardLocation.CLASS_OUTPUT, "", resourceName);
        reader = resource.openReader(true);
        AnnotationProcessorUtil.readOldFile(content, reader);
        return resource;
    } catch (FileNotFoundException e) {
        // close reader, return null
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
    return null;
}
 
Example 2
Source File: DocumentationProcessor.java    From armeria with Apache License 2.0 6 votes vote down vote up
private Properties readProperties(String className) throws IOException {
    if (propertiesMap.containsKey(className)) {
        return propertiesMap.get(className);
    }
    final FileObject resource = processingEnv
            .getFiler()
            .getResource(StandardLocation.CLASS_OUTPUT,
                         "",
                         getFileName(className));
    final Properties properties = new Properties();
    if (resource.getLastModified() == 0L) {
        // returns 0 if file does not exist
        propertiesMap.put(className, properties);
        return properties;
    }
    try (Reader reader = resource.openReader(false)) {
        properties.load(reader);
        return properties;
    }
}
 
Example 3
Source File: SourceToHTMLConverter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert the given Class to an HTML.
 *
 * @param te the class to convert.
 * @param outputdir the name of the directory to output to
 * @throws DocFileIOException if there is a problem generating the output file
 * @throws SimpleDocletException if there is a problem reading the source file
 */
public void convertClass(TypeElement te, DocPath outputdir)
        throws DocFileIOException, SimpleDocletException {
    if (te == null) {
        return;
    }
    FileObject fo = utils.getFileObject(te);
    if (fo == null)
        return;

    try {
        Reader r = fo.openReader(true);
        int lineno = 1;
        String line;
        relativePath = DocPaths.SOURCE_OUTPUT
                .resolve(DocPath.forPackage(utils, te))
                .invert();
        Content body = getHeader();
        Content pre = new HtmlTree(HtmlTag.PRE);
        try (LineNumberReader reader = new LineNumberReader(r)) {
            while ((line = reader.readLine()) != null) {
                addLineNo(pre, lineno);
                addLine(pre, line, lineno);
                lineno++;
            }
        }
        addBlankLines(pre);
        Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
        body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div);
        writeToFile(body, outputdir.resolve(DocPath.forClass(utils, te)));
    } catch (IOException e) {
        String message = configuration.resources.getText("doclet.exception.read.file", fo.getName());
        throw new SimpleDocletException(message, e);
    }
}
 
Example 4
Source File: SourceToHTMLConverter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the given Class to an HTML.
 *
 * @param cd the class to convert.
 * @param outputdir the name of the directory to output to.
 */
public void convertClass(ClassDoc cd, DocPath outputdir) {
    if (cd == null) {
        return;
    }
    try {
        SourcePosition sp = cd.position();
        if (sp == null)
            return;
        Reader r;
        // temp hack until we can update SourcePosition API.
        if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
            FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
            if (fo == null)
                return;
            r = fo.openReader(true);
        } else {
            File file = sp.file();
            if (file == null)
                return;
            r = new FileReader(file);
        }
        LineNumberReader reader = new LineNumberReader(r);
        int lineno = 1;
        String line;
        relativePath = DocPaths.SOURCE_OUTPUT
                .resolve(DocPath.forPackage(cd))
                .invert();
        Content body = getHeader();
        Content pre = new HtmlTree(HtmlTag.PRE);
        try {
            while ((line = reader.readLine()) != null) {
                addLineNo(pre, lineno);
                addLine(pre, line, lineno);
                lineno++;
            }
        } finally {
            reader.close();
        }
        addBlankLines(pre);
        Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
        body.addContent(div);
        writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: SourceToHTMLConverter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the given Class to an HTML.
 *
 * @param cd the class to convert.
 * @param outputdir the name of the directory to output to.
 */
public void convertClass(ClassDoc cd, DocPath outputdir) {
    if (cd == null) {
        return;
    }
    try {
        SourcePosition sp = cd.position();
        if (sp == null)
            return;
        Reader r;
        // temp hack until we can update SourcePosition API.
        if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
            FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
            if (fo == null)
                return;
            r = fo.openReader(true);
        } else {
            File file = sp.file();
            if (file == null)
                return;
            r = new FileReader(file);
        }
        LineNumberReader reader = new LineNumberReader(r);
        int lineno = 1;
        String line;
        relativePath = DocPaths.SOURCE_OUTPUT
                .resolve(DocPath.forPackage(cd))
                .invert();
        Content body = getHeader();
        Content pre = new HtmlTree(HtmlTag.PRE);
        try {
            while ((line = reader.readLine()) != null) {
                addLineNo(pre, lineno);
                addLine(pre, line, lineno);
                lineno++;
            }
        } finally {
            reader.close();
        }
        addBlankLines(pre);
        Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
        body.addContent(div);
        writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: SourceToHTMLConverter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the given Class to an HTML.
 *
 * @param cd the class to convert.
 * @param outputdir the name of the directory to output to.
 */
public void convertClass(ClassDoc cd, DocPath outputdir) {
    if (cd == null) {
        return;
    }
    try {
        SourcePosition sp = cd.position();
        if (sp == null)
            return;
        Reader r;
        // temp hack until we can update SourcePosition API.
        if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
            FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
            if (fo == null)
                return;
            r = fo.openReader(true);
        } else {
            File file = sp.file();
            if (file == null)
                return;
            r = new FileReader(file);
        }
        LineNumberReader reader = new LineNumberReader(r);
        int lineno = 1;
        String line;
        relativePath = DocPaths.SOURCE_OUTPUT
                .resolve(DocPath.forPackage(cd))
                .invert();
        Content body = getHeader();
        Content pre = new HtmlTree(HtmlTag.PRE);
        try {
            while ((line = reader.readLine()) != null) {
                addLineNo(pre, lineno);
                addLine(pre, line, lineno);
                lineno++;
            }
        } finally {
            reader.close();
        }
        addBlankLines(pre);
        Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
        body.addContent(div);
        writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: SourceToHTMLConverter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the given Class to an HTML.
 *
 * @param cd the class to convert.
 * @param outputdir the name of the directory to output to.
 */
public void convertClass(ClassDoc cd, DocPath outputdir) {
    if (cd == null) {
        return;
    }
    try {
        SourcePosition sp = cd.position();
        if (sp == null)
            return;
        Reader r;
        // temp hack until we can update SourcePosition API.
        if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
            FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
            if (fo == null)
                return;
            r = fo.openReader(true);
        } else {
            File file = sp.file();
            if (file == null)
                return;
            r = new FileReader(file);
        }
        LineNumberReader reader = new LineNumberReader(r);
        int lineno = 1;
        String line;
        relativePath = DocPaths.SOURCE_OUTPUT
                .resolve(DocPath.forPackage(cd))
                .invert();
        Content body = getHeader();
        Content pre = new HtmlTree(HtmlTag.PRE);
        try {
            while ((line = reader.readLine()) != null) {
                addLineNo(pre, lineno);
                addLine(pre, line, lineno);
                lineno++;
            }
        } finally {
            reader.close();
        }
        addBlankLines(pre);
        Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
        body.addContent(div);
        writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: SourceToHTMLConverter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the given Class to an HTML.
 *
 * @param cd the class to convert.
 * @param outputdir the name of the directory to output to.
 */
public void convertClass(ClassDoc cd, DocPath outputdir) {
    if (cd == null) {
        return;
    }
    try {
        SourcePosition sp = cd.position();
        if (sp == null)
            return;
        Reader r;
        // temp hack until we can update SourcePosition API.
        if (sp instanceof SourcePositionImpl) {
            FileObject fo = ((SourcePositionImpl) sp).fileObject();
            if (fo == null)
                return;
            r = fo.openReader(true);
        } else {
            File file = sp.file();
            if (file == null)
                return;
            r = new FileReader(file);
        }
        int lineno = 1;
        String line;
        relativePath = DocPaths.SOURCE_OUTPUT
                .resolve(DocPath.forPackage(cd))
                .invert();
        Content body = getHeader();
        Content pre = new HtmlTree(HtmlTag.PRE);
        try (LineNumberReader reader = new LineNumberReader(r)) {
            while ((line = reader.readLine()) != null) {
                addLineNo(pre, lineno);
                addLine(pre, line, lineno);
                lineno++;
            }
        }
        addBlankLines(pre);
        Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
        body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div);
        writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 9
Source File: SourceToHTMLConverter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the given Class to an HTML.
 *
 * @param cd the class to convert.
 * @param outputdir the name of the directory to output to.
 */
public void convertClass(ClassDoc cd, DocPath outputdir) {
    if (cd == null) {
        return;
    }
    try {
        SourcePosition sp = cd.position();
        if (sp == null)
            return;
        Reader r;
        // temp hack until we can update SourcePosition API.
        if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
            FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
            if (fo == null)
                return;
            r = fo.openReader(true);
        } else {
            File file = sp.file();
            if (file == null)
                return;
            r = new FileReader(file);
        }
        LineNumberReader reader = new LineNumberReader(r);
        int lineno = 1;
        String line;
        relativePath = DocPaths.SOURCE_OUTPUT
                .resolve(DocPath.forPackage(cd))
                .invert();
        Content body = getHeader();
        Content pre = new HtmlTree(HtmlTag.PRE);
        try {
            while ((line = reader.readLine()) != null) {
                addLineNo(pre, lineno);
                addLine(pre, line, lineno);
                lineno++;
            }
        } finally {
            reader.close();
        }
        addBlankLines(pre);
        Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
        body.addContent(div);
        writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: SourceToHTMLConverter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the given Class to an HTML.
 *
 * @param cd the class to convert.
 * @param outputdir the name of the directory to output to.
 */
public void convertClass(ClassDoc cd, DocPath outputdir) {
    if (cd == null) {
        return;
    }
    try {
        SourcePosition sp = cd.position();
        if (sp == null)
            return;
        Reader r;
        // temp hack until we can update SourcePosition API.
        if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
            FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
            if (fo == null)
                return;
            r = fo.openReader(true);
        } else {
            File file = sp.file();
            if (file == null)
                return;
            r = new FileReader(file);
        }
        LineNumberReader reader = new LineNumberReader(r);
        int lineno = 1;
        String line;
        relativePath = DocPaths.SOURCE_OUTPUT
                .resolve(DocPath.forPackage(cd))
                .invert();
        Content body = getHeader();
        Content pre = new HtmlTree(HtmlTag.PRE);
        try {
            while ((line = reader.readLine()) != null) {
                addLineNo(pre, lineno);
                addLine(pre, line, lineno);
                lineno++;
            }
        } finally {
            reader.close();
        }
        addBlankLines(pre);
        Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
        body.addContent(div);
        writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 11
Source File: SourceToHTMLConverter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert the given Class to an HTML.
 *
 * @param cd the class to convert.
 * @param outputdir the name of the directory to output to.
 */
public void convertClass(ClassDoc cd, DocPath outputdir) {
    if (cd == null) {
        return;
    }
    try {
        SourcePosition sp = cd.position();
        if (sp == null)
            return;
        Reader r;
        // temp hack until we can update SourcePosition API.
        if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
            FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
            if (fo == null)
                return;
            r = fo.openReader(true);
        } else {
            File file = sp.file();
            if (file == null)
                return;
            r = new FileReader(file);
        }
        LineNumberReader reader = new LineNumberReader(r);
        int lineno = 1;
        String line;
        relativePath = DocPaths.SOURCE_OUTPUT
                .resolve(DocPath.forPackage(cd))
                .invert();
        Content body = getHeader();
        Content pre = new HtmlTree(HtmlTag.PRE);
        try {
            while ((line = reader.readLine()) != null) {
                addLineNo(pre, lineno);
                addLine(pre, line, lineno);
                lineno++;
            }
        } finally {
            reader.close();
        }
        addBlankLines(pre);
        Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
        body.addContent(div);
        writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}