private Collection indentation()

in scripts/src/main/java/com/gu/typesafe/config/impl/ConfigNodeObject.java [121:164]


    private Collection<AbstractConfigNode> indentation() {
        boolean seenNewLine = false;
        ArrayList<AbstractConfigNode> indentation = new ArrayList<AbstractConfigNode>();
        if (children.isEmpty()) {
            return indentation;
        }
        for (int i = 0; i < children.size(); i++) {
            if (!seenNewLine) {
                if (children.get(i) instanceof com.gu.typesafe.config.impl.ConfigNodeSingleToken &&
                        com.gu.typesafe.config.impl.Tokens.isNewline(((com.gu.typesafe.config.impl.ConfigNodeSingleToken) children.get(i)).token())) {
                    seenNewLine = true;
                    indentation.add(new com.gu.typesafe.config.impl.ConfigNodeSingleToken(com.gu.typesafe.config.impl.Tokens.newLine(null)));
                }
            } else {
                if (children.get(i) instanceof com.gu.typesafe.config.impl.ConfigNodeSingleToken &&
                        com.gu.typesafe.config.impl.Tokens.isIgnoredWhitespace(((com.gu.typesafe.config.impl.ConfigNodeSingleToken) children.get(i)).token()) &&
                        i + 1 < children.size() && (children.get(i+1) instanceof ConfigNodeField ||
                        children.get(i+1) instanceof ConfigNodeInclude)) {
                    // Return the indentation of the first setting on its own line
                    indentation.add(children.get(i));
                    return indentation;
                }
            }
        }
        if (indentation.isEmpty()) {
            indentation.add(new com.gu.typesafe.config.impl.ConfigNodeSingleToken(com.gu.typesafe.config.impl.Tokens.newIgnoredWhitespace(null, " ")));
        } else {
            // Calculate the indentation of the ending curly-brace to get the indentation of the root object
            AbstractConfigNode last = children.get(children.size() - 1);
            if (last instanceof com.gu.typesafe.config.impl.ConfigNodeSingleToken && ((com.gu.typesafe.config.impl.ConfigNodeSingleToken) last).token() == com.gu.typesafe.config.impl.Tokens.CLOSE_CURLY) {
                AbstractConfigNode beforeLast = children.get(children.size() - 2);
                String indent = "";
                if (beforeLast instanceof com.gu.typesafe.config.impl.ConfigNodeSingleToken &&
                        com.gu.typesafe.config.impl.Tokens.isIgnoredWhitespace(((com.gu.typesafe.config.impl.ConfigNodeSingleToken) beforeLast).token()))
                    indent = ((com.gu.typesafe.config.impl.ConfigNodeSingleToken) beforeLast).token().tokenText();
                indent += "  ";
                indentation.add(new com.gu.typesafe.config.impl.ConfigNodeSingleToken(com.gu.typesafe.config.impl.Tokens.newIgnoredWhitespace(null, indent)));
                return indentation;
            }
        }

        // The object has no curly braces and is at the root level, so don't indent
        return indentation;
    }