class ProcessDefines extends java.lang.Object implements CompilerPass
@define. A define is
a special constant that may be overridden by later files and
manipulated by the compiler, much like C preprocessor #defines.| Modifier and Type | Class and Description |
|---|---|
private static class |
ProcessDefines.CollectDefines
Finds all assignments to @defines, and figures out the last value of
the @define.
|
private static class |
ProcessDefines.DefineInfo
A simple class for storing information about a define.
|
| Modifier and Type | Field and Description |
|---|---|
private AbstractCompiler |
compiler |
(package private) static DiagnosticType |
DEFINE_NOT_ASSIGNABLE_ERROR |
private java.util.Map<java.lang.String,Node> |
dominantReplacements |
(package private) static DiagnosticType |
INVALID_DEFINE_INIT_ERROR |
(package private) static DiagnosticType |
INVALID_DEFINE_TYPE_ERROR |
private static java.util.Set<java.lang.String> |
KNOWN_DEFINES
Defines in this set will not be flagged with "unknown define" warnings.
|
private GlobalNamespace |
namespace |
(package private) static DiagnosticType |
NON_GLOBAL_DEFINE_INIT_ERROR |
private static MessageFormat |
REASON_DEFINE_NOT_ASSIGNABLE |
(package private) static DiagnosticType |
UNKNOWN_DEFINE_WARNING |
| Constructor and Description |
|---|
ProcessDefines(AbstractCompiler compiler,
java.util.Map<java.lang.String,Node> replacements)
Create a pass that overrides define constants.
|
| Modifier and Type | Method and Description |
|---|---|
private java.util.Map<java.lang.String,ProcessDefines.DefineInfo> |
collectDefines(Node root,
GlobalNamespace namespace)
Finds all defines, and creates a
ProcessDefines.DefineInfo data structure for
each one. |
private static java.lang.String |
format(MessageFormat format,
java.lang.Object... params) |
(package private) ProcessDefines |
injectNamespace(GlobalNamespace namespace)
Injects a pre-computed global namespace, so that the same namespace
can be re-used for multiple check passes.
|
private boolean |
isValidDefineType(JSTypeExpression expression)
Only defines of literal number, string, or boolean are supported.
|
private void |
overrideDefines(java.util.Map<java.lang.String,ProcessDefines.DefineInfo> allDefines) |
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
private static final java.util.Set<java.lang.String> KNOWN_DEFINES
private final AbstractCompiler compiler
private final java.util.Map<java.lang.String,Node> dominantReplacements
private GlobalNamespace namespace
static final DiagnosticType UNKNOWN_DEFINE_WARNING
static final DiagnosticType INVALID_DEFINE_TYPE_ERROR
static final DiagnosticType INVALID_DEFINE_INIT_ERROR
static final DiagnosticType NON_GLOBAL_DEFINE_INIT_ERROR
static final DiagnosticType DEFINE_NOT_ASSIGNABLE_ERROR
private static final MessageFormat REASON_DEFINE_NOT_ASSIGNABLE
ProcessDefines(AbstractCompiler compiler, java.util.Map<java.lang.String,Node> replacements)
replacements from command-line flagsreplacements - A hash table of names of defines to their replacements.
All replacements must be literals.ProcessDefines injectNamespace(GlobalNamespace namespace)
this for
easy chaining.public void process(Node externs, Node root)
CompilerPassprocess in interface CompilerPassexterns - Top of external JS treeroot - Top of JS treeprivate void overrideDefines(java.util.Map<java.lang.String,ProcessDefines.DefineInfo> allDefines)
private static java.lang.String format(MessageFormat format, java.lang.Object... params)
private boolean isValidDefineType(JSTypeExpression expression)
private java.util.Map<java.lang.String,ProcessDefines.DefineInfo> collectDefines(Node root, GlobalNamespace namespace)
ProcessDefines.DefineInfo data structure for
each one.ProcessDefines.DefineInfo structures, keyed by name.