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


Java TokenSequence.offset方法代码示例

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


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

示例1: findLastNonWhitespaceToken

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static TokenSequence<JavaTokenId> findLastNonWhitespaceToken(TokenSequence<JavaTokenId> ts, int startPos, int endPos) {
    ts.move(endPos);
    while(ts.movePrevious()) {
        int offset = ts.offset();
        if (offset < startPos) {
            return null;
        }
        switch (ts.token().id()) {
            case WHITESPACE:
            case LINE_COMMENT:
            case BLOCK_COMMENT:
            case JAVADOC_COMMENT:
                break;
            default:
                return ts;
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:JavaCompletionItem.java

示例2: getFirstChildLocked

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private Node getFirstChildLocked(TokenSequence ts) {
    while (ts.moveNext()) {
        Token<XMLTokenId> t = ts.token();
        if (t.id() == XMLTokenId.VALUE) {
            // fuzziness to relax minor tokenization changes
            CharSequence image = t.text();
            if (image.length() == 1) {
                char test = image.charAt(0);
                if (test == '"' || test == '\'') {
                    if (ts.moveNext()) {
                        t = ts.token();
                    } else {
                        return null;
                    }
                }
            }
            
            if (t.id() == XMLTokenId.VALUE) {
                return new TextImpl(syntax, t, ts.offset(), ts.offset() + t.length(), this);
            } else {
                return null;
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AttrImpl.java

示例3: findBwd

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
 * Search forwards in the token sequence until a matching closing token is
 * found so keeps track of nested pairs of up-down eg (()) is ignored if
 * we're searching for a )
 *
 * @param ts the TokenSequence set to the position after an up
 * @param up the opening token eg { or [
 * @param down the closing token eg } or ]
 * @return the Range of closing token in our case 1 char
 */
public static OffsetRange findBwd(TokenSequence<? extends SQLTokenId> ts, int up, int down) {
    int balance = 0;

    while (ts.movePrevious()) {
        Token<? extends SQLTokenId> token = ts.token();

        if (token.id().ordinal() == up) {
            if (balance == 0) {
                return new OffsetRange(ts.offset(), ts.offset() + token.length());
            }

            balance++;
        } else if (token.id().ordinal() == down) {
            balance--;
        }
    }

    return OffsetRange.NONE;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:LexerUtilities.java

示例4: scanForSemicolon

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static int scanForSemicolon(Document doc, int[] offset, int start, int end) throws BadLocationException {
    TokenHierarchy<Document> th = doc != null ? TokenHierarchy.get(doc) : null;
    List<TokenSequence<?>> embeddedSequences = th != null ? th.embeddedTokenSequences(offset[0], false) : null;
    TokenSequence<?> seq = embeddedSequences != null ? embeddedSequences.get(embeddedSequences.size() - 1) : null;

    if (seq == null) {
        return offset[0];
    }   

    seq.move(start);

    int semicolon = -1;
    while(seq.moveNext()) {
        int tokenOffset = seq.offset();
        if(tokenOffset > end) {
            break;
        }
        Token<?> t = seq.token();
        if(t != null && t.id() == JavaTokenId.SEMICOLON ) {
            semicolon = tokenOffset;
            break;
        }
    }
    return semicolon;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:AddPropertyCodeGenerator.java

示例5: findFirstSentence

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private int [] findFirstSentence(TokenSequence<? extends TokenId> seq) {
    seq.moveStart();
    if (seq.moveNext()) {
        int start = seq.offset();
        do {
            if (seq.token().id() == JavadocTokenId.DOT) {
                if (seq.moveNext()) {
                    if (isWhiteSpace(seq.token())) {
                        return new int [] { start, seq.offset()};
                    }
                    seq.movePrevious();
                 }
            } else if (seq.token().id() == JavadocTokenId.TAG) {
                if (seq.movePrevious()) {
                    if (!seq.token().text().toString().trim().endsWith("{")) {
                        //not an inline tag
                        return new int [] { start, seq.offset()};
                    }
                }
                seq.moveNext();
            }
        } while (seq.moveNext());
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:Highlighting.java

示例6: isEmpty

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean isEmpty (
    int                     ln,
    StyledDocument          document,
    Set<Integer>            whitespaces
) throws BadLocationException {
    int start = NbDocument.findLineOffset (document, ln);
    int end = document.getLength ();
    try {
        end = NbDocument.findLineOffset (document, ln + 1) - 1;
    } catch (IndexOutOfBoundsException ex) {
    }
    TokenSequence ts = Utils.getTokenSequence (document, start);
    if (ts.token () == null) return true;
    while (whitespaces.contains (ts.token ().id ().ordinal ())) {
        if (!ts.moveNext ()) return true;
        if (ts.offset () > end) return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:IndentFactory.java

示例7: isCaretInsideTag

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static boolean isCaretInsideTag(int caretPos, TokenSequence tokenSequence) {
    if (! isTokenSequenceUsable(tokenSequence)) return false;

    boolean tagFirstCharFound = false, tagLastCharFound = false;
    Token token = null;

    boolean checkComment = tokenSequence.move(caretPos) != 0;
    tokenSequence.moveNext();
    do {
        token = tokenSequence.token();
        if (isTagFirstChar(token)) {
            tagFirstCharFound = true;
            break;
        } else if (checkComment && token.id() == XMLTokenId.BLOCK_COMMENT) {
            return true;
        }
        checkComment = false;
    } while (tokenSequence.movePrevious());
    
    if (! tagFirstCharFound) return false;

    while (tokenSequence.moveNext()) {
        token = tokenSequence.token();
        int tokenOffset = tokenSequence.offset();
        boolean isEndTagSuffix = isEndTagSuffix(token);
        if (isTagLastChar(token) || isEndTagSuffix) {
            if ((tokenOffset >= caretPos) ||
                (isEndTagSuffix && (tokenOffset == caretPos - 1))) {
                tagLastCharFound = true;
            }
            break;
        }
        if (token.id() == XMLTokenId.TAG || token.id() == XMLTokenId.TEXT) {
            if (token.text().charAt(0) == '<') {
                break;
            }
        }
    }
    return (tagFirstCharFound && tagLastCharFound);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:CompletionUtil.java

示例8: getCssAreaRange

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private OffsetRange getCssAreaRange(Document doc, int from, int to) {
    //limit the search just to one embedded css section
    TokenSequence<CssTokenId> ts = getCssTokenSequence(doc, from);
    if (ts == null) {
        return OffsetRange.NONE;
    }
    ts.moveStart();
    int limitedFrom = ts.moveNext() ? ts.offset() : from;
    ts.moveEnd();
    int limitedTo = ts.moveNext() ? ts.offset() + ts.token().length() : to;

    return new OffsetRange(limitedFrom, limitedTo);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:CssCommentHandler.java

示例9: embeddedPrologLength

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private int embeddedPrologLength(
    TokenSequence<?> embeddingSeq, 
    TokenSequence<?> embeddedSeq) 
{
    embeddedSeq.moveStart();
    if (embeddedSeq.moveNext()) {
        return embeddedSeq.offset() - embeddingSeq.offset();
    } else {
        return -1;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:SyntaxHighlightingTest.java

示例10: isInHeader

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean isInHeader(CompilationInfo info, ClassTree tree, int offset) {
    CompilationUnitTree cut = info.getCompilationUnit();
    SourcePositions sp = info.getTrees().getSourcePositions();
    long lastKnownOffsetInHeader = sp.getStartPosition(cut, tree);
    
    List<? extends Tree> impls = tree.getImplementsClause();
    List<? extends TypeParameterTree> typeparams;
    if (impls != null && !impls.isEmpty()) {
        lastKnownOffsetInHeader= sp.getEndPosition(cut, impls.get(impls.size() - 1));
    } else if ((typeparams = tree.getTypeParameters()) != null && !typeparams.isEmpty()) {
        lastKnownOffsetInHeader= sp.getEndPosition(cut, typeparams.get(typeparams.size() - 1));
    } else if (tree.getExtendsClause() != null) {
        lastKnownOffsetInHeader = sp.getEndPosition(cut, tree.getExtendsClause());
    } else if (tree.getModifiers() != null) {
        lastKnownOffsetInHeader = sp.getEndPosition(cut, tree.getModifiers());
    }
    
    TokenSequence<JavaTokenId> ts = info.getTreeUtilities().tokensFor(tree);
    
    ts.move((int) lastKnownOffsetInHeader);
    
    while (ts.moveNext()) {
        if (ts.token().id() == JavaTokenId.LBRACE) {
            return offset < ts.offset();
        }
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:JavadocUtilities.java

示例11: getRealMimeType

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private String getRealMimeType(TokenSequence ts, int offset) {
    while (true) {
        ts.move(offset);
        if (!ts.moveNext())
            break;
        offset = ts.offset();
        TokenSequence ts2 = ts.embedded();
        if (ts2 == null) break;
        ts = ts2;
    }
    return ts.language().mimeType();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:CodeUncommentAction.java

示例12: findJavadoc

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static TreePath findJavadoc(CompilationInfo javac, int offset) {
    TokenSequence<JavaTokenId> ts = SourceUtils.getJavaTokenSequence(javac.getTokenHierarchy(), offset);
    if (ts == null || !movedToJavadocToken(ts, offset)) {
        return null;
    }

    int offsetBehindJavadoc = ts.offset() + ts.token().length();

    while (ts.moveNext()) {
        TokenId tid = ts.token().id();
        if (tid == JavaTokenId.BLOCK_COMMENT) {
            if ("/**/".contentEquals(ts.token().text())) { // NOI18N
                // see #147533
                return null;
            }
        } else if (tid == JavaTokenId.JAVADOC_COMMENT) {
            if (ts.token().partType() == PartType.COMPLETE) {
                return null;
            }
        } else if (!IGNORE_TOKES.contains(tid)) {
            offsetBehindJavadoc = ts.offset();
            // it is magic for TreeUtilities.pathFor
            ++offsetBehindJavadoc;
            break;
        }
    }

    TreePath tp = javac.getTreeUtilities().pathFor(offsetBehindJavadoc);
    
    while (!TreeUtilities.CLASS_TREE_KINDS.contains(tp.getLeaf().getKind()) && tp.getLeaf().getKind() != Kind.METHOD && tp.getLeaf().getKind() != Kind.VARIABLE && tp.getLeaf().getKind() != Kind.COMPILATION_UNIT) {
        tp = tp.getParentPath();
        if (tp == null) {
            break;
        }
    }
    
    return tp;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:JavadocCompletionUtils.java

示例13: posWithinQuotes

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean posWithinQuotes(Document doc, int caretOffset, JavaTokenId tokenId) {
    TokenSequence<JavaTokenId> javaTS = javaTokenSequence(doc, caretOffset, false);
    if (javaTS != null) {
        if (javaTS.token().id() != tokenId) {
            return false;
        }
        else if (caretOffset > javaTS.offset() && caretOffset < javaTS.offset() + javaTS.token().length()) {
            return true;
        }
        else {
            return false;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:TypingCompletion.java

示例14: parentEatsTralingComment

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private boolean parentEatsTralingComment(TokenSequence<JavaTokenId> seq, Tree t) {
    if (parent == null || lastWhiteNewline == -1) {
        return false;
    }
    int commentIndent = seq.offset() - lastWhiteNewline;
    Tree.Kind k = parent.getKind();
    boolean ok =  k == Tree.Kind.WHILE_LOOP || k == Tree.Kind.DO_WHILE_LOOP || k == Tree.Kind.IF;
    if (!ok) {
        return false;
    }
    // check indentation:
    int treeIndent = countIndent(seq, t);
    return (treeIndent < commentIndent);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:AssignComments.java

示例15: posWithinAnyQuote

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean posWithinAnyQuote(TypedTextInterceptor.MutableContext context, TokenSequence<JavaTokenId> javaTS) throws BadLocationException {
    if (javaTS.token().id() == JavaTokenId.STRING_LITERAL || javaTS.token().id() == JavaTokenId.CHAR_LITERAL) {
        char chr = context.getDocument().getText(context.getOffset(), 1).charAt(0);
        return (context.getOffset() - javaTS.offset() == 1 || (chr != '"' && chr != '\''));
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:TypingCompletion.java


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