use of com.sun.source.util.TreePath in project error-prone by google.
the class ChildMultiMatcher method multiMatchResult.
@Override
public MultiMatchResult<N> multiMatchResult(T tree, VisitorState state) {
ImmutableList.Builder<Matchable<N>> result = ImmutableList.builder();
for (N subnode : getChildNodes(tree, state)) {
TreePath newPath = new TreePath(state.getPath(), subnode);
result.add(Matchable.create(subnode, state.withPath(newPath)));
}
MatchResult<N> matchResult = listMatcher.matches(result.build(), nodeMatcher);
return MultiMatchResult.create(matchResult.matches(), matchResult.matchingNodes());
}
use of com.sun.source.util.TreePath in project vertx-docgen by vert-x3.
the class JavaDocGenerator method renderSource.
public String renderSource(TypeElement elt, String source) {
TreePath path = docTrees.getPath(elt);
ClassTree classTree = (ClassTree) path.getLeaf();
return renderSource(path, Collections.singletonList(classTree), source);
}
use of com.sun.source.util.TreePath in project vertx-docgen by vert-x3.
the class JavaDocGenerator method renderSource.
/**
* 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;
}
}
use of com.sun.source.util.TreePath in project checker-framework by typetools.
the class TreeUtils method enclosingOfKind.
/**
* Gets the first enclosing tree in path, with any one of the specified kinds.
*
* @param path the path defining the tree node
* @param kinds the set of kinds of the desired tree
* @return the enclosing tree of the given type as given by the path
*/
public static Tree enclosingOfKind(final TreePath path, final Set<Tree.Kind> kinds) {
TreePath p = path;
while (p != null) {
Tree leaf = p.getLeaf();
assert leaf != null;
/*nninvariant*/
if (kinds.contains(leaf.getKind())) {
return leaf;
}
p = p.getParentPath();
}
return null;
}
use of com.sun.source.util.TreePath in project checker-framework by typetools.
the class TreeUtils method enclosingTopLevelBlock.
@Nullable
public static BlockTree enclosingTopLevelBlock(TreePath path) {
TreePath parpath = path.getParentPath();
while (parpath != null && !classTreeKinds.contains(parpath.getLeaf().getKind())) {
path = parpath;
parpath = parpath.getParentPath();
}
if (path.getLeaf().getKind() == Tree.Kind.BLOCK) {
return (BlockTree) path.getLeaf();
}
return null;
}
Aggregations