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

com.dbobjekts.util.ObjectNameValidator.kt Maven / Gradle / Ivy

There is a newer version: 0.6.0-RC2
Show newest version
package com.dbobjekts.util

import com.dbobjekts.api.exception.CodeGenerationException
import com.dbobjekts.codegen.metadata.ReservedKeywords
import javax.lang.model.SourceVersion

object ObjectNameValidator {

    fun validate(txt: String): Boolean =
        !SourceVersion.isKeyword(txt.lowercase())
                && !ReservedKeywords.isKeyword(txt.lowercase())
                && SourceVersion.isIdentifier(txt)

    fun validate(txt: String, errorMessage: String) {
        if (SourceVersion.isKeyword(txt) || ReservedKeywords.isKeyword(txt)) {
            throw CodeGenerationException(errorMessage + " It is a restricted Java/Kotlin keyword.")
        } else if (!SourceVersion.isIdentifier(txt)) {
            throw CodeGenerationException(errorMessage + " It is not a valid Java/Kotlin identifier.")
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy