Deprecate String.concat with error severity.

Fix concat j2k conversion.
Add expected deprecation errors for Java String constructors that must be converted to special Kotlin String methods.
This commit is contained in:
Ilya Gorbunov
2016-01-20 15:50:47 +03:00
parent 2257fa36ec
commit 31ec7bcbea
5 changed files with 10 additions and 4 deletions
@@ -316,6 +316,10 @@ enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String
}
},
STRING_CONCAT(JAVA_LANG_STRING, "concat", 1) {
override fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter)
= BinaryExpression(codeConverter.convertExpression(qualifier), codeConverter.convertExpression(arguments.single()), Operator(JavaTokenType.PLUS).assignNoPrototype())
},
STRING_COMPARE_TO_IGNORE_CASE(JAVA_LANG_STRING, "compareToIgnoreCase", 1) {
override fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter)
@@ -32,7 +32,6 @@ class A {
s.codePointCount(0, s.length());
s.offsetByCodePoints(0, 4);
s.compareTo("test 2");
s.concat(" another");
s.contains("seq");
s.contentEquals(new StringBuilder(s));
s.contentEquals(new StringBuffer(s));
@@ -79,6 +78,7 @@ class A {
int limit = 5;
useSplit(s.split("\\s+", limit));
s.trim();
s.concat(" another");
s.getBytes();
s.getBytes(Charset.forName("utf-8"));
@@ -1,3 +1,5 @@
// ERROR: Using 'String(ByteArray, String): String' is an error. Use String(bytes, Charset) instead.
// ERROR: Using 'String(ByteArray, Int, Int, String): String' is an error. Use String(bytes, offset, length, Charset) instead.
import java.nio.charset.Charset
import java.util.*
@@ -33,7 +35,6 @@ internal class A {
s.codePointCount(0, s.length)
s.offsetByCodePoints(0, 4)
s.compareTo("test 2")
s.concat(" another")
s.contains("seq")
s.contentEquals(StringBuilder(s))
s.contentEquals(StringBuffer(s))
@@ -81,6 +82,7 @@ internal class A {
val limit = 5
useSplit(s.split("\\s+".toRegex(), limit.coerceAtLeast(0)).toTypedArray())
s.trim { it <= ' ' }
s + " another"
s.toByteArray()
s.toByteArray(Charset.forName("utf-8"))
+1 -1
View File
@@ -105,7 +105,7 @@ private fun String.indentWidth(): Int = indexOfFirst { !it.isWhitespace() }.let
private fun getIndentFunction(indent: String) = when {
indent.isEmpty() -> { line: String -> line }
else -> { line: String -> indent.concat(line) }
else -> { line: String -> indent + line }
}
private inline fun List<String>.reindent(resultSizeEstimate: Int, indentAddFunction: (String) -> String, indentCutFunction: (String) -> String?): String {
@@ -277,7 +277,7 @@ public fun String.compareTo(other: String, ignoreCase: Boolean = false): Int {
/**
* Returns a new string obtained by concatenating this string and the specified string.
*/
// TODO: Deprecated in favor of operator plus, when it would be as efficient as concat
@Deprecated("Use this + other, eventually it will be optimized as concat.", ReplaceWith("this + other"), level = DeprecationLevel.ERROR)
public fun String.concat(other: String): String = (this as java.lang.String).concat(other)
/**