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


Java TokenHierarchy.embeddedTokenSequences方法代码示例

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


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

示例1: sameCommentHandler

import org.netbeans.api.lexer.TokenHierarchy; //导入方法依赖的package包/类
private boolean sameCommentHandler(TokenHierarchy<?> th, int offset, boolean backwardBias, CommentHandler cH) {
    CommentHandler cH2 = null;
    List<TokenSequence<?>> seqs = th.embeddedTokenSequences(offset, backwardBias);
    if (!seqs.isEmpty()) {
        for(int i = seqs.size() - 1; i >= 0; i--) {
            TokenSequence<?> ts = seqs.get(i);
            Language lang = LanguageRegistry.getInstance().getLanguageByMimeType(ts.language().mimeType());
            if (lang != null) {
                if (lang.getGsfLanguage() instanceof DefaultLanguageConfig) {
                    cH2 = ((DefaultLanguageConfig) lang.getGsfLanguage()).getCommentHandler();
                }
                break;
            }
        }
    }

    return cH2 != null && cH.getClass() == cH2.getClass();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ToggleBlockCommentAction.java

示例2: scanForSemicolon

import org.netbeans.api.lexer.TokenHierarchy; //导入方法依赖的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

示例3: getEmbeddedTokenSequences

import org.netbeans.api.lexer.TokenHierarchy; //导入方法依赖的package包/类
public static List<TokenSequence<?>> getEmbeddedTokenSequences(
    TokenHierarchy<?> th, int offset, boolean backwardBias, Language<?> language
) {
    List<TokenSequence<?>> sequences = th.embeddedTokenSequences(offset, backwardBias);

    for(int i = sequences.size() - 1; i >= 0; i--) {
        TokenSequence<?> seq = sequences.get(i);
        if (seq.language() == language) {
            break;
        } else {
            sequences.remove(i);
        }
    }
    
    return sequences;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JavaBracesMatcher.java

示例4: getAutoQueryTypes

import org.netbeans.api.lexer.TokenHierarchy; //导入方法依赖的package包/类
public int getAutoQueryTypes (JTextComponent component, String typedText) {
    if (".".equals(typedText)) { // NOI18N
        Document doc = component.getDocument ();
        TokenHierarchy<Document> tokenHierarchy = TokenHierarchy.get (doc);
        if (doc instanceof NbEditorDocument)
            ((NbEditorDocument) doc).readLock ();
        try {
            int offset = component.getCaret().getDot();
            if (offset <= 1) {
                return 0;
            }
            offset = offset - 2; //do Schlieman's magic
            
            List<TokenSequence<?>> sequences = tokenHierarchy.embeddedTokenSequences(offset, true);
            if(sequences.isEmpty()) {
                return 0; //no token sequence
            }
            TokenSequence<?> tokenSequence = sequences.get(sequences.size() - 1); //get the most embedded
            tokenSequence.move(offset);
            if (!tokenSequence.moveNext() && !tokenSequence.movePrevious()) {
                return 0;
            }
            Token<?> token = tokenSequence.token ();
            if (token.id().name().indexOf("identifier") > -1) { // NOI18N [PENDING]
                return COMPLETION_QUERY_TYPE;
            }
        } finally {
            if (doc instanceof NbEditorDocument)
                ((NbEditorDocument) doc).readUnlock ();
        }
    }
    return 0;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:CompletionProviderImpl.java

示例5: getLanguage

import org.netbeans.api.lexer.TokenHierarchy; //导入方法依赖的package包/类
public static Language<? extends TokenId> getLanguage(TokenHierarchy<BaseDocument> th, int offset) {
    List<TokenSequence<?>> list = th.embeddedTokenSequences(offset, true);

    if (list.isEmpty()) {
        return null;
    }
    return list.get(list.size()-1).language();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:LexUtilities.java

示例6: findHtmlValueToken

import org.netbeans.api.lexer.TokenHierarchy; //导入方法依赖的package包/类
private static boolean findHtmlValueToken(TokenHierarchy<?> hi, int offset, boolean backward) {
    List<TokenSequence<?>> embeddedTokenSequences = hi.embeddedTokenSequences(offset, backward);
    for (TokenSequence<?> htmlts : embeddedTokenSequences) {
        if (htmlts.language().mimeType().equals("text/html")) {
            //it relly looks like our parent ts
            int ediff = htmlts.move(offset);
            if (ediff == 0 && backward && htmlts.movePrevious() || htmlts.moveNext()) {
                TokenId id = htmlts.token().id();
                //XXX !!!! DEPENDENCY to HtmlTokenId !!!!
                return id.name().equals("VALUE_CSS");
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:CssTypedTextInterceptor.java

示例7: javaTokenSequence

import org.netbeans.api.lexer.TokenHierarchy; //导入方法依赖的package包/类
/**
 * Get token sequence positioned over a token.
 *
 * @param doc
 * @param caretOffset
 * @param backwardBias
 * @return token sequence positioned over a token that "contains" the offset
 * or null if the document does not contain any java token sequence or the
 * offset is at doc-or-section-start-and-bwd-bias or
 * doc-or-section-end-and-fwd-bias.
 */
private static TokenSequence<JavaTokenId> javaTokenSequence(Document doc, int caretOffset, boolean backwardBias) {
    TokenHierarchy<?> hi = TokenHierarchy.get(doc);
    List<TokenSequence<?>> tsList = hi.embeddedTokenSequences(caretOffset, backwardBias);
    // Go from inner to outer TSes
    for (int i = tsList.size() - 1; i >= 0; i--) {
        TokenSequence<?> ts = tsList.get(i);
        if (ts.languagePath().innerLanguage() == JavaTokenId.language()) {
            TokenSequence<JavaTokenId> javaInnerTS = (TokenSequence<JavaTokenId>) ts;
            return javaInnerTS;
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:TypingCompletion.java

示例8: getTokenSequence

import org.netbeans.api.lexer.TokenHierarchy; //导入方法依赖的package包/类
private TokenSequence getTokenSequence(Document doc, int offset) {
    TokenHierarchy<Document> th = TokenHierarchy.get(doc);
    List<TokenSequence<?>> sequences = th.embeddedTokenSequences(offset, true);
    TokenSequence htmlTs = null;
    for (TokenSequence ts : sequences) {
        if (ts.language().mimeType().equals("text/html")) { //NOI18N
            htmlTs = ts;
            break;
        }
    }
    return htmlTs;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:HtmlPaletteCompletionProvider.java

示例9: findOrigin

import org.netbeans.api.lexer.TokenHierarchy; //导入方法依赖的package包/类
public int[] findOrigin() throws BadLocationException, InterruptedException {
    ((AbstractDocument) context.getDocument()).readLock();
    try {
        int caretOffset = context.getSearchOffset();
        boolean backward = context.isSearchingBackward();

        TokenHierarchy<Document> th = TokenHierarchy.get(context.getDocument());
        List<TokenSequence<?>> sequences = th.embeddedTokenSequences(caretOffset, backward);

        for(int i = sequences.size() - 1; i >= 0; i--) {
            TokenSequence<? extends TokenId> seq = sequences.get(i);
            if (seq.language() == JavadocTokenId.language()) {
                jdocSeq = seq;
                if (i > 0) {
                    TokenSequence<? extends TokenId> javaSeq = sequences.get(i - 1);
                    jdocStart = javaSeq.offset();
                    jdocEnd = javaSeq.offset() + javaSeq.token().length();
                } else {
                    // jdocSeq is the top level sequence, ie the whole document is just javadoc
                    jdocStart = 0;
                    jdocEnd = context.getDocument().getLength();
                }
                break;
            }
        }

        if (jdocSeq == null) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Not javadoc TokenSequence."); //NOI18N
            }
            return null;
        }

//        if (caretOffset >= jdocStart && 
//            ((backward && caretOffset <= jdocStart + 3) ||
//            (!backward && caretOffset < jdocStart + 3))
//        ) {
//            matchingArea = new int [] { jdocEnd - 2, jdocEnd };
//            return new int [] { jdocStart, jdocStart + 3 };
//        }
//
//        if (caretOffset <= jdocEnd && 
//            ((backward && caretOffset > jdocEnd - 2) ||
//            (!backward && caretOffset >= jdocEnd - 2))
//        ) {
//            matchingArea = new int [] { jdocStart, jdocStart + 3 };
//            return new int [] { jdocEnd - 2, jdocEnd };
//        }

        // look for tags first
        jdocSeq.move(caretOffset);
        if (jdocSeq.moveNext()) {
            if (isTag(jdocSeq.token()) && !isTypeParameterTag(jdocSeq) && !isUninterpretedTag(jdocSeq)) {
                if (jdocSeq.offset() < caretOffset || !backward) {
                    return prepareOffsets(jdocSeq, true);
                }
            }

            while(moveTheSequence(jdocSeq, backward, context.getLimitOffset())) {
                if (isTag(jdocSeq.token())) {
                    if (isTypeParameterTag(jdocSeq) || isUninterpretedTag(jdocSeq)) {
                        // do not treat type parameter and {@code} and {@literal} content as HTML tag
                        break;
                    }
                    return prepareOffsets(jdocSeq, true);
                }
            }
        }

        defaultMatcher = BracesMatcherSupport.defaultMatcher(context, jdocStart, jdocEnd);
        return defaultMatcher.findOrigin();
    } finally {
        ((AbstractDocument) context.getDocument()).readUnlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:76,代码来源:JavadocBracesMatcher.java


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