ThriftListener.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:thrifty 作者:
/**
 * Read comments following the given token, until the first newline is encountered.
 *
 * INVARIANT:
 * Assumes that the parse tree is being walked top-down, left to right!
 *
 * Trailing-doc tokens are marked as such, so that subsequent searches for "leading"
 * doc don't grab tokens already used as "trailing" doc.  If the walk order is *not*
 * top-down, left-to-right, then the assumption underpinning the separation of leading
 * and trailing comments is broken.
 *
 * @param endToken the token from which to search for trailing comment tokens.
 * @return a list, possibly empty, of all trailing comment tokens.
 */
private List<Token> getTrailingComments(Token endToken) {
    List<Token> hiddenTokens = tokenStream.getHiddenTokensToRight(endToken.getTokenIndex(), Lexer.HIDDEN);

    if (hiddenTokens == null || hiddenTokens.isEmpty()) {
        return Collections.emptyList();
    }

    Token maybeTrailingDoc = hiddenTokens.get(0); // only one trailing comment is possible

    if (isComment(maybeTrailingDoc)) {
        trailingDocTokenIndexes.set(maybeTrailingDoc.getTokenIndex());
        return Collections.singletonList(maybeTrailingDoc);
    }

    return Collections.emptyList();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号