当前位置: 首页>>代码示例>>Java>>正文


Java TokenSequence.index方法代码示例

本文整理汇总了Java中org.netbeans.api.lexer.TokenSequence.index方法的典型用法代码示例。如果您正苦于以下问题:Java TokenSequence.index方法的具体用法?Java TokenSequence.index怎么用?Java TokenSequence.index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.api.lexer.TokenSequence的用法示例。


在下文中一共展示了TokenSequence.index方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: goAfterLastNewLine

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
@SuppressWarnings("empty-statement")
private static int goAfterLastNewLine(final TokenSequence<JavaTokenId> seq) {
    int base = seq.offset();
    seq.movePrevious();
    while (seq.moveNext() && nonRelevant.contains(seq.token().id())) ;
    
    while (seq.movePrevious() && nonRelevant.contains(seq.token().id())) {
        switch (seq.token().id()) {
            case LINE_COMMENT:
                seq.moveNext();
                return seq.offset();
            case WHITESPACE:
                char[] c = seq.token().text().toString().toCharArray();
                for (int i = c.length; i > 0; ) {
                    if (c[--i] == '\n') {
                        return seq.offset() + i + 1;
                    }
                }
        }
    }
    if ((seq.index() == 0 || seq.moveNext()) && nonRelevant.contains(seq.token().id())) {
        return seq.offset();
    }
    return base;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:PositionEstimator.java

示例2: lookForInline

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private void lookForInline(TokenSequence<JavaTokenId> seq, Tree tree) {
    seq.move((int) positions.getEndPosition(unit, tree));
    CommentsCollection result = new CommentsCollection();
    while (seq.moveNext()) {
        if (seq.token().id() == JavaTokenId.WHITESPACE) {
            if (numberOfNL(seq.token()) > 0) {
                break;
            }
        } else if (isComment(seq.token().id())) {
            if (alreadySeenJavadoc(seq.token(), seq)) {
                continue;
            }
            if (seq.index() > tokenIndexAlreadyAdded)
                result.add(seq.token());
            tokenIndexAlreadyAdded = seq.index();
            if (seq.token().id() == JavaTokenId.LINE_COMMENT) {
                break;
            }
        } else {
            break;
        }
    }
    attachComments(tree, result, CommentSet.RelativePosition.INLINE);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:AssignComments.java

示例3: lookWithinEmptyBlock

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private void lookWithinEmptyBlock(TokenSequence<JavaTokenId> seq, Tree tree) {
    // moving into opening brace.
    if (moveTo(seq, JavaTokenId.LBRACE, true)) {
        int idx = -1;
        if (seq.moveNext()) {
            JavaTokenId id = seq.token().id();
            idx = seq.index();
            if (id == JavaTokenId.WHITESPACE || isComment(id)) {
                CommentsCollection cc = getCommentsCollection(seq, Integer.MAX_VALUE);
                attachComments(tree, cc, CommentSet.RelativePosition.INNER);
            }
        }
        if (tokenIndexAlreadyAdded < idx) {
            tokenIndexAlreadyAdded = idx;
        }
    } else {
        int end = (int) positions.getEndPosition(unit, tree);
        seq.move(end); seq.moveNext();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:AssignComments.java

示例4: CacheBlockContent

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private CacheBlockContent(CharSequence code, TokenSequence<HTMLTokenId> tokenSequence, int firstTokenIndex) {
    this.firstTokenIndex = firstTokenIndex;
    //load the elements
    ElementsParser parser = ElementsParser.forTokenIndex(code, tokenSequence, firstTokenIndex);
    elements = new ArrayList<>(CACHE_BLOCK_SIZE);
    int limit = CACHE_BLOCK_SIZE;
    while (limit-- > 0 && parser.hasNext()) {
        elements.add(parser.next());
    }
    lastTokenIndex = tokenSequence.index();

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ElementsParserCache.java

示例5: forTokenIndex

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static ElementsParser forTokenIndex(CharSequence sourceCode, TokenSequence<HTMLTokenId> tokenSequence, int tokenIndex) {
    if (tokenIndex < 0) {
        throw new IllegalArgumentException(String.format("TokenSequence index (%s) must be positive", tokenIndex));
    }
    tokenSequence.moveEnd();
    int lastTokenIndex = tokenSequence.index();
    if(tokenIndex > lastTokenIndex) {
        throw new IllegalArgumentException(String.format("token index (%s) is bigger than last index in the sequence (%s)", tokenIndex, lastTokenIndex));
    }
    tokenSequence.moveIndex(tokenIndex);
    return new ElementsParser(sourceCode, tokenSequence);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ElementsParser.java

示例6: getCommentsCollection

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
     * Note - Because of {@link Comment.Style#WHITESPACE}, whitespaces are also
     * recorded
     */
    private CommentsCollection getCommentsCollection(TokenSequence<JavaTokenId> ts, int maxTension) {
        CommentsCollection result = new CommentsCollection();
        Token<JavaTokenId> t = ts.token();
        result.add(t);
        boolean isLC = t.id() == JavaTokenId.LINE_COMMENT;
        int lastCommentIndex = ts.index();
        int start = ts.offset();
        int end = ts.offset() + ts.token().length();
        while (ts.moveNext()) {
            if (ts.index() < tokenIndexAlreadyAdded) continue;
            t = ts.token();
            if (isComment(t.id())) {
                if (t.id() == JavaTokenId.JAVADOC_COMMENT &&
                    mixedJDocTokenIndexes.contains(ts.index())) {
                    // skip javadocs already added
                    continue;
                }
                result.add(t);
                start = Math.min(ts.offset(), start);
                end = Math.max(ts.offset() + t.length(), end);
                isLC = t.id() == JavaTokenId.LINE_COMMENT;
                lastCommentIndex = ts.index();                
            } else if (t.id() == JavaTokenId.WHITESPACE) {
                if ((numberOfNL(t) + (isLC ? 1 : 0)) > maxTension) {
                    break;
                }
            } else {
                break;                
            }
        }
        ts.moveIndex(lastCommentIndex);
        ts.moveNext();
        tokenIndexAlreadyAdded = ts.index();
        result.setBounds(new int[]{start, end});
//        System.out.println("tokenIndexAlreadyAdded = " + tokenIndexAlreadyAdded);
        return result;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:AssignComments.java

示例7: getTokenSequenceEndOffset

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static int getTokenSequenceEndOffset(TokenSequence<? extends TokenId> ts) {
    int currentIndex = ts.index();
    ts.moveEnd();
    ts.movePrevious();
    int offset = ts.offset() + ts.token().length();
    ts.moveIndex(currentIndex);
    return offset;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:LexUtilities.java

示例8: getTokenSequenceStartOffset

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static int getTokenSequenceStartOffset(TokenSequence<? extends TokenId> ts) {
    int currentIndex = ts.index();
    ts.moveStart();
    ts.moveNext();
    int offset = ts.offset();
    ts.moveIndex(currentIndex);
    return offset;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:LexUtilities.java

示例9: moveOrSkipSemicolon

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
 * Called to add semicolon after bracket for some conditions
 *
 * @param context
 * @return relative caretOffset change
 * @throws BadLocationException
 */
static int moveOrSkipSemicolon(TypedTextInterceptor.MutableContext context) throws BadLocationException {
    TokenSequence<JavaTokenId> javaTS = javaTokenSequence(context, false);
    if (javaTS == null || isStringOrComment(javaTS.token().id())) {
        return -1;
    }
    if (javaTS.token().id() == JavaTokenId.SEMICOLON) {
        context.setText("", 0); // NOI18N
        return javaTS.offset() + 1;
    }
    int lastParenPos = context.getOffset();
    int index = javaTS.index();
    // Move beyond semicolon
    while (javaTS.moveNext()
            && !(javaTS.token().id() == JavaTokenId.WHITESPACE && javaTS.token().text().toString().contains("\n"))
            && javaTS.token().id() != JavaTokenId.RBRACE) {  // NOI18N
        switch (javaTS.token().id()) {
            case RPAREN:
                lastParenPos = javaTS.offset();
                break;
            case WHITESPACE:
                break;
            default:
                return -1;
        }
    }
    // Restore javaTS position
    javaTS.moveIndex(index);
    javaTS.moveNext();
    if (isForLoopTryWithResourcesOrLambdaSemicolon(javaTS) || posWithinAnyQuote(context, javaTS) || (lastParenPos == context.getOffset() && !javaTS.token().id().equals(JavaTokenId.RPAREN))) {
        return -1;
    }
    context.setText("", 0); // NOI18N
    context.getDocument().insertString(lastParenPos + 1, ";", null); // NOI18N
    return lastParenPos + 2;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:TypingCompletion.java

示例10: isTypeParameterTag

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
 * simple check whether selected token is type parameter {@code @param <T>}
 * @param seq token sequence with selected token
 * @return {@code true} when the token should not be interpreted.
 */
private static boolean isTypeParameterTag(TokenSequence<? extends TokenId> seq) {
    int index = seq.index();
    try {
        if (!seq.movePrevious() || seq.token().id() != JavadocTokenId.OTHER_TEXT) {
            return false;
        }

        return seq.movePrevious() && seq.token().id() == JavadocTokenId.TAG
                && "@param".contentEquals(seq.token().text()); // NOI18N
    } finally {
        seq.moveIndex(index);
        seq.moveNext();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:JavadocBracesMatcher.java

示例11: insert

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
@Override
public void insert(MutableContext context) throws BadLocationException {
    final BaseDocument doc = (BaseDocument) context.getDocument();
    final int offset = context.getCaretOffset();
    final int lineStart = LineDocumentUtils.getLineStart(doc, offset);
    final int lineEnd = LineDocumentUtils.getLineEnd(doc, offset);
    if (lineStart == lineEnd) {
        //Empty line
        return;
    }
    final TokenSequence<DockerfileTokenId> seq = TokenHierarchy.get(doc).tokenSequence(DockerfileTokenId.language());
    if (seq == null) {
        return;
    }
    seq.move(offset);
    if (!seq.moveNext() && !seq.movePrevious()) {
        return;
    }
    final int tokenEnd = seq.index();
    Token<DockerfileTokenId> token;
    while ((token = seq.token()) != null && token.id() == DockerfileTokenId.WHITESPACE) {
        if (!seq.movePrevious()) {
            break;
        }
    }
    final boolean lineContinuation = isLineContinuation(token, offset-seq.offset());
    final Pair<Integer,TokenSequence<DockerfileTokenId>> p = findImportantLine(seq, doc, lineStart, tokenEnd);
    int indent;
    if (lineContinuation) {
        indent = IndentUtils.lineIndent(doc, p.first());
        if (p.second().token().id().isKeyword()) {
            indent+=IndentUtils.indentLevelSize(doc);
        }
    } else {
        token = p.second().token();
        if (token.id() == DockerfileTokenId.WHITESPACE) {
            indent = IndentUtils.lineIndent(doc, lineStart);
        } else {
            if (!token.id().isKeyword() && token.id() != DockerfileTokenId.LINE_COMMENT) {
                int kwOffset = findPrevKeyword(p.second());
                if (kwOffset != -1) {
                    indent = IndentUtils.lineIndent(doc, kwOffset);
                } else {
                    indent = IndentUtils.lineIndent(doc, p.first()) - IndentUtils.indentLevelSize(doc);
                }
            } else {
                indent = IndentUtils.lineIndent(doc, p.first());
            }
        }
    }
    final StringBuilder sb = new StringBuilder("\n");   //NOI18N
    sb.append(IndentUtils.createIndentString(doc, indent));
    context.setText(sb.toString(), 0, sb.length());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:55,代码来源:DockerfileTypedBreakInterceptor.java

示例12: isForLoopTryWithResourcesOrLambdaSemicolon

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean isForLoopTryWithResourcesOrLambdaSemicolon(TokenSequence<JavaTokenId> ts) {
    int parenDepth = 0; // parenthesis depth
    int braceDepth = 0; // brace depth
    boolean semicolonFound = false; // next semicolon
    int tsOrigIndex = ts.index();
    try {
        while (ts.movePrevious()) {
            switch (ts.token().id()) {
                case LPAREN:
                    if (parenDepth == 0) { // could be a 'for (' or 'try ('
                        while (ts.movePrevious()) {
                            switch (ts.token().id()) {
                                case WHITESPACE:
                                case BLOCK_COMMENT:
                                case JAVADOC_COMMENT:
                                case LINE_COMMENT:
                                    break; // skip
                                case FOR:
                                case TRY:
                                    return true;
                                default:
                                    return false;
                            }
                        }
                        return false;
                    } else { // non-zero depth
                        parenDepth--;
                    }
                    break;

                case RPAREN:
                    parenDepth++;
                    break;

                case LBRACE:
                    if (braceDepth == 0) { // unclosed left brace
                        if (!semicolonFound) {
                            while (ts.movePrevious()) {
                                switch (ts.token().id()) {
                                    case WHITESPACE:
                                    case BLOCK_COMMENT:
                                    case JAVADOC_COMMENT:
                                    case LINE_COMMENT:
                                        break; // skip
                                    case ARROW:
                                        return true;
                                    default:
                                        return false;
                                }
                            }
                        }
                        return false;
                    }
                    braceDepth--;
                    break;

                case RBRACE:
                    braceDepth++;
                    break;

                case SEMICOLON:
                    if (semicolonFound) { // one semicolon already found
                        return false;
                    }
                    semicolonFound = true;
                    break;
            }
        }
    } finally {
        // Restore orig TS's location
        ts.moveIndex(tsOrigIndex);
        ts.moveNext();
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:76,代码来源:TypingCompletion.java

示例13: test

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public void test() {
    String commentText = "/* test comment  */";
    String text = "abc+ " + commentText + "def public publica publi static x";
    int commentTextStartOffset = 5;
    TokenHierarchy<?> hi = TokenHierarchy.create(text,TestTokenId.language());
    TokenSequence<?> ts = hi.tokenSequence();
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "abc", 0);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.PLUS, "+", 3);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", 4);
    assertTrue(ts.moveNext());
    int offset = commentTextStartOffset;
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.BLOCK_COMMENT, commentText, offset);
    offset += commentText.length();
    int commentIndex = ts.index();

    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "def", offset);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", -1);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.PUBLIC, "public", -1);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", -1);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "publica", -1);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", -1);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "publi", -1);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", -1);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.STATIC, "static", -1);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", -1);
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "x", -1);
    assertFalse(ts.moveNext());

    // Go back to block comment
    assertEquals(0, ts.moveIndex(commentIndex));
    assertTrue(ts.moveNext());
    LexerTestUtilities.assertTokenEquals(ts,TestTokenId.BLOCK_COMMENT, commentText, commentTextStartOffset);

    // Test embedded token sequence
    TokenSequence<?> embedded = ts.embedded();
    assertNotNull("Null embedded sequence", embedded);
    assertTrue(embedded.moveNext());
    offset = commentTextStartOffset + 2; // skip "/*"
    LexerTestUtilities.assertTokenEquals(embedded,TestPlainTokenId.WHITESPACE, " ", offset);
    offset += 1;
    assertTrue(embedded.moveNext());
    LexerTestUtilities.assertTokenEquals(embedded,TestPlainTokenId.WORD, "test", offset);
    offset += 4;
    assertTrue(embedded.moveNext());
    LexerTestUtilities.assertTokenEquals(embedded,TestPlainTokenId.WHITESPACE, " ", offset);
    offset += 1;
    assertTrue(embedded.moveNext());
    LexerTestUtilities.assertTokenEquals(embedded,TestPlainTokenId.WORD, "comment", offset);
    offset += 7;
    assertTrue(embedded.moveNext());
    LexerTestUtilities.assertTokenEquals(embedded,TestPlainTokenId.WHITESPACE, "  ", offset);
    assertFalse(embedded.moveNext());

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:69,代码来源:SimpleLexerBatchTest.java


注:本文中的org.netbeans.api.lexer.TokenSequence.index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。