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

org.dbtools.codegen.kotlin.KotlinSourceUtil.kt Maven / Gradle / Ivy

There is a newer version: 11.0.0
Show newest version
/*
 * KotlinSourceUtil.kt
 *
 * Created on Nov 7, 2015
 *
 * Copyright 2007 Jeff Campbell. All rights reserved. Unauthorized reproduction
 * is a violation of applicable law. This material contains certain
 * confidential or proprietary information and trade secrets of Jeff Campbell.
 */
package org.dbtools.codegen.kotlin

/**
 * @author Jeff
 */
@SuppressWarnings("PMD.UseStringBufferForStringAppends")
object KotlinSourceUtil {

    fun getTestBaseDir(filepath: String = ""): String {
        var testBaseDir = ""
        if (filepath.contains("src/main/kotlin")) {
            testBaseDir = replaceText(filepath, "src/main/kotlin", "src/test/kotlin")
        } else if (filepath.contains("src\\main\\kotlin")) {
            testBaseDir = replaceText(filepath, "src\\main\\kotlin", "src\\test\\kotlin")
        } else if (filepath.contains("src/kotlin")) {
            testBaseDir = replaceText(filepath, "src/kotlin", "src/test")
        } else if (filepath.contains("src\\kotlin")) {
            testBaseDir = replaceText(filepath, "src\\\\kotlin", "src\\kotlin")
        } else if (filepath.contains("src")) {
            testBaseDir = replaceText(filepath, "src", "test")
        }

        return testBaseDir
    }

    private fun replaceText(sourceText: String, search: String, replace: String): String {
        //String replacedText = Matcher.quoteReplacement(sourceText).replaceAll(search, replace);
        var replaceText = ""
        val pos = sourceText.indexOf(search)
        val len = search.length
        replaceText = sourceText.substring(0, pos)
        replaceText += replace
        replaceText += sourceText.substring(pos + len)

        return replaceText
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy