예제 #1
0
  public List<TreeContext> pathUpTo(Class<ASTNode> node, ASTNodePredicate predicate) {
    List<TreeContext> path = new LinkedList<TreeContext>();
    TreeContext current = lastContext;
    boolean found = false;
    while (current != null && !found) {
      path.add(current);
      ASTNode currentNode = current.node;
      if (node == null) {
        if (predicate.matches(currentNode)) {
          found = true;
        }
      } else {
        if (predicate == null) {
          if (currentNode == null || node == currentNode.getClass()) {
            found = true;
          }
        } else {
          found =
              currentNode != null
                  && node == currentNode.getClass()
                  && predicate.matches(currentNode);
        }
      }

      current = current.parent;
    }
    if (found) {
      return path;
    }
    return Collections.emptyList();
  }
예제 #2
0
 public List<TreeContext> pathMatches(List<ASTNodePredicate> predicates) {
   List<TreeContext> path = new LinkedList<TreeContext>();
   TreeContext current = lastContext.parent;
   for (ASTNodePredicate predicate : predicates) {
     path.add(current);
     if (current == null || !predicate.matches(current.node)) {
       return Collections.emptyList();
     }
     current = current.parent;
   }
   if (!path.isEmpty()) {
     path.add(0, lastContext);
   }
   return path;
 }