Skip to content

Commit

Permalink
fix getAbbreviation
Browse files Browse the repository at this point in the history
  • Loading branch information
Daoortor committed Jul 25, 2024
1 parent 24a48f7 commit 3e7e48f
Showing 1 changed file with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,14 @@ private fun KType.checkAbbreviation(abbreviation: String, errorMessagePrefix: St
Assertions.assertEquals(
this.getAbbreviation(),
abbreviation,
"The return type for $errorMessagePrefix must contain $abbreviation"
"The return type for $errorMessagePrefix must be $abbreviation"
)
}

private fun KType.getAbbreviation(): String {
val separator = " /*"
val strRepresentation = this.toString()
if (separator !in strRepresentation) {
if (arguments.isNotEmpty()) {
this.arguments.first().type?.toString()?.let {
return it
}
}
return if ("?" in strRepresentation) {
strRepresentation.dropLast(1)
} else {
strRepresentation
}
}
val abr = strRepresentation.split(separator).first()
return if ("<" in strRepresentation) {
"$abr>"
} else {
abr
}
val hintRegex = Regex(""" /\*[\w>.< =_]+ \*/""")
return this
.toString()
.replace(hintRegex, "")
.dropLastWhile { it == '?' }
}

0 comments on commit 3e7e48f

Please sign in to comment.