KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > js > JsKeywords


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.dev.js;
17
18 import java.util.HashSet JavaDoc;
19 import java.util.Set JavaDoc;
20
21 /**
22  * Determines whether or not a particular string is a JavaScript keyword or not.
23  */

24 public class JsKeywords {
25
26   private static Set JavaDoc sJavaScriptKeywords = new HashSet JavaDoc();
27
28   static {
29     initJavaScriptKeywords();
30   }
31
32   public static boolean isKeyword(String JavaDoc s) {
33     return sJavaScriptKeywords.contains(s);
34   }
35
36   private static synchronized void initJavaScriptKeywords() {
37     String JavaDoc[] keywords = new String JavaDoc[] {
38         // These are current keywords
39
//
40
"break", "delete", "function", "return", "typeof", "case", "do", "if",
41         "switch", "var", "catch", "else", "in", "this", "void", "continue",
42         "false", "instanceof", "throw", "while", "debugger",
43         "finally",
44         "new",
45         "true",
46         "with",
47         "default",
48         "for",
49         "null",
50         "try",
51
52         // These are future keywords
53
//
54
"abstract", "double", "goto", "native", "static", "boolean", "enum",
55         "implements", "package", "super", "byte", "export", "import",
56         "private", "synchronized", "char", "extends", "int", "protected",
57         "throws", "class", "final", "interface", "public", "transient",
58         "const", "float", "long", "short", "volatile"};
59
60     for (int i = 0; i < keywords.length; i++) {
61       sJavaScriptKeywords.add(keywords[i]);
62     }
63   }
64
65   private JsKeywords() {
66   }
67
68 }
69
Popular Tags