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


Java TokenSequence.moveNext方法代码示例

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


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

示例1: getTooltipText

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
@Override
public String getTooltipText(Document doc, int offset, HyperlinkType type) {
    TokenHierarchy th = TokenHierarchy.get(doc);
    TokenSequence<JavaTokenId> ts = SourceUtils.getJavaTokenSequence(th, offset);

    if (ts == null) {
        return null;
    }

    ts.move(offset);
    if (!ts.moveNext()) {
        return null;
    }

    Token<JavaTokenId> t = ts.token();
    FileObject fo = getFileObject(doc);
    String name = t.text().toString();
    name = name.substring(name.startsWith("\"") ? 1 : 0, name.endsWith("\"") ? name.length() - 1 : name.length());
    String query = findNq(fo, name);
    if (query != null) {
        return query;
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:NamedQueryHyperlinkProvider.java

示例2: tokenize

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static List<Token> tokenize(CharSequence input) {
    List<Token> stack = new LinkedList<>();
    TokenHierarchy<CharSequence> th = TokenHierarchy.create(input, CssTokenId.language());
    TokenSequence<CssTokenId> ts = th.tokenSequence(CssTokenId.language());
    ts.moveStart();
    while(ts.moveNext()) {
        org.netbeans.api.lexer.Token<CssTokenId> t = ts.token();
        switch(t.id()) {
            case WS:
            case NL:
                continue; //ignore WS
        }
        stack.add(new Token(t.id(), ts.offset(), t.length(), input));
    }
    return stack;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:Tokenizer.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: testScriptType_empty

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public void testScriptType_empty() {
    TokenHierarchy th = TokenHierarchy.create("<script type=\"\">plain</script>", HTMLTokenId.language());
    TokenSequence ts = th.tokenSequence();
    ts.moveStart();

    while(ts.moveNext()) {
        Token t = ts.token();
        if(t.id() == HTMLTokenId.SCRIPT) {
            String scriptType = (String)t.getProperty(HTMLTokenId.SCRIPT_TYPE_TOKEN_PROPERTY);
            assertNotNull(scriptType);
            assertEquals("", scriptType);
            return ;
        }
    }
    
    assertTrue("Couldn't find any SCRIPT token!", false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:HtmlLexerTest.java

示例5: moveToDifferentThan

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static JavaTokenId moveToDifferentThan(
    TokenSequence<JavaTokenId> seq,
    Direction dir,
    EnumSet<JavaTokenId> set, int boundary) 
{
    boolean notBound = false;
    switch (dir) {
        case BACKWARD:
            while ((notBound = seq.movePrevious()) /* && (boundary == -1 || seq.offset() >= boundary) */ && set.contains(seq.token().id())) {
                if (boundary != -1 && seq.offset() < boundary) {
                    notBound = false;
                    break;
                }
            }
            break;
        case FORWARD:
            while ((notBound = seq.moveNext()) && /* (boundary == -1 || seq.offset() < boundary) && */ set.contains(seq.token().id())) {
                if (boundary != -1 && seq.offset() >= boundary) {
                    notBound = false;
                    break;
                }
            }
            break;
    }
    return notBound ? seq.token().id() : null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:PositionEstimator.java

示例6: pathFor

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static TreePath pathFor(CompilationInfo info, int pos) {
    TokenSequence<JavaTokenId> ts = info.getTokenHierarchy().tokenSequence(JavaTokenId.language());

    ts.move(info.getSnapshot().getEmbeddedOffset(pos));

    if (ts.moveNext() && ts.token().id() == JavaTokenId.IDENTIFIER) {
        pos = ts.offset() + 1;
    }

    return info.getTreeUtilities().pathFor(pos);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:IntroduceAction.java

示例7: nextNonWhitespaceToken

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private TokenSequence<JavaTokenId> nextNonWhitespaceToken(TokenSequence<JavaTokenId> ts) {
    while (ts.moveNext()) {
        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,代码行数:15,代码来源:JPACodeCompletionProvider.java

示例8: prepareTestDocument

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private int prepareTestDocument(String text) throws Exception {
    ModificationTextDocument doc = new ModificationTextDocument();
    doc.insertString(0, text, null);
    doc.putProperty(Language.class, JavaTokenId.language());
    TokenHierarchy<?> hi = TokenHierarchy.get(doc);
    TokenSequence<?> ts = hi.tokenSequence();
    int tokenCount = 0;
    while (ts.moveNext()) { tokenCount++; }
    return tokenCount;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:JavaLexerPerformanceTest.java

示例9: skipAttributeValue

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static Token skipAttributeValue(TokenSequence ts, char delim) {
    do { 
        Token t = ts.token();
        if (t.text().charAt(t.length() - 1) == delim) {
            return ts.moveNext() ? ts.token() : null;
        }
    } while (ts.moveNext());
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:Tag.java

示例10: getNamespacesFromStartTags

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
 * Finds namespaces declared in all start tags in the document and keeps a map
 * of namespaces to their prefixes.
 * @param document
 * @return
 */
public static HashMap<String, String> getNamespacesFromStartTags(Document document) {
    HashMap<String, String> map = new HashMap<String, String>();
    ((AbstractDocument)document).readLock();
    try {
        TokenHierarchy th = TokenHierarchy.get(document);
        TokenSequence ts = th.tokenSequence();
        String lastNS = null;
        while(ts.moveNext()) {
            Token t = ts.token();
            if(t.id() == XMLTokenId.ARGUMENT &&
               t.text().toString().startsWith(XMLConstants.XMLNS_ATTRIBUTE)) {
                lastNS = t.text().toString();
            }
            if(t.id() == XMLTokenId.VALUE && lastNS != null) {
                String value = t.text().toString();
                if(value.length() >= 2 && (value.startsWith("'") || value.startsWith("\""))) {
                    value = value.substring(1, value.length()-1);
                }
                map.put(value, CompletionUtil.getPrefixFromXMLNS(lastNS));
                lastNS = null;
            }
        } //while loop            
    } finally {
        ((AbstractDocument)document).readUnlock();
    }
    return map;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:CompletionUtil.java

示例11: findCurrentToken

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private Token<OQLTokenId> findCurrentToken(JTextComponent component, TokenSequence<OQLTokenId> ts) {
    Token<OQLTokenId> currentToken = null;
    ts.moveStart();
    int forPosition = component.getCaretPosition();
    int position = 0;
    while(ts.moveNext()) {
        position = ts.offset();
        if (position >= forPosition) {
            ts.movePrevious();
            break;
        }
        currentToken = ts.token();
    }
    return currentToken;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:OQLCompletionProvider.java

示例12: findPrefix

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/** Returns part of token before cursor or entire token if at the end of it.
 * Returns null prefix if token is comma, rparen or whitespace. Returned offset is
 * caret offset if prefix is null, otherwise it is token offset. */
private Symbol findPrefix() {
    TokenSequence<SQLTokenId> seq = env.getTokenSequence();
    int caretOffset = env.getCaretOffset();
    String prefix = null;
    if (seq.move(caretOffset) > 0) {
        // Not on token boundary.
        if (!seq.moveNext() && !seq.movePrevious()) {
            return new Symbol(null, caretOffset, caretOffset);
        }
    } else {
        if (!seq.movePrevious()) {
            return new Symbol(null, caretOffset, caretOffset);
        }
    }
    switch (seq.token().id()) {
        case WHITESPACE:
        case COMMA:
        case RPAREN:
            return new Symbol(null, caretOffset, caretOffset);
        default:
            int offset = caretOffset - seq.offset();
            if (offset > 0 && offset < seq.token().length()) {
                prefix = seq.token().text().subSequence(0, offset).toString();
            } else {
                prefix = seq.token().text().toString();
            }
            return new Symbol(prefix, seq.offset(), seq.offset());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:SQLCompletionQuery.java

示例13: isClosingEndTagFoundAfter

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean isClosingEndTagFoundAfter(int caretPos,
    TokenSequence tokenSequence, String startTagName) {
    if ((tokenSequence == null) || (startTagName == null)) return false;
    tokenSequence.move(caretPos);
    
    int unclosedTagCount = 1;
    while (tokenSequence.moveNext()) {
        Token token = tokenSequence.token();
        String nextTagName = getTokenTagName(token);
        // fix for issue #185048
        // (http://netbeans.org/bugzilla/show_bug.cgi?id=185048)
        // also: must not count ends of nested tags, just the
        // same level
        if (isEndTagPrefix(token)) {
            if (unclosedTagCount-- == 0) {
                return false;
            }
        } else if (isTagFirstChar(token)) {
            unclosedTagCount++;
        } else {
            continue;
        }
        if (unclosedTagCount == 0) {
            if (isEndTagPrefix(token)) {
                return startTagName.equals(nextTagName);
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:CompletionUtil.java

示例14: 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

示例15: testFlyweightTokens

import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public void testFlyweightTokens() {
    assertEquals("a", HtmlElements.getCachedTagName("a"));
    assertEquals("div", HtmlElements.getCachedTagName("div"));
    assertEquals("td", HtmlElements.getCachedTagName("td"));
    assertNull(HtmlElements.getCachedTagName("Xdiv"));
    assertNull(HtmlElements.getCachedTagName("divX"));
    assertNull(HtmlElements.getCachedTagName("t"));
    assertNull(HtmlElements.getCachedTagName("fKHl"));

    assertEquals("onclick", HtmlElements.getCachedAttrName("onclick"));
    assertNull(HtmlElements.getCachedAttrName("fKHl"));
    assertNull(HtmlElements.getCachedAttrName("ht"));

    String code = "<div align='center'></div>";
    TokenHierarchy th = TokenHierarchy.create(code, HTMLTokenId.language());
    TokenSequence<HTMLTokenId> ts = th.tokenSequence();
    ts.moveStart();

    while(ts.moveNext()) {
        HTMLTokenId id = ts.token().id();
        switch (id) {
            case ARGUMENT:
            case TAG_CLOSE:
            case TAG_OPEN:
            case TAG_CLOSE_SYMBOL:
            case TAG_OPEN_SYMBOL:
            case OPERATOR:

                assertTrue(ts.token().isFlyweight());

                break;
        }
    }

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


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