/*
 * Copyright 2018, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.tools.protojs.code;

import com.google.common.annotations.VisibleForTesting;

import java.util.List;

import static java.lang.String.join;
import static java.util.Collections.nCopies;

final class CodeLine {

    private static final String SPACE = " ";

    private final String content;
    private final int depth;

    CodeLine(String content, int depth) {
        this.content = content;
        this.depth = depth;
    }

    String printToString(int indent) {
        int spacesCount = depth * indent;
        List<String> indentSpaces = nCopies(spacesCount, SPACE);
        String codeIndent = join("", indentSpaces);
        String result = codeIndent + content;
        return result;
    }

    @VisibleForTesting
    int depth() {
        return depth;
    }
}

@@ -1048,65 +1048,8 @@
 e;%0A%0A
-import com.google.common.annotations.VisibleForTesting;%0A%0A
 impo
@@ -1155,250 +1155,1013 @@
 s;%0A%0A
-final class CodeLine %7B%0A%0A    private static final String SPACE = %22 %22;%0A%0A    private final String content;%0A    private final int depth;%0A%0A    CodeLine(String content, int depth) %7B%0A        this.content = content;%0A        this.depth = depth;%0A    %7D%0A
+/**%0A * The line of JS code located at some depth.%0A *%0A * %3Cp%3EThe depth is later used together with the indent to calculate the correct indentation of the%0A * line in the generated code.%0A *%0A * @author Dmytro Kuzmin%0A */%0Afinal class CodeLine %7B%0A%0A    private static final String SPACE = %22 %22;%0A%0A    private final String content;%0A    private final int depth;%0A%0A    /**%0A     * Creates a new %7B@code CodeLine%7D.%0A     *%0A     * @param content%0A     *         the JS code%0A     * @param depth%0A     *         the depth of the code, for example the code inside the %22if%22 block is one unit deeper%0A     *         than the %22if%22 statement itself%0A     */%0A    CodeLine(String content, int depth) %7B%0A        this.content = content;%0A        this.depth = depth;%0A    %7D%0A%0A    /**%0A     * Prints the %7B@code CodeLine%7D to the %7B@code String%7D with the specified indent.%0A     *%0A     * @param indent%0A     *         the indent of the file where this line will be written%0A     * @return the %7B@code CodeLine%7D content with the correct indentation%0A     */
 %0A   
@@ -2208,27 +2208,32 @@
     int 
-spacesCount
+indentationUnits
  = depth
@@ -2264,23 +2264,17 @@
 String%3E 
-indentS
+s
 paces = 
@@ -2285,19 +2285,24 @@
 ies(
-spacesCount
+indentationUnits
 , SP
@@ -2322,26 +2322,27 @@
  String 
-codeIndent
+indentation
  = join(
@@ -2349,15 +2349,9 @@
 %22%22, 
-indentS
+s
 pace
@@ -2382,18 +2382,19 @@
 t = 
-codeIndent
+indentation
  + c
@@ -2433,77 +2433,7 @@
    %7D
-%0A%0A    @VisibleForTesting%0A    int depth() %7B%0A        return depth;%0A    %7D
 %0A%7D%0A

Add doc to `CodeLine`