public void apply()

in tools/linter/src/main/java/com/google/cloud/verticals/foundations/dataharmonization/tools/linter/rules/SpacingStatement.java [86:123]


  public void apply(BaseTreeNode node) {
    List<BaseTreeNode> children;
    if (node.isInternal()) {
      children = node.asInternal().getChildren();
    } else {
      children = new ArrayList<>();
    }
    // Go through the children of the statement node, and ensure there is a single space before and
    // after ':', and after 'var'.
    for (int i = 0; i < children.size(); i++) {
      // Check for colon
      if (isColon(children.get(i))) {
        int colonIndex = i;
        // Remove any existing spaces.
        if (children.size() - 1 > i && isNonLinterCreatedSpaceType(children.get(i + 1))) {
          children.remove(i + 1);
        }
        if (i > 0 && isNonLinterCreatedSpaceType(children.get(i - 1))) {
          children.remove(i - 1);
          colonIndex--;
        }
        // Insert a new space after the colon.
        BaseTreeNode spaceNode = new TerminalNode(SPACE, node, true, TerminalNode.Type.SPACE);
        children.add(colonIndex + 1, spaceNode);
      }
      // check for var keyword
      if (containsVar(children.get(i))) {
        List<BaseTreeNode> grandchildren = children.get(i).asInternal().getChildren();
        if (grandchildren.size() > 1 && isNonLinterCreatedSpaceType(grandchildren.get(1))) {
          // Remove any existing spaces.
          grandchildren.remove(1);
        }
        // Insert a new space.
        BaseTreeNode spaceNode = new TerminalNode(SPACE, node, true, TerminalNode.Type.SPACE);
        grandchildren.add(1, spaceNode);
      }
    }
  }