PSITokenSource.java 文件源码

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

项目:jetbrains 作者:
/** Create an ANTLR Token from the current token type of the builder
     *  then advance the builder to next token (which ultimately calls an
     *  ANTLR lexer).  The {@link ANTLRLexerAdaptor} creates tokens via
     *  an ANTLR lexer but converts to {@link TokenIElementType} and here
     *  we have to convert back to an ANTLR token using what info we
     *  can get from the builder. We lose info such as the original channel.
     *  So, whitespace and comments (typically hidden channel) will look like
     *  real tokens. Jetbrains uses {@link ParserDefinition#getWhitespaceTokens()}
     *  and {@link ParserDefinition#getCommentTokens()} to strip these before
     *  our ANTLR parser sees them.
     */
    @Override
    public Token nextToken() {
        ProgressIndicatorProvider.checkCanceled();

        TokenIElementType ideaTType = (TokenIElementType)builder.getTokenType();
        int type = ideaTType!=null ? ideaTType.getANTLRTokenType() : Token.EOF;

        int channel = Token.DEFAULT_CHANNEL;
        Pair<TokenSource, CharStream> source = new Pair<TokenSource, CharStream>(this, null);
        String text = builder.getTokenText();
        int start = builder.getCurrentOffset();
        int length = text != null ? text.length() : 0;
        int stop = start + length - 1;
        // PsiBuilder doesn't provide line, column info
        int line = 0;
        int charPositionInLine = 0;
        Token t = tokenFactory.create(source, type, text, channel, start, stop, line, charPositionInLine);
        builder.advanceLexer();
//      System.out.println("TOKEN: "+t);
        return t;
    }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号