code: private boolean checkExceedsMaxGenders(MsgSelectNode selectNode, int depth) {
      for (int caseNum = 0; caseNum < selectNode.numChildren(); caseNum++) {
        if (selectNode.getChild(caseNum).numChildren() > 0) {
          StandaloneNode caseNodeChild = selectNode.getChild(caseNum).getChild(0);
          // Plural cannot contain plurals or selects, so no need to recurse further.
          if (caseNodeChild instanceof MsgPluralNode && depth >= 3) {
            errorReporter.report(
                selectNode.getSourceLocation(), MORE_THAN_TWO_GENDER_EXPRS_WITH_PLURAL);
            return false;
          }
          if (caseNodeChild instanceof MsgSelectNode) {
            if (depth >= 3) {
              errorReporter.report(selectNode.getSourceLocation(), MORE_THAN_THREE_TOTAL_GENDERS);
              return false;
            } else {
              boolean validSubtree = checkExceedsMaxGenders((MsgSelectNode) caseNodeChild, depth + 1);
              if (!validSubtree) {
                return false;
              }
            }
          }
        }
      }
      return true;
    }
docs: Helper to verify that a rewritten soy msg tree does not exceed the restriction on number of
  total genders allowed (2 if includes plural, 3 otherwise).
  
  @param selectNode The select node to start searching from.
  @param depth The current depth of the select node.
  @return Whether the tree is valid.