/** * Returns a Matcher that matches any function call that has the given * number of arguments and the given name. * @param name The name of the function to match. For non-static functions, * this must be the fully qualified name that includes the type of the * object. For instance: {@code ns.AppContext.prototype.get} will match * {@code appContext.get} and {@code this.get} when called from the * AppContext class. */ public static Matcher functionCallWithNumArgs(final String name, final int numArgs) { return allOf(functionCallWithNumArgs(numArgs), functionCall(name)); }
/** * Returns a matcher that matches any constructor definitions. */ public static Matcher constructor() { return constructor(null); }
/** * Returns a Matcher that matches a declaration of a variable on the * prototype of a class. */ public static Matcher prototypeVariableDeclaration() { return matcherForPrototypeDeclaration(false /* requireFunctionType */); }
/** * Returns a Matcher that matches any function call. */ public static Matcher functionCall() { return functionCall(null); }
/** * Returns a Matcher that matches any property access. */ public static Matcher propertyAccess() { return propertyAccess(null); }
String className = parts[0]; String propertyName = parts[1]; JSType providedJsType = getJsType(metadata, className); if (providedJsType == null) { return false;
private Node findGoogRequireNode(Node n, NodeMetadata metadata, String namespace) { Node script = NodeUtil.getEnclosingScript(n); if (script != null) { Node child = script.getFirstChild(); while (child != null) { if (child.isExprResult() && child.getFirstChild().isCall()) { // TODO(mknichel): Replace this logic with a function argument // Matcher when it exists. Node grandchild = child.getFirstChild(); if (Matchers.functionCall("goog.require").matches(child.getFirstChild(), metadata) && grandchild.getLastChild().isString() && namespace.equals(grandchild.getLastChild().getString())) { return child; } } child = child.getNext(); } } return null; }
@Override public boolean matches(Node node, NodeMetadata metadata) { // TODO(mknichel): Handle the case when functions are applied through .call or .apply. return node.isCall() && propertyAccess(name).matches(node.getFirstChild(), metadata); } };
if (Matchers.functionCall("goog.provide").matches(grandchild, metadata)) { lastGoogProvideNode = grandchild; } else if (Matchers.functionCall("goog.require").matches(grandchild, metadata)) { lastGoogRequireNode = grandchild; if (grandchild.getLastChild().isString()
/** * Returns a Matcher that matches a declaration of a method on the * prototype of a class. */ public static Matcher prototypeMethodDeclaration() { return matcherForPrototypeDeclaration(true /* requireFunctionType */); }