boolean (@Nullable ASTNode node) { if (node == null) return false; ArrayDeque<ASTNode> queue = new ArrayDeque<>(); queue.offer(node); while (!queue.isEmpty()) { TreeElement each = (TreeElement)queue.poll(); if (each instanceof CompositeElement && spacesOnly(each)) { continue; } if (each instanceof LeafElement && !spacesOnly(each)) { return false; } Collections.addAll(queue, each.getChildren(null)); } return true; }