Add constant "invoke" to OperatorConventions
This commit is contained in:
+7
-5
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpression>(javaClass(), "Replace overloaded operator with function call") {
|
||||
companion object {
|
||||
@@ -69,10 +70,10 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
|
||||
val resolvedCall = element.getResolvedCall(element.analyze())
|
||||
val descriptor = resolvedCall?.getResultingDescriptor()
|
||||
if (descriptor is FunctionDescriptor && descriptor.getName().asString() == "invoke") {
|
||||
val parent = element.getParent()
|
||||
if (parent is JetDotQualifiedExpression && element.getCalleeExpression()?.getText() == "invoke") return false
|
||||
return !(element.getValueArgumentList() == null && element.getFunctionLiteralArguments().isEmpty())
|
||||
if (descriptor is FunctionDescriptor && descriptor.getName() == OperatorConventions.INVOKE) {
|
||||
if (element.getParent() is JetDotQualifiedExpression &&
|
||||
element.getCalleeExpression()?.getText() == OperatorConventions.INVOKE.asString()) return false
|
||||
return element.getValueArgumentList() != null || element.getFunctionLiteralArguments().isNotEmpty()
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -186,7 +187,8 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
val argumentString = arguments?.getText()?.trim("(", ")")
|
||||
val funcLitArgs = element.getFunctionLiteralArguments()
|
||||
val calleeText = callee.getText()
|
||||
val transformation = if (argumentString == null) "$calleeText.invoke" else "$calleeText.invoke($argumentString)"
|
||||
val transformation = "$calleeText.${OperatorConventions.INVOKE.asString()}" +
|
||||
(if (argumentString == null) "" else "($argumentString)")
|
||||
val transformed = JetPsiFactory(element).createExpression(transformation)
|
||||
funcLitArgs.forEach { transformed.add(it) }
|
||||
return callee.getParent()!!.replace(transformed) as JetExpression
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.search.usagesSearch
|
||||
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.lexer.JetToken
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions.*
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.JetSingleValueToken
|
||||
import org.jetbrains.kotlin.lexer.JetToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DelegatedPropertyResolver
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions.*
|
||||
|
||||
public val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<JetToken> = ImmutableSet
|
||||
.builder<JetToken>()
|
||||
@@ -45,8 +45,6 @@ public val ALL_SEARCHABLE_OPERATION_PATTERNS: Set<String> =
|
||||
public val INDEXING_OPERATION_NAMES: ImmutableSet<Name> =
|
||||
ImmutableSet.of(Name.identifier("get"), Name.identifier("set"))
|
||||
|
||||
public val INVOKE_OPERATION_NAME: Name = Name.identifier("invoke")
|
||||
|
||||
public val ITERATOR_OPERATION_NAME: Name = Name.identifier("iterator")
|
||||
|
||||
public val IN_OPERATIONS_TO_SEARCH: ImmutableSet<JetToken> = ImmutableSet.of(JetTokens.IN_KEYWORD)
|
||||
|
||||
Reference in New Issue
Block a user