Пример #1
0
 public void iterateOverChildrenWithSuffix(String suffix, TreeNodeHandler handler) {
   if (suffix == null) {
     for (List<TreeNodeImpl> lst1 : childs.values()) {
       for (TreeNodeImpl n : lst1) {
         handler.handleNode(n);
       }
     }
   } else {
     List<TreeNodeImpl> lst = childs.get(suffix);
     if (lst != null) {
       for (TreeNodeImpl n : lst) handler.handleNode(n);
     }
   }
 }
Пример #2
0
  public void searchContextTree_DownUp(
      String startCtxPath, String name, int refType, TreeNodeHandler handler) {
    String[] path = startCtxPath.split("/");

    int _1st_ctxType = -1;
    int startWith = ("/" + path[1]).startsWith(ContextPath.FILE_CTX_PRX) ? 2 : 1;
    List<TreeNode> out = new ArrayList<TreeNode>();

    TreeNode cycled = root;
    for (int i = startWith; i < path.length; i++) {
      String encodedName = "/" + path[i];
      int ctxType = ContextPathUtil.prefix2type(encodedName.substring(0, 4));
      if (i == startWith) {
        // save the type of the first context
        _1st_ctxType = ctxType;
      }

      cycled = cycled.findChildByEncodedName(encodedName);
      if (cycled == null) {
        // todo -- is it suggested?
        break;
      } else {
        if (i == path.length - 1) {
          // check type of the last context
          switch (refType) {
            case ContextPath.NESTED_CALL:
              // search for the name in the context only
              for (TreeNode d : cycled.findChildrenBySuffix(name)) {
                handler.handleNode(d);
              }
              return;
            default:
              switch (ctxType) {
                case ContextPath.COLUMN_DEF:
                case ContextPath.RECORD_ITEM:
                case ContextPath.VARIABLE_DECL:
                case ContextPath.ARGUMENT:
                case ContextPath.REF_CURSOR:
                  // skip search in the context
                  // todo -- more types expected
                  continue;
                default:
                  break;
              }
          }
        } else {
          // intermediate context, add to list
        }

        out.add(cycled);
      }
    }

    for (int i = out.size() - 1; i >= 0; i--) {
      TreeNode n = out.get(i);
      for (TreeNode foundNode : n.findChildrenBySuffix(name)) {
        if (handler.handleNode(foundNode)) {
          // iteration terminated by listener
          return;
        }
      }

      //            switch(n.getType()){
      //                case ContextPath.CURSOR_DECL:
      //                    // Cursor decl: closed scope
      //                    return;
      //            }
    }

    if (_1st_ctxType == ContextPath.PACKAGE_BODY) {
      // search package spec for name
      String spec =
          ContextPath.PACKAGE_SPEC_PRX + path[startWith].substring(3, path[startWith].length());
      for (TreeNode pks : findNodeInRelContext(spec, name)) { // findInContext2(spec, name)) {
        if (handler.handleNode(pks)) {
          // iteration terminated by listener
          return;
        }
      }
    }

    switch (refType) {
      case ContextPath.FUNC_CALL:
      case ContextPath.PROC_CALL:
      case ContextPath.TABLE_REF:
      case ContextPath.TYPE_REF:
      case ContextPath.GENERIC_NAME_REF: // package name (coming from sql code)
      case ContextPath.PLSQL_NAME_REF: // package name (coming from pl/sql code)
        // todo -- do we need to limit target ref types?
        // search in the root context
        for (TreeNode d : findNodeInRootContext(name)) {
          if (handler.handleNode(d)) {
            // iteration terminated by listener
            return;
          }
        }
        break;
    }
  }