Ejemplo n.º 1
0
  @NotNull
  public ContextItem[] findCtxItems(String startCtxPath, String name) {
    String[] path = startCtxPath.split("/");
    int startWith = ("/" + path[1]).startsWith(ContextPath.FILE_CTX_PRX) ? 2 : 1;

    TreeNode cycled = root;
    for (int i = startWith; i < path.length; i++) {
      String encodedName = "/" + path[i];
      cycled = cycled.findChildByEncodedName(encodedName);
      if (cycled == null) {
        return new ContextItem[0];
      }
    }

    List<ContextItem> out = new ArrayList<ContextItem>();
    TreeNode[] children =
        name == null
            ? cycled.getChildren().toArray(new TreeNode[0])
            : cycled.findChildrenBySuffix(name);
    for (TreeNode n : children) {
      // todo -- revise to replace using value directly with a TreeNode instance
      out.add(new ContextItemImpl(n.getPath(), n.getValue()));
    }

    return out.toArray(new ContextItem[out.size()]);
  }
Ejemplo n.º 2
0
  public TreeNode[] findNodeInRelContext(String startCtxPath, String name) {
    String[] path = startCtxPath.split("/");

    TreeNode cycled = root;
    for (int i = 1; i < path.length; i++) {
      String encodedName = "/" + path[i];
      cycled = cycled.findChildByEncodedName(encodedName);
      if (cycled == null) {
        return new TreeNode[0];
      }
    }

    return cycled.findChildrenBySuffix(name);
  }
Ejemplo n.º 3
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;
    }
  }