KT-9628 Intention&inspection to replace use of "set" operator function with []
#KT-9628 Fixed
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
<html>
|
|
||||||
<body>
|
|
||||||
This inspection reports any explicit calls of 'get' which can be replaced by indexing operator []
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
This inspection reports any explicit calls of 'get' or 'set' functions which can be replaced by indexing operator []
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<html>
|
|
||||||
<body>
|
|
||||||
This intention replaces <code>get</code> member calls with the array index operator (<code>[]</code>).
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
This intention replaces <code>get</code> or <code>set</code> function calls with the indexing operator (<code>[]</code>).
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -653,7 +653,7 @@
|
|||||||
</intentionAction>
|
</intentionAction>
|
||||||
|
|
||||||
<intentionAction>
|
<intentionAction>
|
||||||
<className>org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetIntention</className>
|
<className>org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetOrSetIntention</className>
|
||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
</intentionAction>
|
</intentionAction>
|
||||||
|
|
||||||
@@ -1096,8 +1096,8 @@
|
|||||||
level="INFO"
|
level="INFO"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetInspection"
|
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetOrSetInspection"
|
||||||
displayName="Explicit 'get'"
|
displayName="Explicit 'get' or 'set' call"
|
||||||
groupName="Kotlin"
|
groupName="Kotlin"
|
||||||
enabledByDefault="true"
|
enabledByDefault="true"
|
||||||
level="INFO"
|
level="INFO"
|
||||||
|
|||||||
@@ -104,9 +104,9 @@ val KtQualifiedExpression.callExpression: KtCallExpression?
|
|||||||
val KtQualifiedExpression.calleeName: String?
|
val KtQualifiedExpression.calleeName: String?
|
||||||
get() = (callExpression?.getCalleeExpression() as? KtNameReferenceExpression)?.getText()
|
get() = (callExpression?.getCalleeExpression() as? KtNameReferenceExpression)?.getText()
|
||||||
|
|
||||||
fun KtQualifiedExpression.toResolvedCall(): ResolvedCall<out CallableDescriptor>? {
|
fun KtQualifiedExpression.toResolvedCall(bodyResolveMode: BodyResolveMode): ResolvedCall<out CallableDescriptor>? {
|
||||||
val callExpression = callExpression ?: return null
|
val callExpression = callExpression ?: return null
|
||||||
return callExpression.getResolvedCall(callExpression.analyze()) ?: return null
|
return callExpression.getResolvedCall(callExpression.analyze(bodyResolveMode)) ?: return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtExpression.isExitStatement(): Boolean {
|
fun KtExpression.isExitStatement(): Boolean {
|
||||||
|
|||||||
+2
-1
@@ -26,13 +26,14 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
|
|||||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
|
|
||||||
public class ReplaceCallWithBinaryOperatorIntention : JetSelfTargetingRangeIntention<KtDotQualifiedExpression>(javaClass(), "Replace call with binary operator"), HighPriorityAction {
|
public class ReplaceCallWithBinaryOperatorIntention : JetSelfTargetingRangeIntention<KtDotQualifiedExpression>(javaClass(), "Replace call with binary operator"), HighPriorityAction {
|
||||||
override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? {
|
override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? {
|
||||||
val operation = operation(element.calleeName) ?: return null
|
val operation = operation(element.calleeName) ?: return null
|
||||||
|
|
||||||
val resolvedCall = element.toResolvedCall() ?: return null
|
val resolvedCall = element.toResolvedCall(BodyResolveMode.PARTIAL) ?: return null
|
||||||
if (!resolvedCall.isReallySuccess()) return null
|
if (!resolvedCall.isReallySuccess()) return null
|
||||||
if (resolvedCall.getCall().getTypeArgumentList() != null) return null
|
if (resolvedCall.getCall().getTypeArgumentList() != null) return null
|
||||||
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return null
|
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return null
|
||||||
|
|||||||
+2
-1
@@ -25,13 +25,14 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
|
|
||||||
public class ReplaceContainsIntention : JetSelfTargetingRangeIntention<KtDotQualifiedExpression>(javaClass(), "Replace 'contains' call with 'in' operator"), HighPriorityAction {
|
public class ReplaceContainsIntention : JetSelfTargetingRangeIntention<KtDotQualifiedExpression>(javaClass(), "Replace 'contains' call with 'in' operator"), HighPriorityAction {
|
||||||
override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? {
|
override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? {
|
||||||
if (element.calleeName != OperatorNameConventions.CONTAINS.asString()) return null
|
if (element.calleeName != OperatorNameConventions.CONTAINS.asString()) return null
|
||||||
|
|
||||||
val resolvedCall = element.toResolvedCall() ?: return null
|
val resolvedCall = element.toResolvedCall(BodyResolveMode.PARTIAL) ?: return null
|
||||||
if (!resolvedCall.isReallySuccess()) return null
|
if (!resolvedCall.isReallySuccess()) return null
|
||||||
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return null
|
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return null
|
||||||
if ((resolvedCall.getArgumentMapping(argument) as ArgumentMatch).valueParameter.getIndex() != 0) return null
|
if ((resolvedCall.getArgumentMapping(argument) as ArgumentMatch).valueParameter.getIndex() != 0) return null
|
||||||
|
|||||||
+41
-12
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.intention.HighPriorityAction
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.callExpression
|
import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||||
@@ -29,15 +30,19 @@ import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
|||||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.buildExpression
|
import org.jetbrains.kotlin.psi.buildExpression
|
||||||
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
|
|
||||||
public class ReplaceGetInspection : IntentionBasedInspection<KtDotQualifiedExpression>(
|
public class ReplaceGetOrSetInspection : IntentionBasedInspection<KtDotQualifiedExpression>(
|
||||||
ReplaceGetIntention(), ReplaceGetInspection.additionalChecker
|
ReplaceGetOrSetIntention(), ReplaceGetOrSetInspection.additionalChecker
|
||||||
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
val additionalChecker = { expression: KtDotQualifiedExpression ->
|
val additionalChecker = { expression: KtDotQualifiedExpression ->
|
||||||
(expression.toResolvedCall()!!.resultingDescriptor as FunctionDescriptor).isExplicitOperator()
|
(expression.toResolvedCall(BodyResolveMode.PARTIAL)!!.resultingDescriptor as FunctionDescriptor).isExplicitOperator()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,23 +54,35 @@ private fun FunctionDescriptor.isExplicitOperator(): Boolean {
|
|||||||
overriddenDescriptors.any { it.isExplicitOperator() }
|
overriddenDescriptors.any { it.isExplicitOperator() }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReplaceGetIntention : JetSelfTargetingRangeIntention<KtDotQualifiedExpression>(javaClass(), "Replace 'get' call with index operator"), HighPriorityAction {
|
class ReplaceGetOrSetIntention : JetSelfTargetingRangeIntention<KtDotQualifiedExpression>(
|
||||||
|
KtDotQualifiedExpression::class.java,
|
||||||
|
"Replace 'get' or 'set' call with indexing operator"
|
||||||
|
), HighPriorityAction {
|
||||||
|
|
||||||
|
private val operatorNames = setOf(OperatorNameConventions.GET, OperatorNameConventions.SET)
|
||||||
|
|
||||||
override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? {
|
override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? {
|
||||||
val resolvedCall = element.toResolvedCall() ?: return null
|
val callExpression = element.callExpression ?: return null
|
||||||
|
val bindingContext = callExpression.analyze(BodyResolveMode.PARTIAL)
|
||||||
|
val resolvedCall = callExpression.getResolvedCall(bindingContext) ?: return null
|
||||||
if (!resolvedCall.isReallySuccess()) return null
|
if (!resolvedCall.isReallySuccess()) return null
|
||||||
|
|
||||||
val target = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return null
|
val target = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return null
|
||||||
if (target.name.asString() != "get" || !target.isOperator) return null
|
if (!target.isOperator || target.name !in operatorNames) return null
|
||||||
|
|
||||||
val call = element.callExpression ?: return null
|
if (callExpression.getTypeArgumentList() != null) return null
|
||||||
if (call.getTypeArgumentList() != null) return null
|
|
||||||
|
|
||||||
val arguments = call.getValueArguments()
|
val arguments = callExpression.getValueArguments()
|
||||||
if (arguments.isEmpty()) return null
|
if (arguments.isEmpty()) return null
|
||||||
if (arguments.any { it.isNamed() }) return null
|
if (arguments.any { it.isNamed() }) return null
|
||||||
|
|
||||||
if (!element.isReceiverExpressionWithValue()) return null
|
if (!element.isReceiverExpressionWithValue()) return null
|
||||||
|
|
||||||
return call.getCalleeExpression()!!.getTextRange()
|
if (target.name == OperatorNameConventions.SET && element.isUsedAsExpression(bindingContext)) return null
|
||||||
|
|
||||||
|
text = "Replace '${target.name.asString()}' call with indexing operator"
|
||||||
|
|
||||||
|
return callExpression.getCalleeExpression()!!.getTextRange()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun applyTo(element: KtDotQualifiedExpression, editor: Editor) {
|
override fun applyTo(element: KtDotQualifiedExpression, editor: Editor) {
|
||||||
@@ -73,13 +90,19 @@ public class ReplaceGetIntention : JetSelfTargetingRangeIntention<KtDotQualified
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun applyTo(element: KtDotQualifiedExpression) {
|
fun applyTo(element: KtDotQualifiedExpression) {
|
||||||
|
val isSet = element.toResolvedCall(BodyResolveMode.PARTIAL)!!.resultingDescriptor.name == OperatorNameConventions.SET
|
||||||
|
val allArguments = element.callExpression!!.valueArguments
|
||||||
|
if (isSet) {
|
||||||
|
assert(allArguments.size > 0)
|
||||||
|
}
|
||||||
|
|
||||||
val expression = KtPsiFactory(element).buildExpression {
|
val expression = KtPsiFactory(element).buildExpression {
|
||||||
appendExpression(element.getReceiverExpression())
|
appendExpression(element.getReceiverExpression())
|
||||||
|
|
||||||
appendFixedText("[")
|
appendFixedText("[")
|
||||||
|
|
||||||
val call = element.callExpression!!
|
val arguments = if (isSet) allArguments.dropLast(1) else allArguments
|
||||||
for ((index, argument) in call.getValueArguments().withIndex()) {
|
for ((index, argument) in arguments.withIndex()) {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
appendFixedText(",")
|
appendFixedText(",")
|
||||||
}
|
}
|
||||||
@@ -87,7 +110,13 @@ public class ReplaceGetIntention : JetSelfTargetingRangeIntention<KtDotQualified
|
|||||||
}
|
}
|
||||||
|
|
||||||
appendFixedText("]")
|
appendFixedText("]")
|
||||||
|
|
||||||
|
if (isSet) {
|
||||||
|
appendFixedText("=")
|
||||||
|
appendExpression(allArguments.last().getArgumentExpression())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element.replace(expression)
|
element.replace(expression)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,8 +26,8 @@ import org.jetbrains.kotlin.idea.inspections.RedundantSamConstructorInspection
|
|||||||
import org.jetbrains.kotlin.idea.intentions.*
|
import org.jetbrains.kotlin.idea.intentions.*
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetInspection
|
import org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetOrSetInspection
|
||||||
import org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetIntention
|
import org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetOrSetIntention
|
||||||
import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
||||||
import org.jetbrains.kotlin.idea.quickfix.RemoveRightPartOfBinaryExpressionFix
|
import org.jetbrains.kotlin.idea.quickfix.RemoveRightPartOfBinaryExpressionFix
|
||||||
import org.jetbrains.kotlin.idea.references.mainReference
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
@@ -60,7 +60,7 @@ object J2KPostProcessingRegistrar {
|
|||||||
registerIntentionBasedProcessing(IfThenToElvisIntention()) { applyTo(it) }
|
registerIntentionBasedProcessing(IfThenToElvisIntention()) { applyTo(it) }
|
||||||
registerIntentionBasedProcessing(IfNullToElvisIntention()) { applyTo(it) }
|
registerIntentionBasedProcessing(IfNullToElvisIntention()) { applyTo(it) }
|
||||||
registerIntentionBasedProcessing(SimplifyNegatedBinaryExpressionIntention()) { applyTo(it) }
|
registerIntentionBasedProcessing(SimplifyNegatedBinaryExpressionIntention()) { applyTo(it) }
|
||||||
registerIntentionBasedProcessing(ReplaceGetIntention(), additionalChecker = ReplaceGetInspection.additionalChecker) { applyTo(it) }
|
registerIntentionBasedProcessing(ReplaceGetOrSetIntention(), additionalChecker = ReplaceGetOrSetInspection.additionalChecker) { applyTo(it) }
|
||||||
registerIntentionBasedProcessing(AddOperatorModifierIntention()) { applyTo(it) }
|
registerIntentionBasedProcessing(AddOperatorModifierIntention()) { applyTo(it) }
|
||||||
|
|
||||||
registerDiagnosticBasedProcessing<KtBinaryExpressionWithTypeRHS>(Errors.USELESS_CAST) { element, diagnostic ->
|
registerDiagnosticBasedProcessing<KtBinaryExpressionWithTypeRHS>(Errors.USELESS_CAST) { element, diagnostic ->
|
||||||
|
|||||||
-64
@@ -1,64 +0,0 @@
|
|||||||
<problems>
|
|
||||||
<problem>
|
|
||||||
<file>singleArgument.kt</file>
|
|
||||||
<line>6</line>
|
|
||||||
<module>light_idea_test_case</module>
|
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/singleArgument.kt" />
|
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
|
||||||
<description>Replace 'get' call with index operator</description>
|
|
||||||
</problem>
|
|
||||||
|
|
||||||
<problem>
|
|
||||||
<file>multiArgument.kt</file>
|
|
||||||
<line>6</line>
|
|
||||||
<module>light_idea_test_case</module>
|
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/multiArgument.kt" />
|
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
|
||||||
<description>Replace 'get' call with index operator</description>
|
|
||||||
</problem>
|
|
||||||
|
|
||||||
<problem>
|
|
||||||
<file>functionalArgument.kt</file>
|
|
||||||
<line>6</line>
|
|
||||||
<module>light_idea_test_case</module>
|
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/functionalArgument.kt" />
|
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
|
||||||
<description>Replace 'get' call with index operator</description>
|
|
||||||
</problem>
|
|
||||||
|
|
||||||
<problem>
|
|
||||||
<file>extensionFunction.kt</file>
|
|
||||||
<line>7</line>
|
|
||||||
<module>light_idea_test_case</module>
|
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/extensionFunction.kt" />
|
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
|
||||||
<description>Replace 'get' call with index operator</description>
|
|
||||||
</problem>
|
|
||||||
|
|
||||||
<problem>
|
|
||||||
<file>argumentAndFunction.kt</file>
|
|
||||||
<line>6</line>
|
|
||||||
<module>light_idea_test_case</module>
|
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/argumentAndFunction.kt" />
|
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
|
||||||
<description>Replace 'get' call with index operator</description>
|
|
||||||
</problem>
|
|
||||||
|
|
||||||
<problem>
|
|
||||||
<file>acceptableVararg.kt</file>
|
|
||||||
<line>6</line>
|
|
||||||
<module>light_idea_test_case</module>
|
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/acceptableVararg.kt" />
|
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
|
||||||
<description>Replace 'get' call with index operator</description>
|
|
||||||
</problem>
|
|
||||||
|
|
||||||
<problem>
|
|
||||||
<file>qualifier.kt</file>
|
|
||||||
<line>8</line>
|
|
||||||
<module>light_idea_test_case</module>
|
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/qualifier.kt" />
|
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
|
||||||
<description>Replace 'get' call with index operator</description>
|
|
||||||
</problem>
|
|
||||||
</problems>
|
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetIntention
|
org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetOrSetIntention
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
<problems>
|
||||||
|
<problem>
|
||||||
|
<file>singleArgument.kt</file>
|
||||||
|
<line>8</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="singleArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES"/>
|
||||||
|
<description>Replace 'get' call with indexing operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>multiArgument.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="multiArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES"/>
|
||||||
|
<description>Replace 'get' call with indexing operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>functionalArgument.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="functionalArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES"/>
|
||||||
|
<description>Replace 'get' call with indexing operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>extensionFunction.kt</file>
|
||||||
|
<line>7</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="extensionFunction.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES"/>
|
||||||
|
<description>Replace 'get' call with indexing operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>argumentAndFunction.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="argumentAndFunction.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES"/>
|
||||||
|
<description>Replace 'get' call with indexing operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>acceptableVararg.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="acceptableVararg.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES"/>
|
||||||
|
<description>Replace 'get' call with indexing operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>qualifier.kt</file>
|
||||||
|
<line>8</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="qualifier.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES"/>
|
||||||
|
<description>Replace 'get' call with indexing operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>set.kt</file>
|
||||||
|
<line>8</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="set.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES"/>
|
||||||
|
<description>Replace 'set' call with indexing operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>set2.kt</file>
|
||||||
|
<line>9</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="set2.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES"/>
|
||||||
|
<description>Replace 'set' call with indexing operator</description>
|
||||||
|
</problem>
|
||||||
|
</problems>
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetInspection
|
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.conventionNameCalls.ReplaceGetOrSetInspection
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// INTENTION_TEXT: Replace 'set' call with indexing operator
|
||||||
|
|
||||||
|
class C {
|
||||||
|
operator fun set(s: String, value: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
C().<caret>set("x", 1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// INTENTION_TEXT: Replace 'set' call with indexing operator
|
||||||
|
|
||||||
|
class C {
|
||||||
|
operator fun set(s: String, value: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
C()["x"] = 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// INTENTION_TEXT: Replace 'set' call with indexing operator
|
||||||
|
|
||||||
|
class C {
|
||||||
|
operator fun set(s: String, value: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class D(val c: C) {
|
||||||
|
fun foo() {
|
||||||
|
this.c.<caret>set("x", 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// INTENTION_TEXT: Replace 'set' call with indexing operator
|
||||||
|
|
||||||
|
class C {
|
||||||
|
operator fun set(s: String, value: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class D(val c: C) {
|
||||||
|
fun foo() {
|
||||||
|
this.c["x"] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
|
||||||
|
class C {
|
||||||
|
operator fun set(s: String, value: Int): Boolean = true
|
||||||
|
}
|
||||||
|
|
||||||
|
class D(val c: C) {
|
||||||
|
fun foo(): Boolean {
|
||||||
|
return this.c.<caret>set("x", 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
// INTENTION_TEXT: Replace 'get' call with indexing operator
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
class Test{
|
class Test{
|
||||||
operator fun get(i: Int) : Int = 0
|
operator fun get(i: Int) : Int = 0
|
||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
// INTENTION_TEXT: Replace 'get' call with indexing operator
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
class Test{
|
class Test{
|
||||||
operator fun get(i: Int) : Int = 0
|
operator fun get(i: Int) : Int = 0
|
||||||
@@ -49,9 +49,9 @@ public class JetInspectionTestGenerated extends AbstractJetInspectionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("conventionNameCalls/replaceGet/inspectionData/inspections.test")
|
@TestMetadata("conventionNameCalls/replaceGetOrSet/inspectionData/inspections.test")
|
||||||
public void testConventionNameCalls_replaceGet_inspectionData_Inspections_test() throws Exception {
|
public void testConventionNameCalls_replaceGetOrSet_inspectionData_Inspections_test() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/inspectionData/inspections.test");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/inspectionData/inspections.test");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2772,119 +2772,137 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/intentions/conventionNameCalls/replaceGet")
|
@TestMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class ReplaceGet extends AbstractIntentionTest {
|
public static class ReplaceGetOrSet extends AbstractIntentionTest {
|
||||||
@TestMetadata("acceptableVararg.kt")
|
@TestMetadata("acceptableVararg.kt")
|
||||||
public void testAcceptableVararg() throws Exception {
|
public void testAcceptableVararg() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/acceptableVararg.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/acceptableVararg.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllFilesPresentInReplaceGet() throws Exception {
|
public void testAllFilesPresentInReplaceGetOrSet() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/conventionNameCalls/replaceGet"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/conventionNameCalls/replaceGetOrSet"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("argumentAndFunction.kt")
|
@TestMetadata("argumentAndFunction.kt")
|
||||||
public void testArgumentAndFunction() throws Exception {
|
public void testArgumentAndFunction() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/argumentAndFunction.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/argumentAndFunction.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("duplicateArguments.kt")
|
@TestMetadata("duplicateArguments.kt")
|
||||||
public void testDuplicateArguments() throws Exception {
|
public void testDuplicateArguments() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/duplicateArguments.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/duplicateArguments.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("extensionFunction.kt")
|
@TestMetadata("extensionFunction.kt")
|
||||||
public void testExtensionFunction() throws Exception {
|
public void testExtensionFunction() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/extensionFunction.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/extensionFunction.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("functionalArgument.kt")
|
@TestMetadata("functionalArgument.kt")
|
||||||
public void testFunctionalArgument() throws Exception {
|
public void testFunctionalArgument() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/functionalArgument.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/functionalArgument.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("invalidArgument.kt")
|
@TestMetadata("invalidArgument.kt")
|
||||||
public void testInvalidArgument() throws Exception {
|
public void testInvalidArgument() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/invalidArgument.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/invalidArgument.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("missingDefaultArgument.kt")
|
@TestMetadata("missingDefaultArgument.kt")
|
||||||
public void testMissingDefaultArgument() throws Exception {
|
public void testMissingDefaultArgument() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/missingDefaultArgument.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/missingDefaultArgument.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("multiArgument.kt")
|
@TestMetadata("multiArgument.kt")
|
||||||
public void testMultiArgument() throws Exception {
|
public void testMultiArgument() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/multiArgument.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/multiArgument.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("noArgument.kt")
|
@TestMetadata("noArgument.kt")
|
||||||
public void testNoArgument() throws Exception {
|
public void testNoArgument() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/noArgument.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/noArgument.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("notOperator.kt")
|
@TestMetadata("notOperator.kt")
|
||||||
public void testNotOperator() throws Exception {
|
public void testNotOperator() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/notOperator.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/notOperator.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("qualifier.kt")
|
@TestMetadata("qualifier.kt")
|
||||||
public void testQualifier() throws Exception {
|
public void testQualifier() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/qualifier.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/qualifier.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("sanityCheck.kt")
|
@TestMetadata("sanityCheck.kt")
|
||||||
public void testSanityCheck() throws Exception {
|
public void testSanityCheck() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/sanityCheck.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/sanityCheck.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("set.kt")
|
||||||
|
public void testSet() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/set.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("set2.kt")
|
||||||
|
public void testSet2() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/set2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("setValueUsed.kt")
|
||||||
|
public void testSetValueUsed() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/setValueUsed.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("singleArgument.kt")
|
@TestMetadata("singleArgument.kt")
|
||||||
public void testSingleArgument() throws Exception {
|
public void testSingleArgument() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/singleArgument.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/singleArgument.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("staticMethod.kt")
|
@TestMetadata("staticMethod.kt")
|
||||||
public void testStaticMethod() throws Exception {
|
public void testStaticMethod() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/staticMethod.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/staticMethod.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("super.kt")
|
@TestMetadata("super.kt")
|
||||||
public void testSuper() throws Exception {
|
public void testSuper() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/super.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/super.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("topLevelFun.kt")
|
@TestMetadata("topLevelFun.kt")
|
||||||
public void testTopLevelFun() throws Exception {
|
public void testTopLevelFun() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/topLevelFun.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/topLevelFun.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unacceptableVararg.kt")
|
@TestMetadata("unacceptableVararg.kt")
|
||||||
public void testUnacceptableVararg() throws Exception {
|
public void testUnacceptableVararg() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/unacceptableVararg.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/unacceptableVararg.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("unnamedAndNamed.kt")
|
@TestMetadata("unnamedAndNamed.kt")
|
||||||
public void testUnnamedAndNamed() throws Exception {
|
public void testUnnamedAndNamed() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGet/unnamedAndNamed.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/conventionNameCalls/replaceGetOrSet/unnamedAndNamed.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -3,13 +3,13 @@ import java.util.ArrayList
|
|||||||
internal class C {
|
internal class C {
|
||||||
fun foo1(list: MutableList<String>) {
|
fun foo1(list: MutableList<String>) {
|
||||||
for (i in list.indices) {
|
for (i in list.indices) {
|
||||||
list.set(i, "a")
|
list[i] = "a"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo2(list: ArrayList<String>) {
|
fun foo2(list: ArrayList<String>) {
|
||||||
for (i in list.indices) {
|
for (i in list.indices) {
|
||||||
list.set(i, "a")
|
list[i] = "a"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import java.util.ArrayList
|
|||||||
internal class C {
|
internal class C {
|
||||||
fun foo(list: MutableList<String>) {
|
fun foo(list: MutableList<String>) {
|
||||||
for (i in list.indices) {
|
for (i in list.indices) {
|
||||||
list.set(i, "a")
|
list[i] = "a"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user