Search in sources :

Example 51 with IToken

use of org.eclipse.jface.text.rules.IToken in project eclipse.platform.text by eclipse.

the class WordRuleTest method testBug163116.

/*
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=163116
	 */
@Test
public void testBug163116() throws Exception {
    IWordDetector detector = new IWordDetector() {

        @Override
        public boolean isWordPart(char c) {
            return true;
        }

        @Override
        public boolean isWordStart(char c) {
            return true;
        }
    };
    WordRule rule = new WordRule(detector, new Token(this));
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(new IRule[] { rule });
    scanner.setRange(new Document(), 0, 0);
    IToken token = null;
    int i = 0;
    while (token != Token.EOF && i++ < 1000) token = scanner.nextToken();
    assertTrue(i < 1000);
}
Also used : IWordDetector(org.eclipse.jface.text.rules.IWordDetector) IToken(org.eclipse.jface.text.rules.IToken) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) WordRule(org.eclipse.jface.text.rules.WordRule) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) RuleBasedScanner(org.eclipse.jface.text.rules.RuleBasedScanner) Test(org.junit.Test)

Example 52 with IToken

use of org.eclipse.jface.text.rules.IToken in project tmdm-studio-se by Talend.

the class ElementFKInfoColorProvider method getToken.

public IToken getToken(String prefKey) {
    Token token = (Token) tokenTable.get(prefKey);
    if (token == null) {
        String colorName = store.getString(prefKey);
        if (colorName == null || colorName.isEmpty()) {
            if (prefKey.equals(ElementFKInfoConfiguration.PREF_COLOR_DEFAULT)) {
                // $NON-NLS-1$
                colorName = "0,128,0";
            } else if (prefKey.equals(ElementFKInfoConfiguration.PREF_COLOR_STRING)) {
                // $NON-NLS-1$
                colorName = "0,0,255";
            } else if (prefKey.equals(ElementFKInfoConfiguration.PREF_COLOR_KEYWORD)) {
                // $NON-NLS-1$
                colorName = "0,0,128";
            }
        }
        RGB rgb = StringConverter.asRGB(colorName);
        token = new Token(new TextAttribute(getColor(rgb)));
        tokenTable.put(prefKey, token);
    }
    return token;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) RGB(org.eclipse.swt.graphics.RGB)

Example 53 with IToken

use of org.eclipse.jface.text.rules.IToken in project tmdm-studio-se by Talend.

the class XMLDocumentPartitioner method initialize.

protected void initialize() {
    partitionScanner.setRange(document, 0, document.getLength());
    try {
        for (IToken token = partitionScanner.nextToken(); !token.isEOF(); token = partitionScanner.nextToken()) {
            String contentType = getTokenContentType(token);
            if (isSupportedContentType(contentType)) {
                TypedPosition p = createPosition(partitionScanner.getTokenOffset(), partitionScanner.getTokenLength(), contentType);
                addPosition(document, positionCategory, p);
            }
        }
    } catch (BadLocationException _ex) {
    } catch (BadPositionCategoryException _ex) {
    }
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) TypedPosition(org.eclipse.jface.text.TypedPosition) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 54 with IToken

use of org.eclipse.jface.text.rules.IToken in project tmdm-studio-se by Talend.

the class XMLDocumentPartitioner method documentChanged2.

