use of com.sun.source.doctree.DocTree in project morphia by mongodb.
the class QueryFilterTaglet method toString.
@Override
public String toString(List<? extends DocTree> tags, Element element) {
if (tags.size() == 0) {
return null;
}
StringBuilder buf = new StringBuilder(String.format("<dl><dt><span class=\"strong\">%s</span></dt>", getHeader()));
for (DocTree tag : tags) {
String text = ((UnknownBlockTagTree) tag).getContent().get(0).toString();
buf.append("<dd>").append(genLink(text)).append("</dd>");
}
return buf.toString();
}
use of com.sun.source.doctree.DocTree in project ignite by apache.
the class IgniteLinkTaglet method toString.
/**
* Given the <code>DocTree</code> representation of this custom tag, return its string representation.
* <p>
* Input: org.apache.ignite.grid.spi.indexing.h2.GridH2IndexingSpi#setIndexCustomFunctionClasses(Class[])
* <p>
* Output: <a href="../../../../../org/apache/ignite/grid/spi/indexing/h2/GridH2IndexingSpi.html#
* setIndexCustomFunctionClasses(java.lang.Class...)">
* <code>GridH2IndexingSpi.setIndexCustomFunctionClasses(java.lang.Class[])</code></a>
*
* @param tags <code>DocTree</code> representation of this custom tag.
* @param element The element to which the enclosing comment belongs.
*/
@Override
public String toString(List<? extends DocTree> tags, Element element) {
for (DocTree tag : tags) {
String text = new SimpleDocTreeVisitor<String, Void>() {
@Override
public String visitUnknownInlineTag(UnknownInlineTagTree node, Void param) {
return node.getContent().toString();
}
}.visit(tag, null);
if (text == null || text.isEmpty())
return "";
File f = new File(env.getDocTrees().getPath(element).getCompilationUnit().getSourceFile().toUri());
String curCls = f == null ? "" : f.getAbsolutePath().replace(File.separator, ".");
String packPref = "src.main.java.";
int idx = curCls.indexOf(packPref);
StringBuilder path = new StringBuilder();
if (idx != -1) {
curCls = curCls.substring(idx + packPref.length());
for (int i = 0, n = curCls.split("\\.").length - 2; i < n; i++) path.append("../");
}
String[] tokens = text.split("#");
int lastIdx = tokens[0].lastIndexOf('.');
String simpleClsName = lastIdx != -1 && lastIdx + 1 < tokens[0].length() ? tokens[0].substring(lastIdx + 1) : tokens[0];
String fullyQClsName = tokens[0].replace(".", "/");
return "<a href=\"" + path + fullyQClsName + ".html" + (tokens.length > 1 ? ("#" + tokens[1].replace("[]", "...")) : "") + "\"><code>" + simpleClsName + (tokens.length > 1 ? ("." + tokens[1]) : "") + "</code></a>";
}
return "";
}
use of com.sun.source.doctree.DocTree in project cxf by apache.
the class DumpJavaDoc method run.
@Override
public boolean run(DocletEnvironment docEnv) {
final Elements utils = docEnv.getElementUtils();
final DocTrees docTrees = docEnv.getDocTrees();
try (OutputStream os = Files.newOutputStream(Paths.get(dumpFileName))) {
final Properties javaDocMap = new Properties();
for (Element element : docEnv.getIncludedElements()) {
if (element.getKind() == ElementKind.CLASS) {
final TypeElement classDoc = (TypeElement) element;
final DocCommentTree classCommentTree = docTrees.getDocCommentTree(classDoc);
if (classCommentTree != null) {
javaDocMap.put(classDoc.toString(), getAllComments(classCommentTree.getFullBody()));
}
for (Element member : classDoc.getEnclosedElements()) {
// Skip all non-public methods
if (!member.getModifiers().contains(Modifier.PUBLIC)) {
continue;
}
if (member.getKind() == ElementKind.METHOD) {
final ExecutableElement method = (ExecutableElement) member;
final DocCommentTree methodCommentTree = docTrees.getDocCommentTree(method);
final String qualifiedName = utils.getBinaryName(classDoc) + "." + method.getSimpleName();
if (methodCommentTree == null) {
javaDocMap.put(qualifiedName, "");
} else {
javaDocMap.put(qualifiedName, getAllComments(methodCommentTree.getFullBody()));
for (DocTree tree : methodCommentTree.getBlockTags()) {
if (tree.getKind() == DocTree.Kind.RETURN) {
final ReturnTree returnTree = (ReturnTree) tree;
javaDocMap.put(qualifiedName + ".returnCommentTag", getAllComments(returnTree.getDescription()));
} else if (tree.getKind() == DocTree.Kind.PARAM) {
final ParamTree paramTree = (ParamTree) tree;
final int index = getParamIndex(method, paramTree);
if (index >= 0) {
javaDocMap.put(qualifiedName + ".paramCommentTag." + index, getAllComments(paramTree.getDescription()));
}
}
}
}
}
}
}
}
javaDocMap.store(os, "");
os.flush();
} catch (final IOException ex) {
reporter.print(Diagnostic.Kind.ERROR, ex.getMessage());
}
return true;
}
use of com.sun.source.doctree.DocTree in project j2objc by google.
the class JavadocConverter method convertJavadoc.
/**
* Returns an AST node for the javadoc comment of a specified class,
* method, or field element.
*/
static Javadoc convertJavadoc(Element element, String source, JavacEnvironment env, boolean reportWarnings) {
DocTrees docTrees = DocTrees.instance(env.task());
TreePath path = docTrees.getPath(element);
if (path == null) {
throw new AssertionError("could not find tree path for element");
}
DCTree.DCDocComment docComment = (DCTree.DCDocComment) docTrees.getDocCommentTree(path);
if (docComment == null) {
// Declaration does not have a javadoc comment.
return null;
}
JavadocConverter converter = new JavadocConverter(element, docComment, source, docTrees, path.getCompilationUnit(), reportWarnings);
Javadoc result = new Javadoc();
// First tag has no name.
TagElement newTag = new TagElement();
converter.scan(docComment.getFirstSentence(), newTag);
converter.scan(docComment.getBody(), newTag);
if (!newTag.getFragments().isEmpty()) {
List<TreeNode> fragments = newTag.getFragments();
int start = fragments.get(0).getStartPosition();
TreeNode lastFragment = fragments.get(fragments.size() - 1);
int end = start + lastFragment.getLength();
converter.setPos(newTag, start, end);
result.addTag(newTag);
}
for (DocTree tag : docComment.getBlockTags()) {
if (tag.getKind() != DocTree.Kind.ERRONEOUS) {
newTag = new TagElement();
converter.scan(tag, newTag);
result.addTag(newTag);
}
}
return result;
}
use of com.sun.source.doctree.DocTree in project checker-framework by typetools.
the class ManualTaglet method toString.
@Override
public String toString(List<? extends DocTree> tags, Element element) {
if (tags.isEmpty()) {
return "";
}
StringJoiner sb = new StringJoiner(", ");
for (DocTree t : tags) {
String text = getText(t);
String[] split = text.split(" ", 2);
sb.add(formatLink(split));
}
return formatHeader(sb.toString());
}
Aggregations