01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
19: import java.util.Set;
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<String> sJavaScriptKeywords = new HashSet<String>();
27:
28: static {
29: initJavaScriptKeywords();
30: }
31:
32: public static boolean isKeyword(String s) {
33: return sJavaScriptKeywords.contains(s);
34: }
35:
36: private static synchronized void initJavaScriptKeywords() {
37: String[] keywords = new String[] {
38: // These are current keywords
39: //
40: "break", "delete", "function", "return", "typeof",
41: "case", "do", "if", "switch", "var", "catch", "else",
42: "in", "this", "void", "continue", "false",
43: "instanceof", "throw",
44: "while",
45: "debugger",
46: "finally",
47: "new",
48: "true",
49: "with",
50: "default",
51: "for",
52: "null",
53: "try",
54:
55: // These are future keywords
56: //
57: "abstract", "double", "goto", "native", "static",
58: "boolean", "enum", "implements", "package", "super",
59: "byte", "export", "import", "private", "synchronized",
60: "char", "extends", "int", "protected", "throws",
61: "class", "final", "interface", "public", "transient",
62: "const", "float", "long", "short", "volatile" };
63:
64: for (int i = 0; i < keywords.length; i++) {
65: sJavaScriptKeywords.add(keywords[i]);
66: }
67: }
68:
69: private JsKeywords() {
70: }
71:
72: }
|