StdLib deprecations cleanup: string operations.

This commit is contained in:
Ilya Gorbunov
2015-06-25 22:28:29 +03:00
parent 86f4a1b6e4
commit 35166f44ae
7 changed files with 20 additions and 19 deletions
@@ -85,10 +85,10 @@ class JdbcTest {
test fun formatCursor() {
dataSource.query("select * from foo") {
println(it.getColumnNames().toList().makeString("\t"))
println(it.getColumnNames().toList().joinToString("\t"))
for (row in it) {
println(it.getValues().makeString("\t"))
println(it.getValues().joinToString("\t"))
}
}
}
+1 -1
View File
@@ -53,7 +53,7 @@ public var Element.classes: String
}
/** Returns true if the element has the given CSS class style in its 'class' attribute */
public fun Element.hasClass(cssClass: String): Boolean = classes.matches("""(^|.*\s+)$cssClass($|\s+.*)""")
public fun Element.hasClass(cssClass: String): Boolean = classes.matches("""(^|.*\s+)$cssClass($|\s+.*)""".toRegex())
/** Returns the children of the element as a list */
@@ -144,7 +144,7 @@ abstract class KClassOrPackage(model: KModel, descriptor: DeclarationDescriptor)
fun findFunction(expression: String): KFunction? {
val idx = expression.indexOf('(')
val name = if (idx > 0) expression.substring(0, idx) else expression
val postfix = if (idx > 0) expression.substring(idx).trimTrailing("()") else ""
val postfix = if (idx > 0) expression.substring(idx).removeSuffix("()") else ""
return functions.find{ it.name == name && it.parameterTypeText == postfix }
}
}
@@ -342,8 +342,8 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs
canonicalFile.substring(rootDir.length())
else
canonicalFile
val cleanRoot = root.trimTrailing("/")
val cleanPath = relativeFile.trimLeading("/")
val cleanRoot = root.removeSuffix("/")
val cleanPath = relativeFile.removePrefix("/")
return "$cleanRoot/$cleanPath$lineLinkText$sourceLine"
}
return null
@@ -488,14 +488,14 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs
var text = lines[i]
text = text.trim()
if (i == 0) {
text = text.trimLeading("/**").trimLeading("/*")
text = text.removePrefix("/**").removePrefix("/*")
} else {
buffer.append("\n")
}
if (i >= last) {
text = text.trimTrailing("*/")
text = text.removeSuffix("*/")
} else if (i > 0) {
text = text.trimLeading("* ")
text = text.removePrefix("* ")
if (text == "*") text = ""
}
text = processMacros(text, psiElement)
@@ -830,7 +830,7 @@ abstract class KAnnotated(val model: KModel, val declarationDescriptor: Declarat
val detailedText = detailedDescription(template)
val idx = detailedText.indexOf("</p>")
return if (idx > 0) {
detailedText.substring(0, idx).trimLeading("<p>")
detailedText.substring(0, idx).removePrefix("<p>")
} else {
detailedText
}
@@ -950,7 +950,7 @@ class KPackage(
/** Returns a relative path like ../.. for each path in the name */
val nameAsRelativePath: String
get() {
val answer = namePaths.map{ ".." }.makeString("/")
val answer = namePaths.map{ ".." }.joinToString("/")
return if (answer.length() == 0) "" else answer + "/"
}
@@ -958,7 +958,7 @@ class KPackage(
// lets see if we can find a custom summary
val text = model.config.packageSummaryText[name]
return if (text != null)
wikiConvert(text, template).trimLeading("<p>").trimTrailing("</p>")
wikiConvert(text, template).removePrefix("<p>").removeSuffix("</p>")
else
super<KClassOrPackage>.description(template)
}
@@ -1104,7 +1104,7 @@ class KFunction(val descriptor: CallableDescriptor, val owner: KClassOrPackage,
var exceptions: List<KClass> = listOf<KClass>(),
var annotations: List<KAnnotation> = listOf<KAnnotation>()): KAnnotated(owner.model, descriptor), Comparable<KFunction> {
val parameterTypeText: String = parameters.map{ it.aType.name }.makeString(", ")
val parameterTypeText: String = parameters.map{ it.aType.name }.joinToString(", ")
override fun compareTo(other: KFunction): Int {
var answer = name.compareTo(other.name)
@@ -1128,7 +1128,7 @@ class KFunction(val descriptor: CallableDescriptor, val owner: KClassOrPackage,
/** Returns a list of generic type parameter names kinds like "A, I" */
val typeParametersText: String
get() = typeParameters.map{ it.name }.makeString(", ")
get() = typeParameters.map{ it.name }.joinToString(", ")
}
class KProperty(val owner: KClassOrPackage, val descriptor: PropertyDescriptor, val name: String,
@@ -149,7 +149,7 @@ abstract class KDocTemplate() : TextTemplate() {
}
open fun typeArguments(arguments: List<KType>, prefix: String = "&lt;", postfix: String = "&gt;", empty: String = ""): String {
val text = arguments.map<KType, String>() { link(it) }.makeString(", ")
val text = arguments.map<KType, String>() { link(it) }.joinToString(", ")
return if (text.length() == 0) empty else "$prefix$text$postfix"
}
@@ -119,7 +119,7 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
println("""<PRE>""")
println("""<FONT SIZE="-1">""")
printAnnotations(function.annotations)
print("""</FONT>${function.modifiers.makeString(" ")} $funKeyword""")
print("""</FONT>${function.modifiers.joinToString(" ")} $funKeyword""")
printTypeParameters(function, " ")
printReceiverType(function, " ", ".", " ")
@@ -169,7 +169,7 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
.filterNotNull()
.toSet()
private fun File.isJavaFile() = extension.equalsIgnoreCase(JavaFileType.INSTANCE.getDefaultExtension())
private fun File.isJavaFile() = extension.equals(JavaFileType.INSTANCE.getDefaultExtension(), ignoreCase = true)
override fun afterCompileHook(args: K2JVMCompilerArguments) {
getLogger().debug("Copying resulting files to classes")
@@ -695,6 +695,7 @@ private fun compareVersionNumbers(v1: String?, v2: String?): Int {
}
val pattern = "[\\.\\_\\-]".toRegex()
val digitsPattern = "\\d+".toRegex()
val part1 = v1.split(pattern)
val part2 = v2.split(pattern)
@@ -704,7 +705,7 @@ private fun compareVersionNumbers(v1: String?, v2: String?): Int {
val p2 = part2[idx]
val cmp: Int
if (p1.matches("\\d+") && p2.matches("\\d+")) {
if (p1.matches(digitsPattern) && p2.matches(digitsPattern)) {
cmp = p1.toInt().compareTo(p2.toInt())
} else {
cmp = part1[idx].compareTo(part2[idx])
@@ -722,7 +723,7 @@ private fun compareVersionNumbers(v1: String?, v2: String?): Int {
while (idx < parts.size()) {
val p = parts[idx]
val cmp: Int
if (p.matches("\\d+")) {
if (p.matches(digitsPattern)) {
cmp = Integer(p).compareTo(0)
} else {
cmp = 1