public String renderSource(TypeElement elt, String source) { TreePath path = docTrees.getPath(elt); ClassTree classTree = (ClassTree) path.getLeaf(); return renderSource(path, Collections.singletonList(classTree), source); }
/** * Returns the file that contains the current tag, or {@code null} if the method * can not determine the file. * * @return file containing the current tag, or {@code null}. */ protected final Path getCurrentFile() { if (trees != null && element != null) { final TreePath path = trees.getPath(element); if (path != null) { // Following methods do not document 'null' as a possible return value. return Paths.get(path.getCompilationUnit().getSourceFile().toUri()); } } return null; }
/** * Read the source code of the provided element, this returns the source of the entire related compilation unit. * * @param elt the element to load * @return the source */ String readSource(Element elt) { CompilationUnitTree unit = docTrees.getPath(elt).getCompilationUnit(); StringBuilder source = new StringBuilder(); try(Reader reader = unit.getSourceFile().openReader(true)) { char[] buffer = new char[256]; while (true) { int len = reader.read(buffer); if (len == -1) { break; } source.append(buffer, 0, len); } return source.toString(); } catch (IOException e) { throw new DocGenException(elt, "Could not read source code of element " + elt); } }
private void appendComment( Tree node, StringBuilder out ) { if( _docTrees == null ) { return; } TreePath path = _docTrees.getPath( _compilationUnit, node ); if( path != null ) { DocCommentTree docTree = _docTrees.getDocCommentTree( path ); String docComment = _docTrees.getDocComment( path ); if( docComment != null ) { out.append( "/**\n" ); for( String line : docComment.split( "\\r?\\n" ) ) { appendIndent( out ); out.append( " *" ); out.append( line ); out.append( "\n" ); } appendIndent( out ); out.append( " */\n" ); appendIndent( out ); } } }
/** * Render the source fragment for the Java language. Java being the pivot language, we consider this method as the * _default_ behavior. This method is final as it must not be overridden by any extension. * * @param elt the element * @param source the source * @return the fragment */ @Override public String renderSource(ExecutableElement elt, String source) { // Get block TreePath path = docTrees.getPath(elt); MethodTree methodTree = (MethodTree) path.getLeaf(); BlockTree blockTree = methodTree.getBody(); List<? extends StatementTree> statements = blockTree.getStatements(); if (statements.size() > 0) { return renderSource(path, statements, source); } else { return null; } }
TreePath pkgPath = docTrees.getPath(pkgElt); DocCommentTree docTree = docTrees.getDocCommentTree(pkgPath); DocTreeVisitor<Void, Void> visitor = new DocTreeScanner<Void, Void>() {