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

org.hertsstack.codegen.CodeGenUtil Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
package org.hertsstack.codegen;

import org.hertsstack.core.modelx.HertsMessage;

import java.io.FileWriter;
import java.io.IOException;

class CodeGenUtil {
    public static final String GEN_COMMENT = "// Don't edit this file because this file is generated by herts codegen.";

    public static String capitalizeFirstLetter(String input) {
        if (input == null || input.isEmpty()) {
            return input;
        }

        char firstChar = input.charAt(0);
        if (Character.isLowerCase(firstChar)) {
            firstChar = Character.toUpperCase(firstChar);
            return firstChar + input.substring(1);
        } else {
            return input;
        }
    }

    private static boolean isInheritHertsMessage(String className) {
        if (className == null) {
            return false;
        }
        return className.contains(HertsMessage.class.getSimpleName());
    }

    public static boolean isCustomModelClass(Class classInfo) {
        if (classInfo.getSuperclass() != null && isInheritHertsMessage(classInfo.getSuperclass().getName())) {
            return true;
        }
        return false;
    }

    public static String getFullPath(String outDir, String filename) {
        if (outDir == null || outDir.isEmpty()) {
            return filename;
        } else {
            return outDir + "/" + filename;
        }
    }

    public static void writeFile(String fileName, String rawData) {
        try {
            FileWriter fw = new FileWriter(fileName, false);
            fw.write(rawData);
            fw.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy