Search in sources :

Example 1 with PatternRule

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

the class WordRuleTest method testBug175712_2.

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
@Test
public void testBug175712_2() throws Exception {
    IRule[] rules = new IRule[2];
    IToken stepToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    PatternRule stepRule = new PatternRule("(((", ")", stepToken, (char) 0, false);
    stepRule.setColumnConstraint(-1);
    rules[1] = stepRule;
    IToken titleToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    WordRule wordRule = new WordRule(new SimpleWordDetector());
    wordRule.addWord("((", titleToken);
    rules[0] = wordRule;
    IDocument document = new Document("((\n((\n- Cheese\n- Wine");
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(rules);
    scanner.setRange(document, 0, document.getLength());
    IToken defaultToken = new Token(this);
    scanner.setDefaultReturnToken(defaultToken);
    IToken token = scanner.nextToken();
    assertSame(titleToken, token);
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) PatternRule(org.eclipse.jface.text.rules.PatternRule) TextAttribute(org.eclipse.jface.text.TextAttribute) 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) IRule(org.eclipse.jface.text.rules.IRule) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 2 with PatternRule

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

the class WordRuleTest method testBug175712_1.

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
@Test
public void testBug175712_1() throws Exception {
    IRule[] rules = new IRule[2];
    IToken stepToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    PatternRule stepRule = new PatternRule("(((", ")", stepToken, (char) 0, false);
    stepRule.setColumnConstraint(-1);
    rules[1] = stepRule;
    IToken titleToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    WordRule wordRule = new WordRule(new SimpleWordDetector());
    wordRule.addWord("((", titleToken);
    rules[0] = wordRule;
    IDocument document = new Document("((( \n((\n- Cheese\n- Wine");
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(rules);
    scanner.setRange(document, 0, document.getLength());
    IToken defaultToken = new Token(this);
    scanner.setDefaultReturnToken(defaultToken);
    IToken token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(titleToken, token);
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) PatternRule(org.eclipse.jface.text.rules.PatternRule) TextAttribute(org.eclipse.jface.text.TextAttribute) 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) IRule(org.eclipse.jface.text.rules.IRule) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 3 with PatternRule

use of org.eclipse.jface.text.rules.PatternRule in project netxms by netxms.

the class NXSLSourceViewerConfiguration method getPresentationReconciler.

/* (non-Javadoc)
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer)
	 */
@Override
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
    PresentationReconciler reconciler = new PresentationReconciler();
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(codeRules);
    scanner.setDefaultReturnToken(NXSLTextAttributeProvider.getTextAttributeToken(NXSLTextAttributeProvider.DEFAULT));
    DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
    dr = new DefaultDamagerRepairer(new SingleTokenScanner(NXSLTextAttributeProvider.getTextAttribute(NXSLTextAttributeProvider.COMMENT)));
    reconciler.setDamager(dr, NXSLDocument.CONTENT_COMMENTS);
    reconciler.setRepairer(dr, NXSLDocument.CONTENT_COMMENTS);
    scanner = new RuleBasedScanner();
    scanner.setRules(new IRule[] { new PatternRule("\"", "\n", NXSLTextAttributeProvider.getTextAttributeToken(NXSLTextAttributeProvider.ERROR), (char) 0, false) });
    scanner.setDefaultReturnToken(NXSLTextAttributeProvider.getTextAttributeToken(NXSLTextAttributeProvider.STRING));
    dr = new DefaultDamagerRepairer(scanner);
    reconciler.setDamager(dr, NXSLDocument.CONTENT_STRING);
    reconciler.setRepairer(dr, NXSLDocument.CONTENT_STRING);
    return reconciler;
}
Also used : PatternRule(org.eclipse.jface.text.rules.PatternRule) DefaultDamagerRepairer(org.eclipse.jface.text.rules.DefaultDamagerRepairer) IPresentationReconciler(org.eclipse.jface.text.presentation.IPresentationReconciler) PresentationReconciler(org.eclipse.jface.text.presentation.PresentationReconciler) RuleBasedScanner(org.eclipse.jface.text.rules.RuleBasedScanner)

Example 4 with PatternRule

use of org.eclipse.jface.text.rules.PatternRule in project webtools.sourceediting by eclipse.

the class WordRuleTest method testBug175712_1.

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
public void testBug175712_1() throws Exception {
    IRule[] rules = new IRule[2];
    IToken stepToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    PatternRule stepRule = new PatternRule("(((", ")", stepToken, (char) 0, false);
    stepRule.setColumnConstraint(-1);
    rules[1] = stepRule;
    IToken titleToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    WordRule wordRule = new WordRule(new SimpleWordDetector());
    wordRule.addWord("((", titleToken);
    rules[0] = wordRule;
    IDocument document = new Document("((( \n((\n- Cheese\n- Wine");
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(rules);
    scanner.setRange(document, 0, document.getLength());
    IToken defaultToken = new Token(this);
    scanner.setDefaultReturnToken(defaultToken);
    IToken token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(titleToken, token);
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) PatternRule(org.eclipse.jface.text.rules.PatternRule) TextAttribute(org.eclipse.jface.text.TextAttribute) 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) IRule(org.eclipse.jface.text.rules.IRule) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with PatternRule

use of org.eclipse.jface.text.rules.PatternRule in project webtools.sourceediting by eclipse.

the class WordRuleTest method testBug175712_2.

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
public void testBug175712_2() throws Exception {
    IRule[] rules = new IRule[2];
    IToken stepToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    PatternRule stepRule = new PatternRule("(((", ")", stepToken, (char) 0, false);
    stepRule.setColumnConstraint(-1);
    rules[1] = stepRule;
    IToken titleToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    WordRule wordRule = new WordRule(new SimpleWordDetector());
    wordRule.addWord("((", titleToken);
    rules[0] = wordRule;
    IDocument document = new Document("((\n((\n- Cheese\n- Wine");
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(rules);
    scanner.setRange(document, 0, document.getLength());
    IToken defaultToken = new Token(this);
    scanner.setDefaultReturnToken(defaultToken);
    IToken token = scanner.nextToken();
    assertSame(titleToken, token);
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) PatternRule(org.eclipse.jface.text.rules.PatternRule) TextAttribute(org.eclipse.jface.text.TextAttribute) 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) IRule(org.eclipse.jface.text.rules.IRule) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

PatternRule (org.eclipse.jface.text.rules.PatternRule)6 RuleBasedScanner (org.eclipse.jface.text.rules.RuleBasedScanner)6 Document (org.eclipse.jface.text.Document)4 IDocument (org.eclipse.jface.text.IDocument)4 TextAttribute (org.eclipse.jface.text.TextAttribute)4 IRule (org.eclipse.jface.text.rules.IRule)4 IToken (org.eclipse.jface.text.rules.IToken)4 Token (org.eclipse.jface.text.rules.Token)4 WordRule (org.eclipse.jface.text.rules.WordRule)4 IPresentationReconciler (org.eclipse.jface.text.presentation.IPresentationReconciler)2 PresentationReconciler (org.eclipse.jface.text.presentation.PresentationReconciler)2 DefaultDamagerRepairer (org.eclipse.jface.text.rules.DefaultDamagerRepairer)2 Test (org.junit.Test)2