public IRegion documentChanged2(DocumentEvent e) {
    try {
        IDocument d = e.getDocument();
        Position[] category = d.getPositions(positionCategory);
        IRegion line = d.getLineInformationOfOffset(e.getOffset());
        int reparseStart = line.getOffset();
        int partitionStart = -1;
        String contentType = null;
        int first = d.computeIndexInCategory(positionCategory, reparseStart);
        if (first > 0) {
            TypedPosition partition = (TypedPosition) category[first - 1];
            if (partition.includes(reparseStart)) {
                partitionStart = partition.getOffset();
                contentType = partition.getType();
                if (e.getOffset() == partition.getOffset() + partition.getLength()) {
                    reparseStart = partitionStart;
                }
                first--;
            } else if (reparseStart == e.getOffset() && reparseStart == partition.getOffset() + partition.getLength()) {
                partitionStart = partition.getOffset();
                contentType = partition.getType();
                reparseStart = partitionStart;
                first--;
            } else {
                partitionStart = partition.getOffset() + partition.getLength();
                // $NON-NLS-1$
                contentType = "__dftl_partition_content_type";
            }
        }
        positionUpdater.update(e);
        for (int i = first; i < category.length; i++) {
            Position p = category[i];
            if (!p.isDeleted) {
                continue;
            }
            rememberDeletedOffset(e.getOffset());
            break;
        }
        category = d.getPositions(positionCategory);
        partitionScanner.setPartialRange(d, reparseStart, d.getLength() - reparseStart, contentType, partitionStart);
        int lastScannedPosition = reparseStart;
        for (IToken token = partitionScanner.nextToken(); !token.isEOF(); ) {
            contentType = getTokenContentType(token);
            if (!isSupportedContentType(contentType)) {
                token = partitionScanner.nextToken();
            } else {
                int start = partitionScanner.getTokenOffset();
                int length = partitionScanner.getTokenLength();
                lastScannedPosition = (start + length) - 1;
                for (; first < category.length; first++) {
                    TypedPosition p = (TypedPosition) category[first];
                    if (lastScannedPosition < p.offset + p.length && (!p.overlapsWith(start, length) || d.containsPosition(positionCategory, start, length) && contentType.equals(p.getType()))) {
                        break;
                    }
                    rememberRegion(p.offset, p.length);
                    d.removePosition(positionCategory, p);
                }
                if (d.containsPosition(positionCategory, start, length)) {
                    if (lastScannedPosition > e.getOffset()) {
                        return createRegion();
                    }
                    first++;
                } else {
                    try {
                        TypedPosition p = createPosition(start, length, contentType);
                        addPosition(d, positionCategory, p);
                        rememberRegion(start, length);
                    } catch (BadPositionCategoryException _ex) {
                    } catch (BadLocationException _ex) {
                    }
                }
                token = partitionScanner.nextToken();
            }
        }
        if (lastScannedPosition != reparseStart)
            lastScannedPosition++;
        for (first = d.computeIndexInCategory(positionCategory, lastScannedPosition); first < category.length; ) {
            TypedPosition p = (TypedPosition) category[first++];
            d.removePosition(positionCategory, p);
            rememberRegion(p.offset, p.length);
        }
    } catch (BadPositionCategoryException _ex) {
    } catch (BadLocationException _ex) {
    }
    return createRegion();
}
Also used : TypedPosition(org.eclipse.jface.text.TypedPosition) Position(org.eclipse.jface.text.Position) IToken(org.eclipse.jface.text.rules.IToken) TypedPosition(org.eclipse.jface.text.TypedPosition) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 55 with IToken

use of org.eclipse.jface.text.rules.IToken in project abstools by abstools.

the class Preferences method getToken.

public static IToken getToken(IPreferenceStore store, String postfix) {
    Color color = new Color(Display.getCurrent(), PreferenceConverter.getColor(store, SYNTAXCOLOR_COLOR + postfix));
    IToken token = new Token(new TextAttribute(color, null, computeAttributes(store, postfix)));
    return token;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token)

Aggregations

IToken (org.eclipse.jface.text.rules.IToken)77 Token (org.eclipse.jface.text.rules.Token)25 Test (org.junit.Test)21 IDocument (org.eclipse.jface.text.IDocument)17 TextAttribute (org.eclipse.jface.text.TextAttribute)16 Document (org.eclipse.jface.text.Document)15 BadLocationException (org.eclipse.jface.text.BadLocationException)13 MultiLineRule (org.eclipse.jface.text.rules.MultiLineRule)13 IPartitionTokenScanner (org.eclipse.jface.text.rules.IPartitionTokenScanner)10 IPredicateRule (org.eclipse.jface.text.rules.IPredicateRule)10 IRule (org.eclipse.jface.text.rules.IRule)10 RuleBasedPartitionScanner (org.eclipse.jface.text.rules.RuleBasedPartitionScanner)10 ArrayList (java.util.ArrayList)9 WordRule (org.eclipse.jface.text.rules.WordRule)8 SingleLineRule (org.eclipse.jface.text.rules.SingleLineRule)6 NotNull (org.jkiss.code.NotNull)6 RuleBasedScanner (org.eclipse.jface.text.rules.RuleBasedScanner)5 Color (org.eclipse.swt.graphics.Color)5 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)4 TypedPosition (org.eclipse.jface.text.TypedPosition)4