All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ovirt.api.metamodel.tool.JavaGenerator Maven / Gradle / Ivy

/*
Copyright (c) 2015 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.ovirt.api.metamodel.tool;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.ovirt.api.metamodel.concepts.Concept;
import org.ovirt.api.metamodel.concepts.Model;

/**
 * This class contains methods useful for several different kinds of classes that generate Java source code.
 */
public abstract class JavaGenerator {
    // The buffer used to generate Java code:
    protected JavaClassBuffer javaBuffer;

    // The directory were the output will be generated:
    protected File outDir;

    // The directory were the resources file will be generated:
    protected File resourcesDir;

    /**
     * Set the directory were the output will be generated.
     */
    public void setOutDir(File newOutDir) {
        outDir = newOutDir;
    }

    /**
     * Set the directory were the resources files will be generated.
     */
    public void setResourcesDir(File newResourcesDir) {
        resourcesDir = newResourcesDir;
    }

    /**
     * Generate the code for the given model.
     */
    public abstract void generate(Model model);

    protected void generateDoc(Concept concept) {
        List lines = new ArrayList<>();
        String doc = concept.getDoc();
        if (doc != null) {
            Collections.addAll(lines, doc.split("\n"));
        }
        if (!lines.isEmpty()) {
            javaBuffer.addDocComment(lines);
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy