/** * Given a qualified name node, returns whether "prototype" is at the end. * For example: * a.b.c => false * a.b.c.prototype => true */ private static boolean endsWithPrototype(Node qualifiedName) { return qualifiedName.isGetProp() && qualifiedName.getLastChild().getString().equals("prototype"); }
private static boolean isDummyPrototypeMethodDeclaration(Node node, String prototype) { Node getPropNode; return node.isExprResult() && (getPropNode = node.getFirstChild()).isGetProp() && getPropNode.getQualifiedName().startsWith(prototype + "."); }
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; }
static int getLengthOfQname(Node qname) { int result = 1; while (qname.isGetProp() || qname.isGetElem()) { result++; qname = qname.getFirstChild(); } checkState(qname.isName()); return result; }
/** * Given a qualified name {@code node}, checks whether the suffix * of the name could possibly match a static polyfill. */ boolean checkSuffix(Node node) { return node.isGetProp() ? suffixes.contains(node.getLastChild().getString()) : node.isName() ? suffixes.contains(node.getString()) : false; }
private boolean isNameDotPrototype(Node n) { return n.isGetProp() && n.getFirstChild().isName() && n.getLastChild().getString().equals("prototype"); }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isName() && isDeclaration(n)) { checkDeclaration(t, n); } else if (n.isGetProp()) { checkGetProp(t, n); } }
private static Node getPrototypeClassName(Node qName) { Node cur = qName; while (cur.isGetProp()) { if (cur.getLastChild().getString().equals("prototype")) { return cur.getFirstChild(); } else { cur = cur.getFirstChild(); } } return null; }
@Override public boolean matches(Node n) { return n.isGetProp() && n.getLastChild().getString() == prop && owner.matches(n.getFirstChild()); } }
private static String getLastPartOfQualifiedName(Node n) { if (n.isName()) { return n.getString(); } else if (n.isGetProp()) { return n.getLastChild().getString(); } return null; }
private void checkPropertyAccessForGetProp(NodeTraversal t, Node getProp) { checkArgument(getProp.isGetProp(), getProp); Node objNode = getProp.getFirstChild(); JSType objType = getJSType(objNode); Node propNode = getProp.getSecondChild(); JSType propType = getJSType(getProp); checkAbstractPropertyAccess(t, getProp); checkPropertyAccess(objType, t, getProp, propType, propNode, objNode); }
private boolean isSuperGet(Node n) { return (n.isGetProp() || n.isGetElem()) && !isCalled(n) && n.getFirstChild().isSuper() && isInsideInstanceMember(n); }
@Override public boolean isStaticProperty() { Node lhs = assignNode.getFirstChild(); if (lhs.isGetProp()) { // something.propName = someValue Node getPropLhs = lhs.getFirstChild(); JSType typeI = getPropLhs.getJSType(); return typeI != null && (typeI.isConstructor() || typeI.isInterface()); } else { return false; } }
/** * Whether the provided node acts as the target function in a call expression including * .call expressions. For example, returns true for 'x' in 'x.call()'. */ static boolean isCallTarget(Node n) { Node parent = n.getParent(); return ((parent.getFirstChild() == n) && parent.isCall()) || (parent.isGetProp() && parent.getParent().isCall() && parent.getLastChild().getString().equals("call")); }
@Override protected ConformanceResult checkConformance(NodeTraversal t, Node n) { if (n.isGetProp() && isKnownThis(n.getFirstChild()) // not a cascading unknown && isUnknown(n) && !isTypeVariable(n) && isUsed(n) // skip most assignments, etc && !isTypeImmediatelyTightened(n)) { return ConformanceResult.VIOLATION; } return ConformanceResult.CONFORMANCE; }
private void visitQualifiedName(NodeTraversal t, Node n, Node parent) { checkState(n.isName() || n.isGetProp() || n.isStringKey(), n); String qualifiedName = n.isStringKey() ? n.getString() : n.getQualifiedName(); addWeakUsagesOfAllPrefixes(qualifiedName); if (mode != Mode.SINGLE_FILE) { // TODO(b/71638622): Fix violations and remove this check. return; } if (!n.isStringKey() && !NodeUtil.isLhsOfAssign(n) && !parent.isExprResult()) { addUsageOfOutermostClassName(n, t); } }
static boolean isTypedefDecl(Node n) { if (n.isVar() || (n.isName() && n.getParent().isVar()) || (n.isGetProp() && n.getParent().isExprResult())) { JSDocInfo jsdoc = getBestJSDocInfo(n); return jsdoc != null && jsdoc.hasTypedefType(); } return false; }
static boolean isEnumDecl(Node n) { if (NodeUtil.isNameDeclaration(n) || (n.isName() && NodeUtil.isNameDeclaration(n.getParent())) || (n.isGetProp() && n.getParent().isAssign() && n.getGrandparent().isExprResult()) || (n.isAssign() && n.getParent().isExprResult())) { JSDocInfo jsdoc = getBestJSDocInfo(n); return jsdoc != null && jsdoc.hasEnumParameterType(); } return false; }