This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 146020 - TokenHierarchy.joinedTokenSequenceList(LanguagePath, from, to) method
Summary: TokenHierarchy.joinedTokenSequenceList(LanguagePath, from, to) method
Status: NEW
Alias: None
Product: editor
Classification: Unclassified
Component: Lexer (show other bugs)
Version: 6.x
Hardware: Macintosh All
: P2 blocker (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-03 10:58 UTC by Marek Fukala
Modified: 2008-09-03 10:58 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Fukala 2008-09-03 10:58:54 UTC
A method from subject would be handy for some clients. The current way how to get that is quite complicated:

   /*
     * supposes html tokens are always joined - just one joined sequence over the document!
     */
    public static TokenSequence<HTMLTokenId> getJoinedHtmlSequence(Document doc, LanguagePath languagePath) {
        //find html token sequence, in joined version if embedded
        TokenHierarchy th = TokenHierarchy.get(doc);
        List<TokenSequence> tslist = th.tokenSequenceList(languagePath, 0, Integer.MAX_VALUE);
        if(tslist.isEmpty()) {
            return  null; //no such sequence
        }
        TokenSequence first = tslist.get(0);
        first.moveStart(); 
        first.moveNext(); //should return true
        
        List<TokenSequence> embedded = th.embeddedTokenSequences(first.offset(), true);
        if(embedded.isEmpty()) {
            //try forward bias if we didn't find anything backward
            embedded = th.embeddedTokenSequences(first.offset(), false);
        }
        TokenSequence sequence = null;
        for (TokenSequence ts : embedded) {
            if (ts.language() == HTMLTokenId.language()) {
                if (sequence == null) {
                    //html is top level
                    sequence = ts;
                    break;
                } else {
                    //the sequence is my master language
                    //get joined html sequence from it
                    sequence = sequence.embeddedJoined(HTMLTokenId.language());
                    assert sequence != null;
                    break;
                }
            }
            sequence = ts;
        }
        return sequence;
    }