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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations