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

Summary: TokenHierarchy.joinedTokenSequenceList(LanguagePath, from, to) method
Product: editor Reporter: Marek Fukala <mfukala>
Component: LexerAssignee: Miloslav Metelka <mmetelka>
Status: NEW ---    
Severity: blocker    
Priority: P2    
Version: 6.x   
Hardware: Macintosh   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

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.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;
                } else {
                    //the sequence is my master language
                    //get joined html sequence from it
                    sequence = sequence.embeddedJoined(HTMLTokenId.language());
                    assert sequence != null;
            sequence = ts;
        return sequence;