class CheckRequiresForConstructors extends java.lang.Object implements HotSwapCompilerPass, NodeTraversal.Callback
The rules on when a warning is reported are:
Modifier and Type | Class and Description |
---|---|
static class |
CheckRequiresForConstructors.Mode |
Modifier and Type | Field and Description |
---|---|
private CodingConvention |
codingConvention |
private AbstractCompiler |
compiler |
private java.util.Set<java.lang.String> |
constructors |
private static java.util.Set<java.lang.String> |
DEFAULT_EXTRA_NAMESPACES |
(package private) static DiagnosticType |
DUPLICATE_REQUIRE_WARNING |
(package private) static DiagnosticType |
EXTRA_REQUIRE_WARNING |
(package private) static DiagnosticType |
MISSING_REQUIRE_WARNING |
private CheckRequiresForConstructors.Mode |
mode |
private java.util.Map<java.lang.String,Node> |
requires |
private java.util.Map<java.lang.String,Node> |
usages |
private java.util.Map<java.lang.String,Node> |
weakUsages |
Constructor and Description |
---|
CheckRequiresForConstructors(AbstractCompiler compiler,
CheckRequiresForConstructors.Mode mode) |
Modifier and Type | Method and Description |
---|---|
private boolean |
declaresFunction(Node n)
If this returns true, check for @extends and @implements annotations on this node.
|
private static java.lang.String |
getOutermostClassName(java.lang.String className) |
void |
hotSwapScript(Node scriptRoot,
Node originalRoot)
Process the JS with root node root.
|
private static boolean |
isClassName(java.lang.String name) |
private void |
maybeAddConstructor(Node n) |
private void |
maybeAddJsDocUsages(NodeTraversal t,
Node n) |
private void |
maybeAddUsage(NodeTraversal t,
Node n,
JSTypeExpression expr)
Adds a usage for the given type expression (unless it references a variable that is
defined in the externs, in which case no goog.require() is needed).
|
private void |
maybeAddUsage(NodeTraversal t,
Node n,
Node rootTypeNode,
java.util.Map<java.lang.String,Node> usagesMap,
com.google.common.base.Predicate<Node> pred) |
private void |
maybeAddWeakUsage(NodeTraversal t,
Node n,
Node typeNode)
Adds a weak usage for the given type expression (unless it references a variable that is
defined in the externs, in which case no goog.require() is needed).
|
void |
process(Node externs,
Node root)
Uses Collections of new and goog.require nodes to create a compiler warning
for each new class name without a corresponding goog.require().
|
private void |
reportDuplicateRequireWarning(Node call,
java.lang.String require) |
private void |
reportExtraRequireWarning(Node call,
java.lang.String require) |
private void |
reset() |
boolean |
shouldTraverse(NodeTraversal t,
Node n,
Node parent)
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed.
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
private void |
visitCallNode(Node call,
Node parent) |
private void |
visitClassNode(NodeTraversal t,
Node classNode) |
private void |
visitImportNode(Node importNode) |
private void |
visitNewNode(NodeTraversal t,
Node newNode) |
private void |
visitQualifiedName(Node getprop) |
private void |
visitRequire(java.lang.String requiredName,
Node node) |
private void |
visitScriptNode(NodeTraversal t) |
private final AbstractCompiler compiler
private final CodingConvention codingConvention
private final CheckRequiresForConstructors.Mode mode
private final java.util.Set<java.lang.String> constructors
private final java.util.Map<java.lang.String,Node> requires
private final java.util.Map<java.lang.String,Node> usages
private final java.util.Map<java.lang.String,Node> weakUsages
static final DiagnosticType MISSING_REQUIRE_WARNING
static final DiagnosticType EXTRA_REQUIRE_WARNING
static final DiagnosticType DUPLICATE_REQUIRE_WARNING
private static final java.util.Set<java.lang.String> DEFAULT_EXTRA_NAMESPACES
CheckRequiresForConstructors(AbstractCompiler compiler, CheckRequiresForConstructors.Mode mode)
public void process(Node externs, Node root)
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treepublic void hotSwapScript(Node scriptRoot, Node originalRoot)
HotSwapCompilerPass
hotSwapScript
in interface HotSwapCompilerPass
scriptRoot
- Root node corresponding to the file that is modified,
should be of type Token.SCRIPT
.originalRoot
- Root node corresponding to the original version of the
file that is modified. Should be of type token.SCRIPT
.private static boolean isClassName(java.lang.String name)
private static java.lang.String getOutermostClassName(java.lang.String className)
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed. If children are
traversed, they will be visited by
NodeTraversal.Callback.visit(NodeTraversal, Node, Node)
in postorder.
Implementations can have side effects (e.g. modifying the parse tree).
shouldTraverse
in interface NodeTraversal.Callback
public void visit(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in postorder (after its children have been visited).
A node is visited only if all its parents should be traversed
(NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
).
Implementations can have side effects (e.g. modifying the parse tree).
visit
in interface NodeTraversal.Callback
private void reset()
private void visitScriptNode(NodeTraversal t)
private void reportExtraRequireWarning(Node call, java.lang.String require)
private void reportDuplicateRequireWarning(Node call, java.lang.String require)
private void visitRequire(java.lang.String requiredName, Node node)
private void visitImportNode(Node importNode)
private void visitQualifiedName(Node getprop)
private void visitNewNode(NodeTraversal t, Node newNode)
private void visitClassNode(NodeTraversal t, Node classNode)
private void maybeAddConstructor(Node n)
private boolean declaresFunction(Node n)
function foo() {}
var foo = function() {};
foo.bar = function() {};
private void maybeAddJsDocUsages(NodeTraversal t, Node n)
private void maybeAddWeakUsage(NodeTraversal t, Node n, Node typeNode)
private void maybeAddUsage(NodeTraversal t, Node n, JSTypeExpression expr)
private void maybeAddUsage(NodeTraversal t, Node n, Node rootTypeNode, java.util.Map<java.lang.String,Node> usagesMap, com.google.common.base.Predicate<Node> pred)