public abstract class JsScope extends Object implements Serializable
JsName
s. A
JavaScript AST is built in terms of abstract name objects without worrying about obfuscation,
keyword/identifier blacklisting, and so on.
Scopes are associated with JsFunction
s, but the two are not
equivalent. Functions have scopes, but a scope does not necessarily have an associated
Function. Examples of this include the JsRootScope
and
synthetic scopes that might be created by a client.
Scopes can have parents to provide constraints when allocating actual identifiers for names.
Specifically, names in child scopes are chosen such that they do not conflict with names in their
parent scopes. The ultimate parent is usually the global scope (see
JsProgram.getScope()
), but parentless scopes are useful
for managing names that are always accessed with a qualifier and could therefore never be
confused with the global scope hierarchy.
Modifier | Constructor and Description |
---|---|
protected |
JsScope(String description) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
addChild(JsScope child) |
JsName |
declareName(String ident)
Gets a name object associated with the specified ident in this scope, creating it if necessary.
|
JsName |
declareName(String ident,
String shortIdent)
Gets a name object associated with the specified ident in this scope, creating it if necessary.
|
protected abstract JsName |
doCreateName(String ident,
String shortIdent)
Creates a new name in this scope.
|
JsName |
findExistingName(String ident)
Attempts to find the name object for the specified ident, searching in this scope, and if not
found, in the parent scopes.
|
protected abstract JsName |
findExistingNameNoRecurse(String ident)
Attempts to find the name object for the specified ident, searching in this scope only.
|
JsName |
findExistingUnobfuscatableName(String ident)
Attempts to find an unobfuscatable name object for the specified ident, searching in this
scope, and if not found, in the parent scopes.
|
abstract Iterable<JsName> |
getAllNames()
Returns an iterable for all the names defined by this scope.
|
abstract List<JsScope> |
getChildren()
Returns a list of this scope's child scopes.
|
abstract JsScope |
getParent()
Returns the parent scope of this scope, or
null if this is the root scope. |
String |
toString() |
protected JsScope(String description)
public final JsName declareName(String ident)
ident
- An identifier that is unique within this scope.public final JsName declareName(String ident, String shortIdent)
ident
- An identifier that is unique within this scope.shortIdent
- A "pretty" name that does not have to be unique.IllegalArgumentException
- if ident already exists in this scope but the requested short
name does not match the existing short name.public final JsName findExistingName(String ident)
null
if the identifier has no associated namepublic final JsName findExistingUnobfuscatableName(String ident)
null
if the identifier has no associated namepublic abstract Iterable<JsName> getAllNames()
public abstract List<JsScope> getChildren()
public abstract JsScope getParent()
null
if this is the root scope.protected abstract void addChild(JsScope child)
protected abstract JsName doCreateName(String ident, String shortIdent)
Copyright © 2018. All rights reserved.