/*
 * 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.js.generate.typeurl;

import com.google.protobuf.Descriptors.FileDescriptor;
import io.spine.code.js.Directory;
import io.spine.code.js.FileName;
import io.spine.code.proto.FileSet;
import io.spine.js.generate.FileSetEnhancement;

import static io.spine.code.js.LibraryFile.SPINE_OPTIONS;

/**
 * For each type in a {@link FileSet} generates a method to obtain the type URL.
 */
public class TypeUrlsInFiles extends FileSetEnhancement {

    public TypeUrlsInFiles(Directory generatedRoot, FileSet fileSet) {
        super(generatedRoot, fileSet);
    }

    @Override
    protected void processSources() {
        for (FileDescriptor file : fileSet().files()) {
            if (isSpineOptions(file)) {
                return;
            }
            TypeUrlsInFile inFile = new TypeUrlsInFile(file, generatedRoot());
            inFile.generateAndAppend();
        }
    }

    private static boolean isSpineOptions(FileDescriptor file) {
        FileName fileName = FileName.from(file);
        return SPINE_OPTIONS.fileName()
                            .equals(fileName);
    }
}

@@ -1139,42 +1139,8 @@
 ry;%0A
-import io.spine.code.js.FileName;%0A
 impo
@@ -1224,67 +1224,8 @@
 t;%0A%0A
-import static io.spine.code.js.LibraryFile.SPINE_OPTIONS;%0A%0A
 /**%0A
@@ -1597,86 +1597,8 @@
 ) %7B%0A
-            if (isSpineOptions(file)) %7B%0A                return;%0A            %7D%0A
     
@@ -1731,215 +1731,7 @@
    %7D
-%0A%0A    private static boolean isSpineOptions(FileDescriptor file) %7B%0A        FileName fileName = FileName.from(file);%0A        return SPINE_OPTIONS.fileName()%0A                            .equals(fileName);%0A    %7D
 %0A%7D%0A

Generate `typeUrl` method for definitions from `options.proto`