Search in sources :

Example 11 with TreePath

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());
}
Also used : TreePath(com.sun.source.util.TreePath) ImmutableList(com.google.common.collect.ImmutableList) ForOverride(com.google.errorprone.annotations.ForOverride)

Example 12 with TreePath

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);
}
Also used : TreePath(com.sun.source.util.TreePath) ClassTree(com.sun.source.tree.ClassTree)

Example 13 with TreePath

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;
    }
}
Also used : TreePath(com.sun.source.util.TreePath) MethodTree(com.sun.source.tree.MethodTree) BlockTree(com.sun.source.tree.BlockTree)

Example 14 with TreePath

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;
}
Also used : TreePath(com.sun.source.util.TreePath) ArrayAccessTree(com.sun.source.tree.ArrayAccessTree) CompoundAssignmentTree(com.sun.source.tree.CompoundAssignmentTree) LiteralTree(com.sun.source.tree.LiteralTree) AnnotatedTypeTree(com.sun.source.tree.AnnotatedTypeTree) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) AssignmentTree(com.sun.source.tree.AssignmentTree) TypeCastTree(com.sun.source.tree.TypeCastTree) IdentifierTree(com.sun.source.tree.IdentifierTree) NewArrayTree(com.sun.source.tree.NewArrayTree) ParenthesizedTree(com.sun.source.tree.ParenthesizedTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) MemberSelectTree(com.sun.source.tree.MemberSelectTree) ExpressionStatementTree(com.sun.source.tree.ExpressionStatementTree) BlockTree(com.sun.source.tree.BlockTree) PrimitiveTypeTree(com.sun.source.tree.PrimitiveTypeTree) StatementTree(com.sun.source.tree.StatementTree) AnnotationTree(com.sun.source.tree.AnnotationTree) MethodTree(com.sun.source.tree.MethodTree) BinaryTree(com.sun.source.tree.BinaryTree) VariableTree(com.sun.source.tree.VariableTree) TypeParameterTree(com.sun.source.tree.TypeParameterTree) NewClassTree(com.sun.source.tree.NewClassTree) ParameterizedTypeTree(com.sun.source.tree.ParameterizedTypeTree) Tree(com.sun.source.tree.Tree) ClassTree(com.sun.source.tree.ClassTree) ExpressionTree(com.sun.source.tree.ExpressionTree) JCTree(com.sun.tools.javac.tree.JCTree)

Example 15 with TreePath

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;
}
Also used : TreePath(com.sun.source.util.TreePath) BlockTree(com.sun.source.tree.BlockTree) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

TreePath (com.sun.source.util.TreePath)151 ExpressionTree (com.sun.source.tree.ExpressionTree)60 Tree (com.sun.source.tree.Tree)60 VariableTree (com.sun.source.tree.VariableTree)50 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)46 MethodTree (com.sun.source.tree.MethodTree)46 ClassTree (com.sun.source.tree.ClassTree)45 MemberSelectTree (com.sun.source.tree.MemberSelectTree)39 IdentifierTree (com.sun.source.tree.IdentifierTree)37 BlockTree (com.sun.source.tree.BlockTree)36 NewClassTree (com.sun.source.tree.NewClassTree)32 StatementTree (com.sun.source.tree.StatementTree)32 JCTree (com.sun.tools.javac.tree.JCTree)31 AssignmentTree (com.sun.source.tree.AssignmentTree)27 BinaryTree (com.sun.source.tree.BinaryTree)27 TypeCastTree (com.sun.source.tree.TypeCastTree)26 ExpressionStatementTree (com.sun.source.tree.ExpressionStatementTree)25 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)25 LiteralTree (com.sun.source.tree.LiteralTree)25 CompoundAssignmentTree (com.sun.source.tree.CompoundAssignmentTree)23