/*  return the tree specification, marked at token k
512027
function (token, k) {
        var str = "";
        for (var i = 0; i < k && i < token.length; i++)
            str += token[i];
        if (i < token.length) {
            str += "<";
            str += token[i++];
            str += ">";
            for (; i < token.length; i++)
                str += token[i];
        }
        return str;
    }
645956
CmsTreeOpenState getVfsTreeState(String treeToken) {

        return (CmsTreeOpenState)(getRequest().getSession().getAttribute(
            getTreeOpenStateAttributeName(I_CmsGalleryProviderConstants.TREE_VFS, treeToken)));
    }
1302209
public ParseTree getStatementAtLine( int iLineNum, Class clsSkip )
  {
    if( _pe instanceof NewExpression )
    {
      NewExpression newExpression = (NewExpression)_pe;
      IType type = newExpression.getType();
      if( type instanceof IGosuClassInternal && newExpression.isAnonymousClass() )
      {
        return (ParseTree)((IGosuClassInternal)type).getClassStatement().getLocation().getStatementAtLine( iLineNum, clsSkip );
      }
    }

    if( (_pe instanceof Statement) && // Note we must analyze expressions e.g., block expressions can have statements
        !(_pe instanceof FunctionStatement && ((FunctionStatement)_pe).getDynamicFunctionSymbol() instanceof ProgramClassFunctionSymbol) &&
        (getLineNum() == iLineNum) &&
        (clsSkip == null || !clsSkip.isAssignableFrom( _pe.getClass() )) )
    {
      return this;
    }

    ParseTree deepest = null;
    for(int i = 0; i < _children.size; i++)
    {
      ParseTree child = (ParseTree) _children.data[i];
      ParseTree l = child.getStatementAtLine( iLineNum, clsSkip );
      if( Search.isDeeper( deepest, l ) )
      {
        deepest = l;
      }
    }

    return deepest;
  }
882134
function getPrefixTokens (node) {
    const prefixes = []

    let token = tokenStore.getFirstToken(node)
    while (token != null && token.range[1] <= node.key.range[0]) {
      prefixes.push(token)
      token = tokenStore.getTokenAfter(token)
    }
    while (isLeftParen(last(prefixes)) || isLeftBracket(last(prefixes))) {
      prefixes.pop()
    }

    return prefixes
  }
997425
public List<ErrorProneToken> getTokensForNode(Tree tree) {
    return ErrorProneTokens.getTokens(getSourceForNode(tree), context);
  }
1327305
function _getGraphDetails(tree) {
  var maxDepth = 0,
      leafCount = 0,

      links = _getLinks(tree);

  tree.ifForEach('children', function (child) {
    var details = _getGraphDetails(child);
    maxDepth = Math.max(maxDepth, details.maxDepth);
    leafCount += details.leafCount;

    links.push.apply(links, details.links);
  });

  if(!tree.get('children')) {
    leafCount++;
  }

  return {
    tree: tree,
    links: links,
    maxDepth: maxDepth + 1,
    leafCount: leafCount
  };
}
939376
private ParseTree parseShiftExpression() {
    SourcePosition start = getTreeStartLocation();
    ParseTree left = parseAdditiveExpression();
    while (peekShiftOperator()) {
      Token operator = nextToken();
      ParseTree right = parseAdditiveExpression();
      left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
    }
    return left;
  }
607903
public String getTreeResource(String type) {

        String result = m_treeType.get(type);
        if (result == null) {
            result = "/";
        }
        return result;
    }
202860
function defineRootTokenBuilder(Type) {
    return (node, _parentToken, html, sourceCodeStore, lastIndex) => {
        const token = new Type(html, 0, lastIndex, sourceCodeStore)
        token.children = buildChildTokens(
            node,
            token,
            html,
            sourceCodeStore,
            lastIndex
        )
        return token
    }
}
1016689
TreeNode childWithToken(Token token) {
        for (TreeNode child : m_children) {
            if (child.getToken().equals(token)) {
                return child;
            }
        }

        return null;
    }
426955
public static Element getDeclaredElement(TreeNode node) {
    if (node instanceof AbstractTypeDeclaration) {
      return ((AbstractTypeDeclaration) node).getTypeElement();
    } else if (node instanceof MethodDeclaration) {
      return ((MethodDeclaration) node).getExecutableElement();
    } else if (node instanceof VariableDeclaration) {
      return ((VariableDeclaration) node).getVariableElement();
    }
    return null;
  }
80603
function (s) {
      var tree = []
      var value = ''
      var data

      // TODO Refactor, to get this removed.
      this.lastTreeInExpression = tree
      while (true) {
        data = this.lookUp(s.slice(value.length), value)
        if (data) {
          tree = tree.concat(data.tree)
          value = data.value
          this.lastTreeInExpression = tree
          if (!data.ret) {
            break
          }
        } else {
          break
        }
      }
      if (tree.length) {
        tree = this.composeExpression(tree)
      }

      return {tree: tree, value: value}
    }
1020956
public Tree getStanfordContituencyTree() {
        TreeFactory tf = new LabeledScoredTreeFactory();
        StringReader r = new StringReader(getParseText());
        TreeReader tr = new PennTreeReader(r, tf);
        try {
            return tr.readTree();
        } catch (IOException e) {
            throw new RuntimeException("Error: IOException should not be thrown by StringReader");
        }
    }
749602
final TreeNode<K,V> findTreeNode(int h, Object k, Class<?> kc) {
            if (k != null) {
                TreeNode<K,V> p = this;
                do {
                    int ph, dir; K pk; TreeNode<K,V> q;
                    TreeNode<K,V> pl = p.left, pr = p.right;
                    if ((ph = p.hash) > h)
                        p = pl;
                    else if (ph < h)
                        p = pr;
                    else if ((pk = p.key) == k || (pk != null && k.equals(pk)))
                        return p;
                    else if (pl == null)
                        p = pr;
                    else if (pr == null)
                        p = pl;
                    else if ((kc != null ||
                              (kc = comparableClassFor(k)) != null) &&
                             (dir = compareComparables(kc, k, pk)) != 0)
                        p = (dir < 0) ? pl : pr;
                    else if ((q = pr.findTreeNode(h, k, kc)) != null)
                        return q;
                    else
                        p = pl;
                } while (p != null);
            }
            return null;
        }
363141
public static int getStartPos(JCTree tree) {
        if (tree == null)
            return Position.NOPOS;

        switch(tree.getTag()) {
            case MODULEDEF: {
                JCModuleDecl md = (JCModuleDecl)tree;
                return md.mods.annotations.isEmpty() ? md.pos :
                       md.mods.annotations.head.pos;
            }
            case PACKAGEDEF: {
                JCPackageDecl pd = (JCPackageDecl)tree;
                return pd.annotations.isEmpty() ? pd.pos :
                       pd.annotations.head.pos;
            }
            case APPLY:
                return getStartPos(((JCMethodInvocation) tree).meth);
            case ASSIGN:
                return getStartPos(((JCAssign) tree).lhs);
            case BITOR_ASG: case BITXOR_ASG: case BITAND_ASG:
            case SL_ASG: case SR_ASG: case USR_ASG:
            case PLUS_ASG: case MINUS_ASG: case MUL_ASG:
            case DIV_ASG: case MOD_ASG:
            case OR: case AND: case BITOR:
            case BITXOR: case BITAND: case EQ:
            case NE: case LT: case GT:
            case LE: case GE: case SL:
            case SR: case USR: case PLUS:
            case MINUS: case MUL: case DIV:
            case MOD:
            case POSTINC:
            case POSTDEC:
                return getStartPos(((JCOperatorExpression) tree).getOperand(LEFT));
            case CLASSDEF: {
                JCClassDecl node = (JCClassDecl)tree;
                if (node.mods.pos != Position.NOPOS)
                    return node.mods.pos;
                break;
            }
            case CONDEXPR:
                return getStartPos(((JCConditional) tree).cond);
            case EXEC:
                return getStartPos(((JCExpressionStatement) tree).expr);
            case INDEXED:
                return getStartPos(((JCArrayAccess) tree).indexed);
            case METHODDEF: {
                JCMethodDecl node = (JCMethodDecl)tree;
                if (node.mods.pos != Position.NOPOS)
                    return node.mods.pos;
                if (node.typarams.nonEmpty()) // List.nil() used for no typarams
                    return getStartPos(node.typarams.head);
                return node.restype == null ? node.pos : getStartPos(node.restype);
            }
            case SELECT:
                return getStartPos(((JCFieldAccess) tree).selected);
            case TYPEAPPLY:
                return getStartPos(((JCTypeApply) tree).clazz);
            case TYPEARRAY:
                return getStartPos(((JCArrayTypeTree) tree).elemtype);
            case TYPETEST:
                return getStartPos(((JCInstanceOf) tree).expr);
            case ANNOTATED_TYPE: {
                JCAnnotatedType node = (JCAnnotatedType) tree;
                if (node.annotations.nonEmpty()) {
                    if (node.underlyingType.hasTag(TYPEARRAY) ||
                            node.underlyingType.hasTag(SELECT)) {
                        return getStartPos(node.underlyingType);
                    } else {
                        return getStartPos(node.annotations.head);
                    }
                } else {
                    return getStartPos(node.underlyingType);
                }
            }
            case NEWCLASS: {
                JCNewClass node = (JCNewClass)tree;
                if (node.encl != null)
                    return getStartPos(node.encl);
                break;
            }
            case VARDEF: {
                JCVariableDecl node = (JCVariableDecl)tree;
                if (node.mods.pos != Position.NOPOS) {
                    return node.mods.pos;
                } else if (node.vartype == null) {
                    //if there's no type (partially typed lambda parameter)
                    //simply return node position
                    return node.pos;
                } else {
                    return getStartPos(node.vartype);
                }
            }
            case ERRONEOUS: {
                JCErroneous node = (JCErroneous)tree;
                if (node.errs != null && node.errs.nonEmpty())
                    return getStartPos(node.errs.head);
            }
        }
        return tree.pos;
    }
771215
def _tree_line(self, no_type: bool = False) -> str:
        """"""
        keys = (" [" + " ".join([k[0] for k in self.keys]) + "]"
                if self.keys else "")
        return super()._tree_line() + keys
945846
function getAtruler() {
  const type = NodeType.AtruleType;
  const token = tokens[pos];
  const line = token.ln;
  const column = token.col;
  const content = [].concat(
    getAtkeyword(),
    getTsets(),
    getAtrulers()
  );

  return newNode(type, content, line, column);
}