Smaller ranges for intentions
This commit is contained in:
+11
-10
@@ -17,7 +17,8 @@
|
||||
package org.jetbrains.kotlin.idea.intentions.conventionNameCalls
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
||||
import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||
import org.jetbrains.kotlin.idea.intentions.functionName
|
||||
import org.jetbrains.kotlin.idea.intentions.toResolvedCall
|
||||
@@ -26,16 +27,16 @@ import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||
|
||||
public class ReplaceCallWithBinaryOperatorIntention : JetSelfTargetingOffsetIndependentIntention<JetDotQualifiedExpression>(javaClass(), "Replace call with binary operator") {
|
||||
override fun isApplicableTo(element: JetDotQualifiedExpression): Boolean {
|
||||
val operation = operation(element.functionName) ?: return false
|
||||
val resolvedCall = element.toResolvedCall() ?: return false
|
||||
if (!resolvedCall.getStatus().isSuccess()) return false
|
||||
if (resolvedCall.getCall().getTypeArgumentList() != null) return false
|
||||
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return false
|
||||
if ((resolvedCall.getArgumentMapping(argument) as ArgumentMatch).valueParameter.getIndex() != 0) return false
|
||||
public class ReplaceCallWithBinaryOperatorIntention : JetSelfTargetingRangeIntention<JetDotQualifiedExpression>(javaClass(), "Replace call with binary operator") {
|
||||
override fun applicabilityRange(element: JetDotQualifiedExpression): TextRange? {
|
||||
val operation = operation(element.functionName) ?: return null
|
||||
val resolvedCall = element.toResolvedCall() ?: return null
|
||||
if (!resolvedCall.getStatus().isSuccess()) return null
|
||||
if (resolvedCall.getCall().getTypeArgumentList() != null) return null
|
||||
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return null
|
||||
if ((resolvedCall.getArgumentMapping(argument) as ArgumentMatch).valueParameter.getIndex() != 0) return null
|
||||
setText("Replace with '$operation' operator")
|
||||
return true
|
||||
return element.callExpression!!.getCalleeExpression()!!.getTextRange()
|
||||
}
|
||||
|
||||
override fun applyTo(element: JetDotQualifiedExpression, editor: Editor) {
|
||||
|
||||
+9
-8
@@ -17,21 +17,22 @@
|
||||
package org.jetbrains.kotlin.idea.intentions.conventionNameCalls
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
||||
import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||
import org.jetbrains.kotlin.idea.intentions.functionName
|
||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||
|
||||
public class ReplaceCallWithUnaryOperatorIntention : JetSelfTargetingOffsetIndependentIntention<JetDotQualifiedExpression>(javaClass(), "Replace call with unary operator") {
|
||||
override fun isApplicableTo(element: JetDotQualifiedExpression): Boolean {
|
||||
val operation = operation(element.functionName) ?: return false
|
||||
val call = element.callExpression ?: return false
|
||||
if (call.getTypeArgumentList() != null) return false
|
||||
if (!call.getValueArguments().isEmpty()) return false
|
||||
public class ReplaceCallWithUnaryOperatorIntention : JetSelfTargetingRangeIntention<JetDotQualifiedExpression>(javaClass(), "Replace call with unary operator") {
|
||||
override fun applicabilityRange(element: JetDotQualifiedExpression): TextRange? {
|
||||
val operation = operation(element.functionName) ?: return null
|
||||
val call = element.callExpression ?: return null
|
||||
if (call.getTypeArgumentList() != null) return null
|
||||
if (!call.getValueArguments().isEmpty()) return null
|
||||
setText("Replace with '$operation' operator")
|
||||
return true
|
||||
return call.getCalleeExpression()!!.getTextRange()
|
||||
}
|
||||
|
||||
override fun applyTo(element: JetDotQualifiedExpression, editor: Editor) {
|
||||
|
||||
+12
-10
@@ -17,7 +17,8 @@
|
||||
package org.jetbrains.kotlin.idea.intentions.conventionNameCalls
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
||||
import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||
import org.jetbrains.kotlin.idea.intentions.functionName
|
||||
import org.jetbrains.kotlin.idea.intentions.toResolvedCall
|
||||
@@ -27,17 +28,18 @@ import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
public class ReplaceContainsIntention : JetSelfTargetingOffsetIndependentIntention<JetDotQualifiedExpression>(javaClass(), "Replace 'contains' call with 'in' operator") {
|
||||
override fun isApplicableTo(element: JetDotQualifiedExpression): Boolean {
|
||||
if (element.functionName != OperatorConventions.CONTAINS.asString()) return false
|
||||
val resolvedCall = element.toResolvedCall() ?: return false
|
||||
if (!resolvedCall.getStatus().isSuccess()) return false
|
||||
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return false
|
||||
if ((resolvedCall.getArgumentMapping(argument) as ArgumentMatch).valueParameter.getIndex() != 0) return false
|
||||
public class ReplaceContainsIntention : JetSelfTargetingRangeIntention<JetDotQualifiedExpression>(javaClass(), "Replace 'contains' call with 'in' operator") {
|
||||
override fun applicabilityRange(element: JetDotQualifiedExpression): TextRange? {
|
||||
if (element.functionName != OperatorConventions.CONTAINS.asString()) return null
|
||||
val resolvedCall = element.toResolvedCall() ?: return null
|
||||
if (!resolvedCall.getStatus().isSuccess()) return null
|
||||
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return null
|
||||
if ((resolvedCall.getArgumentMapping(argument) as ArgumentMatch).valueParameter.getIndex() != 0) return null
|
||||
|
||||
val target = resolvedCall.getResultingDescriptor()
|
||||
val returnType = target.getReturnType() ?: return false
|
||||
return target.builtIns.isBooleanOrSubtype(returnType)
|
||||
val returnType = target.getReturnType() ?: return null
|
||||
if (!target.builtIns.isBooleanOrSubtype(returnType)) return null
|
||||
return element.callExpression!!.getCalleeExpression()!!.getTextRange()
|
||||
}
|
||||
|
||||
override fun applyTo(element: JetDotQualifiedExpression, editor: Editor) {
|
||||
|
||||
+10
-10
@@ -17,23 +17,23 @@
|
||||
package org.jetbrains.kotlin.idea.intentions.conventionNameCalls
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
||||
import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||
import org.jetbrains.kotlin.idea.intentions.functionName
|
||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.buildExpression
|
||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||
|
||||
public class ReplaceGetIntention : JetSelfTargetingOffsetIndependentIntention<JetDotQualifiedExpression>(javaClass(), "Replace 'get' call with index operator") {
|
||||
override fun isApplicableTo(element: JetDotQualifiedExpression): Boolean {
|
||||
if (element.functionName != "get") return false
|
||||
val call = element.callExpression ?: return false
|
||||
if (call.getTypeArgumentList() != null) return false
|
||||
public class ReplaceGetIntention : JetSelfTargetingRangeIntention<JetDotQualifiedExpression>(javaClass(), "Replace 'get' call with index operator") {
|
||||
override fun applicabilityRange(element: JetDotQualifiedExpression): TextRange? {
|
||||
if (element.functionName != "get") return null
|
||||
val call = element.callExpression ?: return null
|
||||
if (call.getTypeArgumentList() != null) return null
|
||||
val arguments = call.getValueArguments()
|
||||
if (arguments.isEmpty()) return false
|
||||
if (arguments.any { it.isNamed() }) return false
|
||||
return true
|
||||
if (arguments.isEmpty()) return null
|
||||
if (arguments.any { it.isNamed() }) return null
|
||||
return call.getCalleeExpression()!!.getTextRange()
|
||||
}
|
||||
|
||||
override fun applyTo(element: JetDotQualifiedExpression, editor: Editor) {
|
||||
|
||||
+6
-5
@@ -17,16 +17,17 @@
|
||||
package org.jetbrains.kotlin.idea.intentions.conventionNameCalls
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
||||
import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||
import org.jetbrains.kotlin.idea.intentions.functionName
|
||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
public class ReplaceInvokeIntention : JetSelfTargetingOffsetIndependentIntention<JetDotQualifiedExpression>(javaClass(), "Replace 'invoke' with direct call") {
|
||||
override fun isApplicableTo(element: JetDotQualifiedExpression): Boolean {
|
||||
return element.functionName == OperatorConventions.INVOKE.asString()
|
||||
public class ReplaceInvokeIntention : JetSelfTargetingRangeIntention<JetDotQualifiedExpression>(javaClass(), "Replace 'invoke' with direct call") {
|
||||
override fun applicabilityRange(element: JetDotQualifiedExpression): TextRange? {
|
||||
if (element.functionName != OperatorConventions.INVOKE.asString()) return null
|
||||
return element.callExpression!!.getCalleeExpression()!!.getTextRange()
|
||||
}
|
||||
|
||||
override fun applyTo(element: JetDotQualifiedExpression, editor: Editor) {
|
||||
|
||||
Reference in New Issue
Block a user