Search in sources :

Example 6 with RuleBasedPartitionScanner

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

the class AbstractPairMatcherTest method createPartitioner.

private static IDocumentPartitioner createPartitioner() {
    final RuleBasedPartitionScanner scan = new RuleBasedPartitionScanner();
    final List<SingleLineRule> rules = new ArrayList<>();
    rules.add(new SingleLineRule("|a", "a|", new Token("a")));
    rules.add(new SingleLineRule("|b", "b|", new Token("b")));
    rules.add(new SingleLineRule("|c", "c|", new Token("c")));
    scan.setPredicateRules(rules.toArray(new IPredicateRule[rules.size()]));
    scan.setDefaultReturnToken(new Token(DEFAULT_PARTITION));
    return new FastPartitioner(scan, new String[] { DEFAULT_PARTITION, "a", "b", "c" });
}
Also used : RuleBasedPartitionScanner(org.eclipse.jface.text.rules.RuleBasedPartitionScanner) SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) ArrayList(java.util.ArrayList) Token(org.eclipse.jface.text.rules.Token) IPredicateRule(org.eclipse.jface.text.rules.IPredicateRule)

Example 7 with RuleBasedPartitionScanner

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

the class FastPartitionerTest method testBug409538_2.

@Test
public void testBug409538_2() throws Exception {
    fPartitioner.disconnect();
    IPartitionTokenScanner scanner = new RuleBasedPartitionScanner() {

        {
            IToken comment = new Token(COMMENT);
            IPredicateRule[] rules = new IPredicateRule[] { new MultiLineRule("<!--", "-->", comment, (char) 0, true) };
            setPredicateRules(rules);
        }
    };
    fPartitioner = createPartitioner(scanner);
    fDoc.setDocumentPartitioner(fPartitioner);
    fPartitioner.connect(fDoc);
    fDoc.set("<!-- blah");
    assertEqualPartition(0, 9, COMMENT);
}
Also used : RuleBasedPartitionScanner(org.eclipse.jface.text.rules.RuleBasedPartitionScanner) IToken(org.eclipse.jface.text.rules.IToken) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) IPartitionTokenScanner(org.eclipse.jface.text.rules.IPartitionTokenScanner) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) IPredicateRule(org.eclipse.jface.text.rules.IPredicateRule) Test(org.junit.Test)

Example 8 with RuleBasedPartitionScanner

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

the class FastPartitionerTest method testPR130900.

@Test
public void testPR130900() throws Exception {
    fPartitioner.disconnect();
    IPartitionTokenScanner scanner = new RuleBasedPartitionScanner() {

        {
            IToken comment = new Token(COMMENT);
            IPredicateRule[] rules = new IPredicateRule[] { new SingleLineRule("#", null, comment, (char) 0, true, false) };
            setPredicateRules(rules);
        }
    };
    fPartitioner = createPartitioner(scanner);
    fDoc.setDocumentPartitioner(fPartitioner);
    fPartitioner.connect(fDoc);
    fDoc.set("#");
    int[] offsets = new int[] { 0, 1 };
    assertComputePartitioning_InterleavingPartitions(offsets);
}
Also used : RuleBasedPartitionScanner(org.eclipse.jface.text.rules.RuleBasedPartitionScanner) IToken(org.eclipse.jface.text.rules.IToken) SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) IPartitionTokenScanner(org.eclipse.jface.text.rules.IPartitionTokenScanner) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) IPredicateRule(org.eclipse.jface.text.rules.IPredicateRule) Test(org.junit.Test)

Example 9 with RuleBasedPartitionScanner

use of org.eclipse.jface.text.rules.RuleBasedPartitionScanner in project linuxtools by eclipse.

the class SuppressionsDocumentProvider method getDocument.

@Override
public IDocument getDocument(Object element) {
    IDocument document = super.getDocument(element);
    if (document != null) {
        FastPartitioner partitioner = new FastPartitioner(new RuleBasedPartitionScanner(), SuppressionsPartitionScanner.SUPP_CONTENT_TYPES);
        partitioner.connect(document, false);
        if (document.getDocumentPartitioner() == null) {
            document.setDocumentPartitioner(partitioner);
        }
    }
    return document;
}
Also used : RuleBasedPartitionScanner(org.eclipse.jface.text.rules.RuleBasedPartitionScanner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

RuleBasedPartitionScanner (org.eclipse.jface.text.rules.RuleBasedPartitionScanner)9 IPredicateRule (org.eclipse.jface.text.rules.IPredicateRule)8 Token (org.eclipse.jface.text.rules.Token)8 IPartitionTokenScanner (org.eclipse.jface.text.rules.IPartitionTokenScanner)7 IToken (org.eclipse.jface.text.rules.IToken)7 MultiLineRule (org.eclipse.jface.text.rules.MultiLineRule)6 Test (org.junit.Test)5 IDocument (org.eclipse.jface.text.IDocument)3 FastPartitioner (org.eclipse.jface.text.rules.FastPartitioner)3 Document (org.eclipse.jface.text.Document)2 SingleLineRule (org.eclipse.jface.text.rules.SingleLineRule)2 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1