KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > js > ast > JsRootScope


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.ast;
17
18 /**
19  * The root scope is the parent of every scope. All identifiers in this scope
20  * are not obfuscatable.
21  */

22 public final class JsRootScope extends JsScope {
23
24   private final JsProgram program;
25
26   public JsRootScope(JsProgram program) {
27     super("Root");
28     this.program = program;
29     ctorAddKnownGlobalSymbols();
30   }
31
32   public JsProgram getProgram() {
33     return program;
34   }
35
36   protected JsName doCreateName(String JavaDoc ident, String JavaDoc shortIdent) {
37     JsName name = super.doCreateName(ident, shortIdent);
38     name.setObfuscatable(false);
39     return name;
40   }
41
42   private void ctorAddKnownGlobalSymbols() {
43     // HACK: debugger is modelled as an ident even though it's really a keyword
44
String JavaDoc[] commonBuiltins = new String JavaDoc[] {
45         "ActiveXObject", "Array", "Boolean", "Date", "Debug", "Enumerator",
46         "Error", "Function", "Global", "Image", "Math", "Number", "Object",
47         "RegExp", "String", "VBArray", "window", "document", "event",
48         "arguments", "call", "toString", "$wnd", "$doc", "$moduleName",
49         "$moduleBase", "debugger", "undefined"};
50
51     for (int i = 0; i < commonBuiltins.length; i++) {
52       String JavaDoc ident = commonBuiltins[i];
53       this.doCreateName(ident, ident);
54     }
55   }
56
57 }
58
Popular Tags