public String formatJavadoc(String header, String javadoc) {
        try {
            StringBuilder result = new StringBuilder();

            result.append(escape(CODE_HIGHLIGHT)).append(header).append(escape(CODE_RESET)).append("\n");

            if (javadoc == null) {
                return result.toString();
            }

            JavacTask task = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, null, null, null, null);
            DocTrees trees = DocTrees.instance(task);
            DocCommentTree docComment = trees.getDocCommentTree(new SimpleJavaFileObject(new URI("mem://doc.html"), Kind.HTML) {
                @Override @DefinedBy(Api.COMPILER)
                public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
                    return "<body>" + javadoc + "</body>";
                }
            });

            new FormatJavadocScanner(result, task).scan(docComment, null);

            addNewLineIfNeeded(result);

            return result.toString();
        } catch (URISyntaxException ex) {
            throw new InternalError("Unexpected exception", ex);
        }
    }
public String formatJavadoc ( String header , String javadoc ) { try { StringBuilder result = new StringBuilder ( ) ; result . append ( escape ( CODE_HIGHLIGHT ) ) . append ( header ) . append ( escape ( CODE_RESET ) ) . append ( "\n" ) ; if ( javadoc == null ) { return result . toString ( ) ; } JavacTask task = ( JavacTask ) ToolProvider . getSystemJavaCompiler ( ) . getTask ( null , null , null , null , null , null ) ; DocTrees trees = DocTrees . instance ( task ) ; DocCommentTree docComment = trees . getDocCommentTree ( new SimpleJavaFileObject ( new URI ( "mem://doc.html" ) , Kind . HTML ) { @ Override @ DefinedBy ( Api . COMPILER ) public CharSequence getCharContent ( boolean ignoreEncodingErrors ) throws IOException { return "<body>" + javadoc + "</body>" ; } } ) ; new FormatJavadocScanner ( result , task ) . scan ( docComment , null ) ; addNewLineIfNeeded ( result ) ; return result . toString ( ) ; } catch ( URISyntaxException ex ) { throw new InternalError ( "Unexpected exception" , ex ) ; } }
Format javadoc to plain text.

@param header element caption that should be used
@param javadoc to format
@return javadoc formatted to plain text