KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > editors > HQLScanner


1 package org.hibernate.eclipse.console.editors;
2
3 import org.eclipse.jdt.internal.compiler.parser.Parser;
4 import org.eclipse.jface.text.TextAttribute;
5 import org.eclipse.jface.text.rules.IRule;
6 import org.eclipse.jface.text.rules.IWhitespaceDetector;
7 import org.eclipse.jface.text.rules.IWordDetector;
8 import org.eclipse.jface.text.rules.RuleBasedScanner;
9 import org.eclipse.jface.text.rules.SingleLineRule;
10 import org.eclipse.jface.text.rules.Token;
11 import org.eclipse.jface.text.rules.WhitespaceRule;
12 import org.eclipse.jface.text.rules.WordRule;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.Color;
15 import org.eclipse.swt.graphics.RGB;
16
17 public class HQLScanner extends RuleBasedScanner {
18
19     public HQLScanner(ColorManager colorManager) {
20         WordRule rule = new WordRule(new IWordDetector() {
21            public boolean isWordStart(char c) {
22                return Character.isJavaIdentifierStart(c);
23            }
24            public boolean isWordPart(char c) {
25             return Character.isJavaIdentifierPart(c);
26            }
27         });
28         Token keyword = new Token(new TextAttribute(
29                 colorManager.getColor(new RGB(238,238,255)), null, SWT.BOLD));
30         Token comment = new Token(
31                 colorManager.getColor(new RGB(200,200,200)));
32         Token string = new Token(
33                 colorManager.getColor(new RGB(255,255,255)));
34         //add tokens for each reserved word
35
String JavaDoc[] KEYWORDS = new String JavaDoc[] {
36                 "from",
37                 "where",
38                 "as",
39         };
40         
41         for (int n = 0; n < KEYWORDS.length; n++)
42            rule.addWord(KEYWORDS[n], keyword);
43         setRules(new IRule[] {
44            rule,
45            //new SingleLineRule("#", null, comment),
46
new SingleLineRule("\"", "\"", string, '\\'),
47            new SingleLineRule("'", "'", string, '\\'),
48            new WhitespaceRule(new IWhitespaceDetector() {
49               public boolean isWhitespace(char c) {
50                  return Character.isWhitespace(c);
51               }
52            }),
53         });
54      }
55
56 }
57
Popular Tags