private static boolean isPrototypeMethodDefinition(Node node) {
    Node parent = node.getParent();
    Node grandparent = node.getGrandparent();
    if (parent == null || grandparent == null) {
      return false;
    }

    switch (node.getToken()) {
      case MEMBER_FUNCTION_DEF:
        if (NodeUtil.isEs6ConstructorMemberFunctionDef(node)) {
          return false; // Constructors aren't methods.
        }

        return true;

      case GETPROP:
        {
          // Case: `Foo.prototype.bar = function() { };
          if (parent.getFirstChild() != node) {
            return false;
          }

          if (!NodeUtil.isExprAssign(grandparent)) {
            return false;
          }

          Node functionNode = parent.getLastChild();
          if ((functionNode == null) || !functionNode.isFunction()) {
            return false;
          }

          Node nameNode = node.getFirstChild();
          return nameNode.isGetProp() && nameNode.getLastChild().getString().equals("prototype");
        }

      case STRING_KEY:
        {
          // Case: `Foo.prototype = {
          //          bar: function() { },
          //        }`
          checkArgument(parent.isObjectLit(), parent);

          if (!grandparent.isAssign()) {
            return false;
          }

          if (grandparent.getLastChild() != parent) {
            return false;
          }

          Node greatgrandparent = grandparent.getParent();
          if (greatgrandparent == null || !greatgrandparent.isExprResult()) {
            return false;
          }

          Node functionNode = node.getFirstChild();
          if ((functionNode == null) || !functionNode.isFunction()) {
            return false;
          }

          Node target = grandparent.getFirstChild();
          return target.isGetProp() && target.getLastChild().getString().equals("prototype");
        }

      default:
        return false;
    }
  }
private static boolean isPrototypeMethodDefinition ( Node node ) { Node parent = node . getParent ( ) ; Node grandparent = node . getGrandparent ( ) ; if ( parent == null || grandparent == null ) { return false ; } switch ( node . getToken ( ) ) { case MEMBER_FUNCTION_DEF : if ( NodeUtil . isEs6ConstructorMemberFunctionDef ( node ) ) { return false ; } return true ; case GETPROP : { if ( parent . getFirstChild ( ) != node ) { return false ; } if ( ! NodeUtil . isExprAssign ( grandparent ) ) { return false ; } Node functionNode = parent . getLastChild ( ) ; if ( ( functionNode == null ) || ! functionNode . isFunction ( ) ) { return false ; } Node nameNode = node . getFirstChild ( ) ; return nameNode . isGetProp ( ) && nameNode . getLastChild ( ) . getString ( ) . equals ( "prototype" ) ; } case STRING_KEY : { checkArgument ( parent . isObjectLit ( ) , parent ) ; if ( ! grandparent . isAssign ( ) ) { return false ; } if ( grandparent . getLastChild ( ) != parent ) { return false ; } Node greatgrandparent = grandparent . getParent ( ) ; if ( greatgrandparent == null || ! greatgrandparent . isExprResult ( ) ) { return false ; } Node functionNode = node . getFirstChild ( ) ; if ( ( functionNode == null ) || ! functionNode . isFunction ( ) ) { return false ; } Node target = grandparent . getFirstChild ( ) ; return target . isGetProp ( ) && target . getLastChild ( ) . getString ( ) . equals ( "prototype" ) ; } default : return false ; } }
Determines if the current node is a function prototype definition.