joinSimpleNamesAndTruncate

fun ClassName.joinSimpleNamesAndTruncate(hashParams: List<Any>, separator: String = "_", suffix: String = "", innerClassLength: Int = 0): ClassName

Joins the simple names of a class with the given separator and suffix.

The end of the name will be the separator followed by a hash of the hashParams, so that generated class names are unique. If the resulting class name is too long to be a valid file name, it will be truncated by removing the last characters before the hash, but the hash be unchanged.

val someScope = ClassName("com.example", "SomeScope")
val boundType = ClassName("com.example", "BoundType")
val normalName = ClassName("com.example", "Outer", "Middle", "Inner")
val joinedName = normalName.joinSimpleNamesAndTruncate(
hashParams = listOf(someScope, boundType),
separator = "_",
suffix = "Factory"
)
println(joinedName) // com.example.Outer_Middle_InnerFactory_0a1b2c3d

See also

for a version that doesn't truncate the class name.

Throws

if the resulting class name is too long to be a valid file name even after truncating.