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)
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
import java.awt.GridBagConstraints
|
||||
import java.awt.GridBagLayout
|
||||
@@ -156,7 +157,7 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
|
||||
private fun isConventionalName(namedDeclaration: JetNamedDeclaration): Boolean {
|
||||
val name = namedDeclaration.getNameAsName()
|
||||
return name.getOperationSymbolsToSearch().isNotEmpty() || name == INVOKE_OPERATION_NAME
|
||||
return name.getOperationSymbolsToSearch().isNotEmpty() || name == OperatorConventions.INVOKE
|
||||
}
|
||||
|
||||
private fun hasNonTrivialUsages(declaration: JetNamedDeclaration): Boolean {
|
||||
|
||||
+2
-1
@@ -18,11 +18,12 @@ package org.jetbrains.kotlin.idea.intentions.attributeCallReplacements
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
public open class ReplaceInvokeIntention : AttributeCallReplacementIntention("replace.invoke.with.call") {
|
||||
|
||||
override fun isApplicableToCall(call: CallDescription): Boolean {
|
||||
return call.functionName == "invoke"
|
||||
return call.functionName == OperatorConventions.INVOKE.asString()
|
||||
}
|
||||
|
||||
override fun replaceCall(call: CallDescription, editor: Editor) {
|
||||
|
||||
+11
-6
@@ -16,15 +16,17 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||
import java.util.Collections
|
||||
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.FunctionInfo
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.ParameterInfo
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
object CreateInvokeFunctionActionFactory : JetIntentionActionsFactory() {
|
||||
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||
@@ -44,6 +46,9 @@ object CreateInvokeFunctionActionFactory : JetIntentionActionsFactory() {
|
||||
}
|
||||
|
||||
val returnType = TypeInfo(callExpr, Variance.OUT_VARIANCE)
|
||||
return CreateCallableFromUsageFixes(callExpr, FunctionInfo("invoke", receiverType, returnType, Collections.emptyList(), parameters))
|
||||
return CreateCallableFromUsageFixes(
|
||||
callExpr,
|
||||
FunctionInfo(OperatorConventions.INVOKE.asString(), receiverType, returnType, emptyList(), parameters)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user