<commit_before>package org.nkumar.ssql.translator;

import org.nkumar.ssql.dialect.Dialect;
import org.nkumar.ssql.model.SqlVisitable;
import org.nkumar.ssql.translator.SqlParser;
import org.nkumar.ssql.util.Util;

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

public final class SqlTranslator
{
    private SqlTranslator()
    {
    }

    @SuppressWarnings("unchecked")
    public static List<SqlVisitable> parseSql(String sql) throws Exception
    {
        return (List<SqlVisitable>) SqlParser.parseDdls(sql);
    }

    public static TranslatorSqlVisitor createVisitor(String dialectClassName) throws Exception
    {
        if (dialectClassName == null)
        {
            throw new IllegalArgumentException("Dialect class name was null");
        }
        dialectClassName = dialectClassName.trim();
        Class<?> clazz;
        try
        {
            clazz = Class.forName(dialectClassName);
        }
        catch (ClassNotFoundException e)
        {
            throw new RuntimeException("Could not load the Dialect class - " + dialectClassName, e);
        }
        Dialect dialect;
        try
        {
            dialect = (Dialect) clazz.newInstance();
        }
        catch (ClassCastException e)
        {
            throw new RuntimeException(dialectClassName + " not of type TranslatorSqlVisitor", e);
        }
        catch (Exception e)
        {
            throw new RuntimeException("Could not create an instance of - " + dialectClassName, e);
        }
        return new GenericTranslatorSqlVisitor(dialect);
    }

    public static void translateSqlFile(File srcFile, File destFile, String dialectClassName) throws Exception
    {
        List<SqlVisitable> list = parseSql(Util.readFileAsString(srcFile));
        TranslatorSqlVisitor visitor = createVisitor(dialectClassName);
        String generatedSql = translate(list, visitor);
        Util.writeStringToFile(destFile, generatedSql);
    }

    private static String translate(Iterable<SqlVisitable> list, TranslatorSqlVisitor visitor)
    {
        for (SqlVisitable sql : list)
        {
            sql.accept(visitor);
        }
        return visitor.getGeneratedSql();<commit_msg>fixed an exception message<commit_after>package org.nkumar.ssql.translator;

import org.nkumar.ssql.dialect.Dialect;
import org.nkumar.ssql.model.SqlVisitable;
import org.nkumar.ssql.translator.SqlParser;
import org.nkumar.ssql.util.Util;

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

public final class SqlTranslator
{
    private SqlTranslator()
    {
    }

    @SuppressWarnings("unchecked")
    public static List<SqlVisitable> parseSql(String sql) throws Exception
    {
        return (List<SqlVisitable>) SqlParser.parseDdls(sql);
    }

    public static TranslatorSqlVisitor createVisitor(String dialectClassName) throws Exception
    {
        if (dialectClassName == null)
        {
            throw new IllegalArgumentException("Dialect class name was null");
        }
        dialectClassName = dialectClassName.trim();
        Class<?> clazz;
        try
        {
            clazz = Class.forName(dialectClassName);
        }
        catch (ClassNotFoundException e)
        {
            throw new RuntimeException("Could not load the Dialect class - " + dialectClassName, e);
        }
        Dialect dialect;
        try
        {
            dialect = (Dialect) clazz.newInstance();
        }
        catch (ClassCastException e)
        {
            throw new RuntimeException(dialectClassName + " not of type Dialect", e);
        }
        catch (Exception e)
        {
            throw new RuntimeException("Could not create an instance of - " + dialectClassName, e);
        }
        return new GenericTranslatorSqlVisitor(dialect);
    }

    public static void translateSqlFile(File srcFile, File destFile, String dialectClassName) throws Exception
    {
        List<SqlVisitable> list = parseSql(Util.readFileAsString(srcFile));
        TranslatorSqlVisitor visitor = createVisitor(dialectClassName);
        String generatedSql = translate(list, visitor);
        Util.writeStringToFile(destFile, generatedSql);
    }

    private static String translate(Iterable<SqlVisitable> list, TranslatorSqlVisitor visitor)
    {
        for (SqlVisitable sql : list)
        {
            sql.accept(visitor);
        }
        return visitor.getGeneratedSql();
{'fraction_non_alphanumeric': 0.08405664687071722, 'fraction_numerical': 0.0, 'mean_word_length': 2.583469721767594, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6958759', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1176, 'n_words': 278}