Suggest to replace 'substring' calls by take/drop/dropLast calls when possible
#KT-10196 Fixed
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
s.<spot>drop(5)</spot>
|
||||
+1
@@ -0,0 +1 @@
|
||||
s.<spot>substring(5)</spot>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention replaces 'substring' call with 'drop' call.
|
||||
</body>
|
||||
</html>
|
||||
+1
@@ -0,0 +1 @@
|
||||
s.<spot>dropLast(5)</spot>
|
||||
+1
@@ -0,0 +1 @@
|
||||
s.<spot>substring(0, s.length - 5)</spot>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention replaces 'substring' call with 'dropLast' call.
|
||||
</body>
|
||||
</html>
|
||||
+1
@@ -0,0 +1 @@
|
||||
s.<spot>substringAfter('x')</spot>
|
||||
+1
@@ -0,0 +1 @@
|
||||
s.<spot>substring(s.indexOf('x'))</spot>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention replaces 'substring' and 'indexOf' calls with 'substringAfter' call.
|
||||
</body>
|
||||
</html>
|
||||
+1
@@ -0,0 +1 @@
|
||||
s.<spot>substringBefore('x')</spot>
|
||||
+1
@@ -0,0 +1 @@
|
||||
s.<spot>substring(0, s.indexOf('x'))</spot>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention replaces 'substring' and 'indexOf' calls with 'substringBefore' call.
|
||||
</body>
|
||||
</html>
|
||||
+1
@@ -0,0 +1 @@
|
||||
s.<spot>take(10)</spot>
|
||||
+1
@@ -0,0 +1 @@
|
||||
s.<spot>substring(0, 10)</spot>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention replaces 'substring' call with 'take' call.
|
||||
</body>
|
||||
</html>
|
||||
@@ -880,6 +880,31 @@
|
||||
<category>Kotlin</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithDropIntention</className>
|
||||
<category>Kotlin</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithDropLastIntention</className>
|
||||
<category>Kotlin</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithSubstringAfterIntention</className>
|
||||
<category>Kotlin</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithSubstringBeforeIntention</className>
|
||||
<category>Kotlin</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithTakeIntention</className>
|
||||
<category>Kotlin</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.intentions.RemoveBracesIntention</className>
|
||||
<category>Kotlin</category>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.codeInsight.intention.HighPriorityAction
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable
|
||||
import org.jetbrains.kotlin.psi.KtConstantExpression
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
abstract class ReplaceSubstringIntention(text: String) : SelfTargetingRangeIntention<KtDotQualifiedExpression>(KtDotQualifiedExpression::class.java, text), HighPriorityAction {
|
||||
protected abstract fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange?
|
||||
|
||||
override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? {
|
||||
if (!element.receiverExpression.isStableVariable()) return null
|
||||
val resolvedCall = element.toResolvedCall(BodyResolveMode.PARTIAL) ?: return null
|
||||
if (resolvedCall.resultingDescriptor.fqNameUnsafe.asString() != "kotlin.text.substring") return null
|
||||
return applicabilityRangeInner(element)
|
||||
}
|
||||
|
||||
protected fun KtDotQualifiedExpression.isFirstArgumentZero(): Boolean {
|
||||
val resolvedCall = toResolvedCall(BodyResolveMode.PARTIAL) ?: return false
|
||||
val expression = resolvedCall.call.valueArguments[0].getArgumentExpression() as? KtConstantExpression ?: return false
|
||||
|
||||
val bindingContext = expression.analyze()
|
||||
val constant = ConstantExpressionEvaluator.getConstant(expression, bindingContext) ?: return false
|
||||
val constantType = bindingContext.getType(expression) ?: return false
|
||||
return constant.getValue(constantType) == 0
|
||||
}
|
||||
|
||||
protected fun getTextRange(element: KtDotQualifiedExpression): TextRange? {
|
||||
return element.callExpression!!.textRange
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||
|
||||
class ReplaceSubstringWithDropIntention : ReplaceSubstringIntention("Replace 'substring' call with 'drop' call") {
|
||||
override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? {
|
||||
val arguments = element.callExpression?.valueArguments ?: return null
|
||||
if (arguments.count() != 1) return null
|
||||
return getTextRange(element)
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) {
|
||||
val receiver = element.receiverExpression
|
||||
val argument = element.callExpression!!.valueArguments[0].getArgumentExpression()!!
|
||||
|
||||
val psiFactory = KtPsiFactory(element)
|
||||
element.replace(psiFactory.createExpressionByPattern("$0.drop($1)", receiver, argument))
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
class ReplaceSubstringWithDropLastIntention : ReplaceSubstringIntention("Replace 'substring' call with 'dropLast' call") {
|
||||
override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? {
|
||||
val arguments = element.callExpression?.valueArguments ?: return null
|
||||
if (arguments.count() != 2 || !element.isFirstArgumentZero()) return null
|
||||
|
||||
val secondArgumentExpression = arguments[1].getArgumentExpression()
|
||||
|
||||
if (secondArgumentExpression !is KtBinaryExpression) return null
|
||||
if (secondArgumentExpression.operationReference.getReferencedNameElementType() != KtTokens.MINUS) return null
|
||||
if (isLengthAccess(secondArgumentExpression.left, element.receiverExpression)) {
|
||||
return getTextRange(element)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) {
|
||||
val receiver = element.receiverExpression
|
||||
val argument = element.callExpression!!.valueArguments[1].getArgumentExpression()!!
|
||||
val rightExpression = (argument as KtBinaryExpression).right!!
|
||||
|
||||
val psiFactory = KtPsiFactory(element)
|
||||
element.replace(psiFactory.createExpressionByPattern("$0.dropLast($1)", receiver, rightExpression))
|
||||
}
|
||||
|
||||
private fun isLengthAccess(expression: KtExpression?, expectedReceiver: KtExpression): Boolean {
|
||||
return expression is KtDotQualifiedExpression
|
||||
&& expression.selectorExpression.let { it is KtNameReferenceExpression && it.getReferencedName() == "length" }
|
||||
&& expression.receiverExpression.evaluatesTo(expectedReceiver)
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
class ReplaceSubstringWithSubstringAfterIntention : ReplaceSubstringIntention("Replace 'substring' call with 'substringAfter' call") {
|
||||
override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? {
|
||||
val arguments = element.callExpression?.valueArguments ?: return null
|
||||
|
||||
if (arguments.count() == 1 && isIndexOfCall(arguments[0].getArgumentExpression(), element.receiverExpression)) {
|
||||
return getTextRange(element)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) {
|
||||
element.replaceWith(
|
||||
"$0.substringAfter($1)",
|
||||
(element.getArgumentExpression(0) as KtDotQualifiedExpression).getArgumentExpression(0))
|
||||
}
|
||||
}
|
||||
|
||||
class ReplaceSubstringWithSubstringBeforeIntention : ReplaceSubstringIntention("Replace 'substring' call with 'substringBefore' call") {
|
||||
override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? {
|
||||
val arguments = element.callExpression?.valueArguments ?: return null
|
||||
|
||||
if (arguments.count() == 2
|
||||
&& element.isFirstArgumentZero()
|
||||
&& isIndexOfCall(arguments[1].getArgumentExpression(), element.receiverExpression)) {
|
||||
return getTextRange(element)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) {
|
||||
element.replaceWith(
|
||||
"$0.substringBefore($1)",
|
||||
(element.getArgumentExpression(1) as KtDotQualifiedExpression).getArgumentExpression(0))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun KtDotQualifiedExpression.replaceWith(pattern: String, argument: KtExpression) {
|
||||
val psiFactory = KtPsiFactory(this)
|
||||
replace(psiFactory.createExpressionByPattern(pattern, receiverExpression, argument))
|
||||
}
|
||||
|
||||
private fun KtDotQualifiedExpression.getArgumentExpression(index: Int): KtExpression {
|
||||
return callExpression!!.valueArguments[index].getArgumentExpression()!!
|
||||
}
|
||||
|
||||
private fun isIndexOfCall(expression: KtExpression?, expectedReceiver: KtExpression): Boolean {
|
||||
if (expression !is KtDotQualifiedExpression) return false
|
||||
val resolvedCall = expression.toResolvedCall(BodyResolveMode.PARTIAL) ?: return false
|
||||
if (resolvedCall.resultingDescriptor.fqNameUnsafe.asString() != "kotlin.text.indexOf") return false
|
||||
if (!expression.receiverExpression.evaluatesTo(expectedReceiver)) return false
|
||||
return expression.callExpression!!.valueArguments.count() == 1
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||
|
||||
class ReplaceSubstringWithTakeIntention : ReplaceSubstringIntention("Replace 'substring' call with 'take' call") {
|
||||
override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? {
|
||||
val arguments = element.callExpression?.valueArguments ?: return null
|
||||
if (arguments.count() == 2 && element.isFirstArgumentZero()) {
|
||||
return getTextRange(element)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtDotQualifiedExpression, editor: Editor?) {
|
||||
val receiver = element.receiverExpression
|
||||
val argument = element.callExpression!!.valueArguments[1].getArgumentExpression()!!
|
||||
|
||||
val psiFactory = KtPsiFactory(element)
|
||||
element.replace(psiFactory.createExpressionByPattern("$0.take($1)", receiver, argument))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithDropIntention
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(4)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.drop(4)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(4);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.drop(4);
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(0, 10)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithDropLastIntention
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(val x: String)
|
||||
|
||||
fun foo(a: A) {
|
||||
a.x.substring<caret>(0, a.x.length - 5)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(val x: String)
|
||||
|
||||
fun foo(a: A) {
|
||||
a.x.dropLast(5)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(3, s.length - 5)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(0, s.length - 5)
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.dropLast(5)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(0, s.length - 5);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.dropLast(5);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithSubstringAfterIntention
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(val x: String)
|
||||
|
||||
fun foo(a: A) {
|
||||
a.x.substring<caret>(a.x.indexOf('x'))
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(val x: String)
|
||||
|
||||
fun foo(a: A) {
|
||||
a.x.substringAfter('x')
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(s.indexOf('x'))
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substringAfter('x')
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(s.indexOf('x'));
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substringAfter('x');
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithSubstringBeforeIntention
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(val x: String)
|
||||
|
||||
fun foo(a: A) {
|
||||
a.x.substring<caret>(0, a.x.indexOf('x'))
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(val x: String)
|
||||
|
||||
fun foo(a: A) {
|
||||
a.x.substringBefore('x')
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(1, s.indexOf('x'))
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(0, s.indexOf('x'))
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substringBefore('x')
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(0, s.indexOf('x'));
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substringBefore('x');
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ReplaceSubstringWithTakeIntention
|
||||
@@ -0,0 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
const val x = 0
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(x, 10)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(1 - 1, 10)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(1, 10)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(0, 10)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.take(10)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.substring<caret>(0, 10);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(s: String) {
|
||||
s.take(10);
|
||||
}
|
||||
@@ -7573,6 +7573,165 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/replaceSubstringWithDrop")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ReplaceSubstringWithDrop extends AbstractIntentionTest {
|
||||
public void testAllFilesPresentInReplaceSubstringWithDrop() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithDrop"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("replaceWithDrop.kt")
|
||||
public void testReplaceWithDrop() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithDrop/replaceWithDrop.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("semicolon.kt")
|
||||
public void testSemicolon() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithDrop/semicolon.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("substringWithTwoArguments.kt")
|
||||
public void testSubstringWithTwoArguments() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithDrop/substringWithTwoArguments.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/replaceSubstringWithDropLast")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ReplaceSubstringWithDropLast extends AbstractIntentionTest {
|
||||
public void testAllFilesPresentInReplaceSubstringWithDropLast() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithDropLast"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("immutableProperty.kt")
|
||||
public void testImmutableProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithDropLast/immutableProperty.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonZeroFirstArgument.kt")
|
||||
public void testNonZeroFirstArgument() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithDropLast/nonZeroFirstArgument.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("replaceWithDropLast.kt")
|
||||
public void testReplaceWithDropLast() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithDropLast/replaceWithDropLast.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("semicolon.kt")
|
||||
public void testSemicolon() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithDropLast/semicolon.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/replaceSubstringWithSubstringAfter")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ReplaceSubstringWithSubstringAfter extends AbstractIntentionTest {
|
||||
public void testAllFilesPresentInReplaceSubstringWithSubstringAfter() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithSubstringAfter"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("immutableProperty.kt")
|
||||
public void testImmutableProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithSubstringAfter/immutableProperty.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("replaceWithSubstringAfter.kt")
|
||||
public void testReplaceWithSubstringAfter() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithSubstringAfter/replaceWithSubstringAfter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("semicolon.kt")
|
||||
public void testSemicolon() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithSubstringAfter/semicolon.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/replaceSubstringWithSubstringBefore")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ReplaceSubstringWithSubstringBefore extends AbstractIntentionTest {
|
||||
public void testAllFilesPresentInReplaceSubstringWithSubstringBefore() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithSubstringBefore"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("immutableProperty.kt")
|
||||
public void testImmutableProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithSubstringBefore/immutableProperty.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonZeroFirstArgument.kt")
|
||||
public void testNonZeroFirstArgument() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithSubstringBefore/nonZeroFirstArgument.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("replaceWithSubstringBefore.kt")
|
||||
public void testReplaceWithSubstringBefore() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithSubstringBefore/replaceWithSubstringBefore.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("semicolon.kt")
|
||||
public void testSemicolon() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithSubstringBefore/semicolon.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/replaceSubstringWithTake")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ReplaceSubstringWithTake extends AbstractIntentionTest {
|
||||
public void testAllFilesPresentInReplaceSubstringWithTake() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSubstringWithTake"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("constantAsFirstArgument.kt")
|
||||
public void testConstantAsFirstArgument() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithTake/constantAsFirstArgument.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("expressionAsFirstArgument.kt")
|
||||
public void testExpressionAsFirstArgument() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithTake/expressionAsFirstArgument.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonZeroFirstArgument.kt")
|
||||
public void testNonZeroFirstArgument() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithTake/nonZeroFirstArgument.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("replaceWithTake.kt")
|
||||
public void testReplaceWithTake() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithTake/replaceWithTake.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("semicolon.kt")
|
||||
public void testSemicolon() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSubstringWithTake/semicolon.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/replaceWithOperatorAssignment")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user