Automatically put 'operator' modifier on appropriate Java methods
This commit is contained in:
+4
-4
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpression>(javaClass(), "Replace overloaded operator with function call") {
|
||||
companion object {
|
||||
@@ -72,9 +72,9 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
|
||||
val resolvedCall = element.getResolvedCall(element.analyze())
|
||||
val descriptor = resolvedCall?.getResultingDescriptor()
|
||||
if (descriptor is FunctionDescriptor && descriptor.getName() == OperatorConventions.INVOKE) {
|
||||
if (descriptor is FunctionDescriptor && descriptor.getName() == OperatorNameConventions.INVOKE) {
|
||||
if (element.getParent() is JetDotQualifiedExpression &&
|
||||
element.getCalleeExpression()?.getText() == OperatorConventions.INVOKE.asString()) return false
|
||||
element.getCalleeExpression()?.getText() == OperatorNameConventions.INVOKE.asString()) return false
|
||||
return element.getValueArgumentList() != null || element.getFunctionLiteralArguments().isNotEmpty()
|
||||
}
|
||||
return false
|
||||
@@ -189,7 +189,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
val argumentString = arguments?.getText()?.removeSurrounding("(", ")")
|
||||
val funcLitArgs = element.getFunctionLiteralArguments()
|
||||
val calleeText = callee.getText()
|
||||
val transformation = "$calleeText.${OperatorConventions.INVOKE.asString()}" +
|
||||
val transformation = "$calleeText.${OperatorNameConventions.INVOKE.asString()}" +
|
||||
(if (argumentString == null) "" else "($argumentString)")
|
||||
val transformed = JetPsiFactory(element).createExpression(transformation)
|
||||
funcLitArgs.forEach { transformed.add(it) }
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DelegatedPropertyResolver
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions.*
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
public val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<JetToken> = ImmutableSet
|
||||
.builder<JetToken>()
|
||||
@@ -37,7 +38,7 @@ public val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<JetToken> = ImmutableSet
|
||||
.add(JetTokens.BY_KEYWORD)
|
||||
.build()
|
||||
|
||||
public val INDEXING_OPERATION_NAMES = setOf(GET, SET)
|
||||
public val INDEXING_OPERATION_NAMES = setOf(OperatorNameConventions.GET, OperatorNameConventions.SET)
|
||||
|
||||
public val IN_OPERATIONS_TO_SEARCH = setOf(JetTokens.IN_KEYWORD)
|
||||
|
||||
@@ -45,11 +46,11 @@ public val COMPARISON_OPERATIONS_TO_SEARCH = setOf(JetTokens.LT, JetTokens.GT)
|
||||
|
||||
public fun Name.getOperationSymbolsToSearch(): Set<JetToken> {
|
||||
when (this) {
|
||||
COMPARE_TO -> return COMPARISON_OPERATIONS_TO_SEARCH
|
||||
EQUALS -> return EQUALS_OPERATIONS
|
||||
IDENTITY_EQUALS -> return IDENTITY_EQUALS_OPERATIONS
|
||||
CONTAINS -> return IN_OPERATIONS_TO_SEARCH
|
||||
ITERATOR -> return IN_OPERATIONS_TO_SEARCH
|
||||
OperatorNameConventions.COMPARE_TO -> return COMPARISON_OPERATIONS_TO_SEARCH
|
||||
OperatorNameConventions.EQUALS -> return EQUALS_OPERATIONS
|
||||
OperatorNameConventions.IDENTITY_EQUALS -> return IDENTITY_EQUALS_OPERATIONS
|
||||
OperatorNameConventions.CONTAINS -> return IN_OPERATIONS_TO_SEARCH
|
||||
OperatorNameConventions.ITERATOR -> return IN_OPERATIONS_TO_SEARCH
|
||||
in INDEXING_OPERATION_NAMES -> return setOf(JetTokens.LBRACKET, JetTokens.BY_KEYWORD)
|
||||
DelegatedPropertyResolver.PROPERTY_DELEGATED_FUNCTION_NAME -> return setOf(JetTokens.BY_KEYWORD)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.sun.jdi.Location
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.psi.JetBlockExpression
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
public class KotlinLambdaMethodFilter(
|
||||
lambda: JetFunctionLiteralExpression,
|
||||
@@ -71,7 +71,7 @@ public class KotlinLambdaMethodFilter(
|
||||
|
||||
companion object {
|
||||
public fun isLambdaName(name: String?): Boolean {
|
||||
return name == OperatorConventions.INVOKE.asString()
|
||||
return name == OperatorNameConventions.INVOKE.asString()
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.idea.JetIcons
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import javax.swing.Icon
|
||||
|
||||
public class KotlinLambdaSmartStepTarget(
|
||||
@@ -40,7 +40,7 @@ public class KotlinLambdaSmartStepTarget(
|
||||
|
||||
companion object {
|
||||
fun calcLabel(descriptor: DeclarationDescriptor, paramName: Name): String {
|
||||
return "${descriptor.getName().asString()}: ${paramName.asString()}.${OperatorConventions.INVOKE.asString()}()"
|
||||
return "${descriptor.getName().asString()}: ${paramName.asString()}.${OperatorNameConventions.INVOKE.asString()}()"
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import java.util.HashSet
|
||||
|
||||
public class KotlinRecursiveCallLineMarkerProvider() : LineMarkerProvider {
|
||||
@@ -155,7 +156,7 @@ private fun getCallNameFromPsi(element: JetElement): Name? {
|
||||
return Name.identifier("get")
|
||||
is JetThisExpression ->
|
||||
if (element.getParent() is JetCallExpression) {
|
||||
return OperatorConventions.INVOKE
|
||||
return OperatorNameConventions.INVOKE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.OverrideResolver
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
public class OperatorModifierInspection : AbstractKotlinInspection() {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
@@ -67,25 +68,25 @@ public class OperatorModifierInspection : AbstractKotlinInspection() {
|
||||
val arity = valueParameters.size()
|
||||
if (arity == 0 &&
|
||||
(name in OperatorConventions.UNARY_OPERATION_NAMES.values() ||
|
||||
name == OperatorConventions.ITERATOR ||
|
||||
name == OperatorNameConventions.ITERATOR ||
|
||||
isComponentLike(name) ||
|
||||
name == OperatorConventions.NEXT ||
|
||||
(name == OperatorConventions.HAS_NEXT && isBooleanReturnType()))) {
|
||||
name == OperatorNameConventions.NEXT ||
|
||||
(name == OperatorNameConventions.HAS_NEXT && isBooleanReturnType()))) {
|
||||
return true
|
||||
}
|
||||
if (arity == 1 && (name in OperatorConventions.BINARY_OPERATION_NAMES.values() ||
|
||||
name in OperatorConventions.ASSIGNMENT_OPERATIONS.values () ||
|
||||
(name == OperatorConventions.CONTAINS && isBooleanReturnType()) ||
|
||||
(name == OperatorConventions.COMPARE_TO && isIntReturnType()))) {
|
||||
(name == OperatorNameConventions.CONTAINS && isBooleanReturnType()) ||
|
||||
(name == OperatorNameConventions.COMPARE_TO && isIntReturnType()))) {
|
||||
return true
|
||||
}
|
||||
if (name == OperatorConventions.INVOKE) {
|
||||
if (name == OperatorNameConventions.INVOKE) {
|
||||
return true
|
||||
}
|
||||
if (arity >= 1 && name == OperatorConventions.GET) {
|
||||
if (arity >= 1 && name == OperatorNameConventions.GET) {
|
||||
return true
|
||||
}
|
||||
if (arity >= 2 && name == OperatorConventions.SET) {
|
||||
if (arity >= 2 && name == OperatorNameConventions.SET) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -58,6 +58,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
import java.awt.GridBagConstraints
|
||||
import java.awt.GridBagLayout
|
||||
@@ -213,7 +214,7 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
|
||||
private fun isConventionalName(namedDeclaration: JetNamedDeclaration): Boolean {
|
||||
val name = namedDeclaration.getNameAsName()
|
||||
return name!!.getOperationSymbolsToSearch().isNotEmpty() || name == OperatorConventions.INVOKE
|
||||
return name!!.getOperationSymbolsToSearch().isNotEmpty() || name == OperatorNameConventions.INVOKE
|
||||
}
|
||||
|
||||
private fun hasNonTrivialUsages(declaration: JetNamedDeclaration): Boolean {
|
||||
|
||||
+2
-2
@@ -25,11 +25,11 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
public class ReplaceContainsIntention : JetSelfTargetingRangeIntention<JetDotQualifiedExpression>(javaClass(), "Replace 'contains' call with 'in' operator"), HighPriorityAction {
|
||||
override fun applicabilityRange(element: JetDotQualifiedExpression): TextRange? {
|
||||
if (element.calleeName != OperatorConventions.CONTAINS.asString()) return null
|
||||
if (element.calleeName != OperatorNameConventions.CONTAINS.asString()) return null
|
||||
|
||||
val resolvedCall = element.toResolvedCall() ?: return null
|
||||
if (!resolvedCall.isReallySuccess()) return null
|
||||
|
||||
+2
-2
@@ -24,11 +24,11 @@ import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||
import org.jetbrains.kotlin.idea.intentions.calleeName
|
||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
public class ReplaceInvokeIntention : JetSelfTargetingRangeIntention<JetDotQualifiedExpression>(javaClass(), "Replace 'invoke' with direct call"), HighPriorityAction {
|
||||
override fun applicabilityRange(element: JetDotQualifiedExpression): TextRange? {
|
||||
if (element.calleeName != OperatorConventions.INVOKE.asString()) return null
|
||||
if (element.calleeName != OperatorNameConventions.INVOKE.asString()) return null
|
||||
return element.callExpression!!.getCalleeExpression()!!.getTextRange()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -416,7 +416,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
}
|
||||
|
||||
return fakeFunction.initialize(null, null, typeParameters, Collections.emptyList(), null,
|
||||
null, Visibilities.INTERNAL, false, false)
|
||||
null, Visibilities.INTERNAL)
|
||||
}
|
||||
|
||||
private fun renderTypeCandidates(
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.Functi
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
||||
import org.jetbrains.kotlin.psi.JetForExpression
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
object CreateHasNextFunctionActionFactory : CreateCallableMemberFromUsageFactory<JetForExpression>() {
|
||||
override fun getElementOfInterest(diagnostic: Diagnostic): JetForExpression? {
|
||||
@@ -38,6 +38,6 @@ object CreateHasNextFunctionActionFactory : CreateCallableMemberFromUsageFactory
|
||||
DiagnosticFactory.cast(diagnostic, Errors.HAS_NEXT_MISSING, Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE)
|
||||
val ownerType = TypeInfo(diagnosticWithParameters.a, Variance.IN_VARIANCE)
|
||||
val returnType = TypeInfo(element.platform.builtIns.booleanType, Variance.OUT_VARIANCE)
|
||||
return FunctionInfo(OperatorConventions.HAS_NEXT.asString(), ownerType, returnType, isOperator = true)
|
||||
return FunctionInfo(OperatorNameConventions.HAS_NEXT.asString(), ownerType, returnType, isOperator = true)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.Parame
|
||||
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
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
object CreateInvokeFunctionActionFactory : CreateCallableMemberFromUsageFactory<JetCallExpression>() {
|
||||
override fun getElementOfInterest(diagnostic: Diagnostic): JetCallExpression? {
|
||||
@@ -47,6 +47,6 @@ object CreateInvokeFunctionActionFactory : CreateCallableMemberFromUsageFactory<
|
||||
}
|
||||
|
||||
val returnType = TypeInfo(element, Variance.OUT_VARIANCE)
|
||||
return FunctionInfo(OperatorConventions.INVOKE.asString(), receiverType, returnType, parameterInfos = parameters, isOperator = true)
|
||||
return FunctionInfo(OperatorNameConventions.INVOKE.asString(), receiverType, returnType, parameterInfos = parameters, isOperator = true)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.psi.JetForExpression
|
||||
import org.jetbrains.kotlin.types.JetTypeImpl
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import java.util.*
|
||||
|
||||
object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactory<JetForExpression>() {
|
||||
@@ -58,6 +58,6 @@ object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactor
|
||||
returnJetTypeArguments,
|
||||
returnJetType.memberScope)
|
||||
val returnType = TypeInfo(newReturnJetType, Variance.OUT_VARIANCE)
|
||||
return FunctionInfo(OperatorConventions.ITERATOR.asString(), iterableType, returnType, isOperator = true)
|
||||
return FunctionInfo(OperatorNameConventions.ITERATOR.asString(), iterableType, returnType, isOperator = true)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeIn
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetForExpression
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
object CreateNextFunctionActionFactory : CreateCallableMemberFromUsageFactory<JetForExpression>() {
|
||||
override fun getElementOfInterest(diagnostic: Diagnostic): JetForExpression? {
|
||||
@@ -39,6 +39,6 @@ object CreateNextFunctionActionFactory : CreateCallableMemberFromUsageFactory<Je
|
||||
|
||||
val variableExpr = element.loopParameter ?: element.multiParameter ?: return null
|
||||
val returnType = TypeInfo(variableExpr as JetExpression, Variance.OUT_VARIANCE)
|
||||
return FunctionInfo(OperatorConventions.NEXT.asString(), ownerType, returnType, isOperator = true)
|
||||
return FunctionInfo(OperatorNameConventions.NEXT.asString(), ownerType, returnType, isOperator = true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user