Search in sources :

Example 6 with WordRule

use of org.eclipse.jface.text.rules.WordRule 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)

Example 7 with WordRule

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

the class WordRuleTest method testBug163116.

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

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

        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)

Example 8 with WordRule

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

the class JSDTCodeScanner method initializeRules.

public void initializeRules() {
    List rules = new ArrayList();
    // Add rule for multiple line comments.
    // $NON-NLS-1$ //$NON-NLS-2$
    rules.add(new MultiLineRule("/*", "*/", fMultiLineCommentToken));
    // Add rule for single line comments.
    // $NON-NLS-1$ //$NON-NLS-2$s
    rules.add(new SingleLineRule("//", "\n", fSingleLineCommentToken));
    // Add rule for strings and character constants.
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("\"", "\"", fStringToken, '\\'));
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("'", "'", fStringToken, '\\'));
    // Add generic whitespace rule.
    // rules.add(new WhitespaceRule(new JavaWhitespaceDetector()));
    // Add word rule for keywords, types, and constants.
    WordRule wordRule = new WordRule(new JavaWordDetector(), fDefaultToken);
    for (int i = 0; i < JSDTCodeScanner.fgKeywords.length; i++) {
        wordRule.addWord(JSDTCodeScanner.fgKeywords[i], fKeywordToken);
    }
    for (int i = 0; i < JSDTCodeScanner.fgTypes.length; i++) {
        wordRule.addWord(JSDTCodeScanner.fgTypes[i], fTypeToken);
    }
    for (int i = 0; i < JSDTCodeScanner.fgConstants.length; i++) {
        wordRule.addWord(JSDTCodeScanner.fgConstants[i], fTypeToken);
    }
    rules.add(wordRule);
    // add word rule for HTML style comment delimiters
    // $NON-NLS-1$ //$NON-NLS-2$
    rules.add(new MultiLineRule("<!--", "-->", fHTMLCommentBorderToken));
    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
Also used : SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) ArrayList(java.util.ArrayList) List(java.util.List) WordRule(org.eclipse.jface.text.rules.WordRule) IRule(org.eclipse.jface.text.rules.IRule)

Example 9 with WordRule

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

the class JavaCodeScanner method initializeRules.

public void initializeRules() {
    List rules = new ArrayList();
    // Add rule for multiple line comments.
    // $NON-NLS-1$ //$NON-NLS-2$
    rules.add(new MultiLineRule("/*", "*/", fSingleLineCommentToken));
    // Add rule for single line comments.
    // $NON-NLS-1$
    rules.add(new EndOfLineRule("//", fSingleLineCommentToken));
    // Add rule for strings and character constants.
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("\"", "\"", fStringToken, '\\'));
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("'", "'", fStringToken, '\\'));
    // Add generic whitespace rule.
    // rules.add(new WhitespaceRule(new JavaWhitespaceDetector()));
    // Add word rule for keywords, types, and constants.
    WordRule wordRule = new WordRule(new JavaWordDetector(), fDefaultToken);
    for (int i = 0; i < fgKeywords.length; i++) wordRule.addWord(fgKeywords[i], fKeywordToken);
    for (int i = 0; i < fgTypes.length; i++) wordRule.addWord(fgTypes[i], fTypeToken);
    for (int i = 0; i < fgConstants.length; i++) wordRule.addWord(fgConstants[i], fTypeToken);
    rules.add(wordRule);
    // Add the double-quoted string rule
    rules.add(new DoubleQuotedStringRule(fStringToken));
    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
Also used : SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) List(java.util.List) ArrayList(java.util.ArrayList) WordRule(org.eclipse.jface.text.rules.WordRule) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule) IRule(org.eclipse.jface.text.rules.IRule)

Example 10 with WordRule

use of org.eclipse.jface.text.rules.WordRule in project hale by halestudio.

the class JavaDocScanner method createRules.

/*
	 * @see AbstractJavaScanner#createRules()
	 */
@Override
protected List<IRule> createRules() {
    List<IRule> list = new ArrayList<IRule>();
    // Add rule for tags.
    Token token = getToken(ColorConstants.JAVADOC_TAG);
    list.add(new TagRule(token));
    // Add rule for HTML comments
    WordRule wordRule = new WordRule(new HTMLCommentDetector(), token);
    // $NON-NLS-1$
    wordRule.addWord("<!--", token);
    // $NON-NLS-1$
    wordRule.addWord("--!>", token);
    list.add(wordRule);
    // Add rule for links.
    token = getToken(ColorConstants.JAVADOC_LINK);
    // $NON-NLS-2$ //$NON-NLS-1$
    list.add(new SingleLineRule("{@link", "}", token));
    // $NON-NLS-2$ //$NON-NLS-1$
    list.add(new SingleLineRule("{@value", "}", token));
    // $NON-NLS-2$ //$NON-NLS-1$
    list.add(new SingleLineRule("{@inheritDoc", "}", token));
    // Add generic whitespace rule.
    token = getToken(ColorConstants.JAVADOC_DEFAULT);
    list.add(new WhitespaceRule(new JavaWhitespaceDetector(), token));
    list.addAll(super.createRules());
    return list;
}
Also used : SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) ArrayList(java.util.ArrayList) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) WordRule(org.eclipse.jface.text.rules.WordRule) WhitespaceRule(org.eclipse.jface.text.rules.WhitespaceRule) IRule(org.eclipse.jface.text.rules.IRule)

Aggregations

WordRule (org.eclipse.jface.text.rules.WordRule)14 IToken (org.eclipse.jface.text.rules.IToken)11 IRule (org.eclipse.jface.text.rules.IRule)10 Token (org.eclipse.jface.text.rules.Token)10 Document (org.eclipse.jface.text.Document)8 IDocument (org.eclipse.jface.text.IDocument)8 RuleBasedScanner (org.eclipse.jface.text.rules.RuleBasedScanner)8 ArrayList (java.util.ArrayList)6 TextAttribute (org.eclipse.jface.text.TextAttribute)5 IWordDetector (org.eclipse.jface.text.rules.IWordDetector)4 PatternRule (org.eclipse.jface.text.rules.PatternRule)4 SingleLineRule (org.eclipse.jface.text.rules.SingleLineRule)4 Test (org.junit.Test)4 List (java.util.List)3 EndOfLineRule (org.eclipse.jface.text.rules.EndOfLineRule)3 MultiLineRule (org.eclipse.jface.text.rules.MultiLineRule)3 WhitespaceRule (org.eclipse.jface.text.rules.WhitespaceRule)3 Color (org.eclipse.swt.graphics.Color)1 StringDetectionPatternRule (org.eclipse.titan.designer.editors.StringDetectionPatternRule)1 WhiteSpaceDetector (org.eclipse.titan.designer.editors.WhiteSpaceDetector)1