KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > editors > JimpleScanner


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package ca.mcgill.sable.soot.editors;
21
22 import java.util.*;
23 import org.eclipse.jface.text.rules.*;
24 import org.eclipse.jface.text.*;
25
26 public class JimpleScanner extends RuleBasedScanner {
27
28   private static String JavaDoc[] keywords= {
29         "ignored",
30         "abstract",
31         "final",
32         "native",
33         "public",
34         "protected",
35         "private",
36         "static",
37         "synchronized",
38         "transient",
39         "volatile",
40         "class",
41         "interface",
42         "void",
43         "boolean",
44         "byte",
45         "short",
46         "char",
47         "int",
48         "long",
49         "float",
50         "double",
51         "null_type",
52         "unknown",
53         "extends",
54         "implements",
55         "breakpoint",
56         "case",
57         "catch",
58         "cmp",
59         "cmpg",
60         "cmpl",
61         "default",
62         "entermonitor",
63         "exitmonitor",
64         "goto",
65         "if",
66         "instanceof",
67         "interfaceinvoke",
68         "lengthof",
69         "lookupswitch",
70         "neg",
71         "new",
72         "newarray",
73         "newmultiarray",
74         "nop",
75         "ret",
76         "return",
77         "specialinvoke",
78         "staticinvoke",
79         "tableswitch",
80         "throw",
81         "throws",
82         "virtualinvoke",
83         "null",
84         "from",
85         "to",
86         "with"
87         };
88         
89
90   public JimpleScanner(ColorManager manager) {
91      
92     List rules = new ArrayList();
93    
94     IToken string = new Token(new TextAttribute(manager.getColor(IJimpleColorConstants.JIMPLE_STRING)));
95     IToken def= new Token(new TextAttribute(manager.getColor(IJimpleColorConstants.JIMPLE_DEFAULT)));
96     IToken key= new Token(new TextAttribute(manager.getColor(IJimpleColorConstants.JIMPLE_KEYWORD)));
97    
98     rules.add(new SingleLineRule("\"", "\"", string, '\\'));
99     rules.add(new SingleLineRule("'", "'", string, '\\'));
100     
101     WordRule wordRule= new WordRule(new JimpleWordDetector(), def);
102     
103
104     for (int i=0; i<keywords.length; i++)
105          wordRule.addWord(keywords[i], key);
106        
107     rules.add(wordRule);
108
109
110     // Add generic whitespace rule.
111
rules.add(new WhitespaceRule(new JimpleWhitespaceDetector()));
112
113     IRule[] result = new IRule[rules.size()];
114     rules.toArray(result);
115     setRules(result);
116     }
117 }
118
Popular Tags