示例#1
0
文件: Ast.java 项目: rahulcn/wink
 /**
  * @param top
  * @param type
  * @param depth
  * @return
  */
 public static List<AstNode> getNodesByType(final AstNode top, final int type, final int depth) {
   final List<AstNode> result = new ArrayList<AstNode>();
   for (final AstNode an : top.getChilds()) {
     getNodesByTypeR(an, type, depth, 1, result);
   }
   return result;
 }
示例#2
0
文件: Ast.java 项目: rahulcn/wink
 /** @return */
 private void toStringTree(final AstNode n, final StringBuffer sb) {
   for (int i = 0; i < n.getDepth(); i++) {
     sb.append("    ");
   }
   sb.append(n.toString());
   sb.append("\n");
   for (final AstNode child : n.getChilds()) {
     toStringTree(child, sb);
   }
 }
示例#3
0
文件: Ast.java 项目: rahulcn/wink
 /**
  * @param top
  * @param type
  * @param depth
  * @param currentDepth
  * @param result
  */
 private static void getNodesByTypeR(
     final AstNode top,
     final int type,
     final int depth,
     final int currentDepth,
     final List<AstNode> result) {
   if (depth != -1 && currentDepth > depth) {
     return;
   }
   if (type == -1 || top.getNode().getType() == type) {
     result.add(top);
   }
   for (final AstNode an : top.getChilds()) {
     getNodesByTypeR(an, type, depth, currentDepth + 1, result);
   }
 }