@Override public boolean matches(Node n) { return n.matchesQualifiedName(node); } }
/** * Returns whether a node matches a simple or a qualified name, such as * <code>x</code> or <code>a.b.c</code> or <code>this.a</code>. */ public final boolean matchesQualifiedName(String name) { return name != null && matchesQualifiedName(name, name.length()); }
static boolean isImportRhs(@Nullable Node rhs) { if (rhs == null || !rhs.isCall()) { return false; } Node callee = rhs.getFirstChild(); return callee.matchesQualifiedName("goog.require") || callee.matchesQualifiedName("goog.requireType") || callee.matchesQualifiedName("goog.forwardDeclare") || callee.matchesQualifiedName("require"); }
private static boolean isKnownGlobalObjectReference(Node n) { switch (n.getToken()) { case NAME: return n.getString().equals("Object"); case GETPROP: return n.matchesQualifiedName("$jscomp.global.Object") || n.matchesQualifiedName("$jscomp$global.Object"); default: return false; } }
/** Is this the LHS of a goog.module export? i.e. Either "exports" or "exports.name" */ private boolean isExportLhs(Node lhs) { if (!lhs.isQualifiedName()) { return false; } return lhs.matchesQualifiedName("exports") || (lhs.isGetProp() && lhs.getFirstChild().matchesQualifiedName("exports")); }
/** * A faster version of {@link #isCallTo(Node, String)}. * * @param n node to check if a call * @param targetMethod the prebuilt AST getprop node that represents the method to check */ public static boolean isCallTo(Node n, Node targetMethod) { if (!n.isCall()) { return false; } return n.getFirstChild().matchesQualifiedName(targetMethod); }
/** * @return Whether the call represents a class definition. */ static boolean isGoogDefineClass(Node value) { if (value != null && value.isCall()) { return value.getFirstChild().matchesQualifiedName("goog.defineClass"); } return false; }
private boolean matchesCacheMethodName(Node target) { if (target.isGetProp()) { return target.matchesQualifiedName(googCacheReflect); } else if (target.isName()) { return target.getString().equals("goog$reflect$cache"); } return false; }
@Override public String getSingletonGetterClassName(Node callNode) { Node callArg = callNode.getFirstChild(); // Use both the original name and the post-CollapseProperties name. if (callNode.hasTwoChildren() && (callArg.matchesQualifiedName("goog.addSingletonGetter") || callArg.matchesQualifiedName("goog$addSingletonGetter"))) { return callArg.getNext().getQualifiedName(); } return super.getSingletonGetterClassName(callNode); }
private static boolean isTypedRhs(Node rhs) { return rhs.isFunction() || rhs.isClass() || NodeUtil.isCallTo(rhs, "goog.defineClass") || (rhs.isQualifiedName() && rhs.matchesQualifiedName("goog.abstractMethod")) || (rhs.isQualifiedName() && rhs.matchesQualifiedName("goog.nullFunction")); }
protected boolean isAssertionCall(Node n) { if (n.isCall() && n.getFirstChild().isQualifiedName()) { Node target = n.getFirstChild(); for (int i = 0; i < assertionsFunctionNames.size(); i++) { if (target.matchesQualifiedName(assertionsFunctionNames.get(i))) { return true; } } } return false; }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (!foundNonEmptyReturn) { if (n.isReturn() && n.hasChildren() && !n.getFirstChild().matchesQualifiedName("undefined")) { foundNonEmptyReturn = true; } } } };
/** @return Whether {@code n} is a reference to the global "Symbol" function. */ private boolean isGlobalSymbol(NodeTraversal t, Node n) { if (!n.matchesQualifiedName("Symbol")) { return false; } Var var = t.getScope().getVar("Symbol"); return var == null || var.isGlobal(); }
@Override public void visit(Node node) { if ((node.isName() && (node.getString().equals(MODULE) || node.getString().equals("define"))) || (node.isGetProp() && node.matchesQualifiedName("window.define")) || (node.isString() && node.getString().equals("amd") && node.getParent().isIn())) { umdTests.add(node); } } });
String getBasePropertyImport(String moduleName, Node requireCall) { checkArgument(requireCall.isCall()); if (compiler.getOptions().getModuleResolutionMode() == ModuleLoader.ResolutionMode.WEBPACK && requireCall.getFirstChild().matchesQualifiedName(WEBPACK_REQUIRE_NAMESPACE)) { return moduleName; } return getBasePropertyImport(moduleName); }
static boolean isSafeNamespaceReinit(Ref ref) { // allow "a = a || {}" or "var a = a || {}" or "var a;" Node valParent = getValueParent(ref); Node val = valParent.getLastChild(); if (val != null && val.isOr()) { Node maybeName = val.getFirstChild(); if (ref.node.matchesQualifiedName(maybeName)) { return true; } } return false; }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (!n.isAssign() || n.getFirstChild() == className) { return; } if (className.matchesQualifiedName(n.getFirstChild())) { compiler.report(JSError.make(n, CLASS_REASSIGNMENT)); } }
static boolean isAliasingGlobalThis(CodingConvention convention, Node n) { return n.isAssign() && n.getFirstChild().matchesQualifiedName(convention.getGlobalObject()) && n.getLastChild().isThis(); }
static boolean isNaN(Node n) { return (n.isName() && n.getString().equals("NaN")) || (n.getToken() == Token.DIV && n.getFirstChild().isNumber() && n.getFirstChild().getDouble() == 0 && n.getLastChild().isNumber() && n.getLastChild().getDouble() == 0) || n.matchesQualifiedName(NUMBER_NAN); }
@Override public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) { if (n.isCall() && n.getFirstChild().matchesQualifiedName("goog.scope")) { Node function = n.getSecondChild(); if (function.isFunction()) { googScopeBlock = NodeUtil.getFunctionBody(function); } } return parent == null || !parent.isScript() || !t.getInput().isExtern(); }