use of com.sun.source.doctree.DocCommentTree 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.DocCommentTree 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(TreePath path, String source, JavacEnvironment env, boolean reportWarnings) {
DocTrees docTrees = DocTrees.instance(env.task());
DocCommentTree docComment = docTrees.getDocCommentTree(path);
if (docComment == null) {
// Declaration does not have a javadoc comment.
return null;
}
JavadocConverter converter = new JavadocConverter(env.treeUtilities().getElement(path), docComment, source, docTrees, path.getCompilationUnit(), reportWarnings);
Javadoc result = new Javadoc();
// First tag is the description.
TagElement newTag = new TagElement().setTagKind(TagElement.TagKind.DESCRIPTION);
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;
}
Aggregations