in tools/linter/src/main/java/com/google/cloud/verticals/foundations/dataharmonization/tools/linter/rules/ConditionalRedundant.java [89:115]
public void apply(BaseTreeNode node) {
List<BaseTreeNode> children = node.asInternal().getChildren();
for (int i = 0; i < children.size(); i++) {
BaseTreeNode child = children.get(i);
if (child.isTerminal()
&& child.asTerminal().getValue().equals(ELSE)
&& children.size() - 1 >= i + 1) {
// Find the next ExprBlock node following the "else". There may or may not be spaces.
BaseTreeNode exprBlockNode;
if (children.size() - 1 >= i + 2
&& children.get(i + 1).isTerminal()
&& children.get(i + 1).asTerminal().getType().equals(TerminalNode.Type.SPACE)) {
exprBlockNode = children.get(i + 2);
} else {
exprBlockNode = children.get(i + 1);
}
// If the else block doesn't contain any statements, remove the block and the else
// statement.
if (exprBlockNode.getOriginalNodeType().equals(ExprBlockContext.class)
&& !containsStatements(exprBlockNode)) {
children.remove(exprBlockNode);
children.remove(i);
}
}
}
removeTrailingWhitespace(children);
}