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


Java TokenSequence.move方法代码示例

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


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

示例1: runWithSequence

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
 * Executes user code on token sequence from the document.
 * Read-locks the document, obtains {@link TokenSequence} from the Lexer and executes {@code userCode} 
 * passing the initialized sequence. The sequence is moved to the desired offset and the token that contains
 * or starts at that position. The client can move the sequence elsewhere.
 * <p/>
 * If the {@code userCode} calls this {@code SyntaxSupport} methods like {@link #getNextToken(int)}, they will use
 * the <b>same TokenSequence</b> as passed to {@code userCode}. This allows to combine navigation calls from {@link XMLSyntaxSupport}
 * with client's own sequence movements. The TokenSequence instance passed to {@code userCode} can be queried for
 * current token offset after navigation.
 * 
 * @param <T>
 * @param offset offset to position the sequence at
 * @param userCode code to execute
 * @return user-defined value
 * @throws BadLocationException if the user code throws BadLocationException
 * @throws IllegalStateException if the user code throws a checked exception
 */
@NullUnknown
public <T> T runWithSequence(int offset, SequenceCallable<T> userCode) throws BadLocationException {
    T result;
    TokenSequence old = null;
    try {
        ((AbstractDocument)document).readLock();
        old = cachedSequence.get();
        cachedSequence.remove();
        TokenSequence ts = getSequence();
        if (ts == null) {
            throw new BadLocationException("No sequence for position", offset); // NOI18N
        }
        cachedSequence.set(ts);
        synchronized (ts) {
            ts.move(offset);
            ts.moveNext();
            result = userCode.call(ts);
        }
    } finally {
        cachedSequence.set(old);
        ((AbstractDocument)document).readUnlock();
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:XMLSyntaxSupport.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: getJavaTokenSequence

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
 * @since 0.21
 */
public static TokenSequence<JavaTokenId> getJavaTokenSequence(final TokenHierarchy hierarchy, final int offset) {
    if (hierarchy != null) {
        TokenSequence<?> ts = hierarchy.tokenSequence();
        while(ts != null && (offset == 0 || ts.moveNext())) {
            ts.move(offset);
            if (ts.language() == JavaTokenId.language()) {
                return (TokenSequence<JavaTokenId>)ts;
            }
            if (!ts.moveNext() && !ts.movePrevious()) {
                return null;
            }
            ts = ts.embedded();
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SourceUtils.java

示例4: blockCommentCompletionImpl

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean blockCommentCompletionImpl(TypedBreakInterceptor.Context context, boolean javadoc) {
        TokenSequence<JavaTokenId> ts = javaTokenSequence(context, false);
        if (ts == null) {
            return false;
        }
        int dotPosition = context.getCaretOffset();
        ts.move(dotPosition);
        if (!((ts.moveNext() || ts.movePrevious()) && ts.token().id() == (javadoc ? JavaTokenId.JAVADOC_COMMENT : JavaTokenId.BLOCK_COMMENT))) {
            return false;
        }

        int jdoffset = dotPosition - (javadoc ? 3 : 2);
        if (jdoffset >= 0) {
            CharSequence content = org.netbeans.lib.editor.util.swing.DocumentUtilities.getText(context.getDocument());
            if (isOpenBlockComment(content, dotPosition - 1, javadoc) && !isClosedBlockComment(content, dotPosition) && isAtRowEnd(content, dotPosition)) {
                return true;
            }
        }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:TypingCompletion.java

示例5: removeTextLength

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
@Override
protected int removeTextLength(JTextComponent component, int offset, int removeLength) {
    if (removeLength <= 0) {
        return super.removeTextLength(component, offset, removeLength);
    }
    TokenSequence s = createTokenSequence(component);
    s.move(offset);
    s.moveNext();
    if (s.token().id() == XMLTokenId.TAG || s.token().id() == XMLTokenId.TEXT) {
        // replace entire tag, minus starting >
        if (s.token().text().toString().startsWith(CompletionUtil.TAG_FIRST_CHAR)) {
            return s.token().length() - (offset - s.offset());
        }
    }
    return super.removeTextLength(component, offset, removeLength);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ElementResultItem.java

示例6: findLastNonWhitespaceToken

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
TokenSequence<JavaTokenId> findLastNonWhitespaceToken(Env env, int startPos, int endPos) {
    TokenSequence<JavaTokenId> ts = env.getController().getTokenHierarchy().tokenSequence(JavaTokenId.language());
    ts.move(endPos);
    ts = previousNonWhitespaceToken(ts);
    if (ts == null || ts.offset() < startPos) {
        return null;
    }
    return ts;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:BaseTask.java

示例7: canCompleteBrace

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean canCompleteBrace(Document doc, int caretOffset) {
    SQLCompletionEnv env = SQLCompletionEnv.forDocument(doc, caretOffset);
    TokenSequence<SQLTokenId> seq = env.getTokenSequence();
    if (seq.move(env.getCaretOffset()) == 0 && seq.movePrevious()) {
        switch (seq.token().id()) {
            case WHITESPACE:
                return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:SQLTypedTextInterceptor.java

示例8: addSecondQuote

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static void addSecondQuote(MutableContext context) throws BadLocationException {
    if (!HtmlPreferences.autocompleteQuotes()) {
        return;
    }

    int dotPos = context.getOffset();
    char qchar = context.getText().charAt(0);
    //test whether the user typed an ending quotation in the attribute value
    TokenSequence<HTMLTokenId> ts = LexUtilities.getTokenSequence((BaseDocument) context.getDocument(), dotPos, HTMLTokenId.language());
    if (ts == null) {
        return;
    }
    int diff = ts.move(dotPos);
    if (diff == 0) {
        if (!ts.movePrevious()) {
            return;
        }
    } else {
        if (!ts.moveNext()) {
            return;
        }
    }

    Token<HTMLTokenId> token = ts.token();
    if (token.id() == HTMLTokenId.OPERATOR) {
        //check if the next token is a value 
        if (ts.moveNext()) {
            Token<HTMLTokenId> next = ts.token();
            if (isHtmlValueToken(next)) {
                return;
            }
        }

        //user typed quation just after equal sign after tag attribute name => complete the second quote
        StringBuilder insert = new StringBuilder().append(qchar).append(qchar);
        context.setText(insert.toString(), 1);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:HtmlTypedTextInterceptor.java

示例9: atOffset

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
 * Finds the starting tag token for the specified offset. It respects the 
 * search direction in the search context. May return {@code null} in the
 * case of an error or when tag could not be found.
 * 
 * @return starting tag Token
 */
private Token atOffset(TokenSequence ts, int offset) {
    int diff = ts.move(offset);
    if (diff == 0 && (context == null || context.isSearchingBackward())) {
        if (!ts.movePrevious()) {
            return null;
        }
    } else {
        if (!ts.moveNext()) {
            return null;
        }
    }
    if (diff == ts.token().text().length() - 1 && (context != null && !context.isSearchingBackward())) {
        if (!ts.moveNext()) {
            return null;
        }
    }
    
    do {
        Token t = ts.token();
        XMLTokenId id = (XMLTokenId)t.id();
        switch (id) {
            case ARGUMENT:
            case OPERATOR:
            case VALUE:
            case WS:
                // continue the cycle
                break;
            default:
                return t;
        }
    } while (ts.movePrevious());
    return ts.token();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:XMLBraceMatcher.java

示例10: analyzeContext

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private void analyzeContext(JavadocContext jdctx) {
    TokenSequence<JavadocTokenId> jdts = jdctx.jdts;
    if (jdts == null) {
        return;
    }
    
    jdts.move(this.caretOffset);
    if (!jdts.moveNext() && !jdts.movePrevious()) {
        // XXX solve /***/
        // provide block tags, inline tags, html
        return;
    }
    
    if (this.caretOffset - jdts.offset() == 0) {
        // if position in token == 0 resolve CC according to previous token
        jdts.movePrevious();
    }
    
    switch (jdts.token().id()) {
        case TAG:
            resolveTagToken(jdctx);
            break;
        case IDENT:
            resolveIdent(jdctx);
            break;
        case DOT:
            resolveDotToken(jdctx);
            break;
        case HASH:
            resolveHashToken(jdctx);
            break;
        case OTHER_TEXT:
            resolveOtherText(jdctx, jdts);
            break;
        case HTML_TAG:
            resolveHTMLToken(jdctx);
            break;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:JavadocCompletionQuery.java

示例11: findJavadocTokenSequence

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static TokenSequence<JavadocTokenId> findJavadocTokenSequence(CompilationInfo javac, int offset) {
    TokenSequence<JavaTokenId> ts = SourceUtils.getJavaTokenSequence(javac.getTokenHierarchy(), offset);
    if (ts == null || !movedToJavadocToken(ts, offset)) {
        return null;
    }
    
    TokenSequence<JavadocTokenId> jdts = ts.embedded(JavadocTokenId.language());
    if (jdts == null) {
        return null;
    }
    
    jdts.move(offset);
    return jdts;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:JavadocCompletionUtils.java

示例12: isInsideParamName

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
 * Checks if the passed position {@code pos} is inside name part of
 * some javadoc param tag.
 *
 * @param jdts javadoc token sequence to search
 * @param pos position to check
 * @return {@code true} if the position is inside the param name.
 */
public static boolean isInsideParamName(TokenSequence<JavadocTokenId> jdts, int pos) {
    int delta = jdts.move(pos);
    if ((jdts.moveNext() && (JavadocTokenId.IDENT == jdts.token().id() || JavadocTokenId.HTML_TAG == jdts.token().id())
            || delta == 0 && jdts.movePrevious() && (JavadocTokenId.IDENT == jdts.token().id() || JavadocTokenId.HTML_TAG == jdts.token().id()))
            && jdts.movePrevious() && JavadocTokenId.OTHER_TEXT == jdts.token().id()
            && jdts.movePrevious() && JavadocTokenId.TAG == jdts.token().id()) {
        return "@param".contentEquals(jdts.token().text());
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:JavadocImports.java

示例13: moveFwdToToken

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
static int moveFwdToToken(TokenSequence<JavaTokenId> tokenSequence, 
        final int pos,
        JavaTokenId id)
{
    tokenSequence.move(pos);
    tokenSequence.moveNext(); // Assumes the pos is located within input bounds
    while (!id.equals(tokenSequence.token().id())) {
        if (!tokenSequence.moveNext())
            return -1;
    }
    return tokenSequence.offset();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:PositionEstimator.java

示例14: isInstantRenameAllowed

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
@Override
public boolean isInstantRenameAllowed(EditorFeatureContext context) {
    TokenSequence<CssTokenId> tokenSequence = context.getTokenSequence();
    int diff = tokenSequence.move(context.getCaretOffset());
    if (diff > 0 && tokenSequence.moveNext() || diff == 0 && tokenSequence.movePrevious()) {
        Token<CssTokenId> token = tokenSequence.token();
        return token.id() == CssTokenId.AT_IDENT //less
                || token.id() == CssTokenId.SASS_VAR //sass
                || token.id() == CssTokenId.IDENT; //sass/less mixin name

    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:CPCssEditorModule.java

示例15: findPiContentOffsets

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private int[] findPiContentOffsets(FxNode node) {
    TokenSequence<XMLTokenId> seq = (TokenSequence<XMLTokenId>)hierarchy.tokenSequence();
    int start = -1;
    int end = -1;
    
    int s = nodes.positions(node).getStart();
    seq.move(s);
    boolean cont = true;
    while (cont && seq.moveNext()) {
        Token<XMLTokenId> token = seq.token();
        switch (token.id()) {
            case PI_TARGET:
            case PI_START:
            case WS:
                break;
            case PI_CONTENT:
                if (start == -1) {
                    start = seq.offset();
                }
                end = seq.offset() + token.length();
                break;
            default:
                cont = false;
        }
    }
    return new int[] { start, end };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ImportProcessor.java


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