From 70a994b1356f8e4b6a9c1b55b954bf38cbebc661 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 27 Jun 2016 17:35:08 +0300 Subject: [PATCH] Drop resolution of deprecated plus/minus/get/set conventions Also remove the corresponding quick fix --- .../jetbrains/kotlin/diagnostics/Errors.java | 3 - .../rendering/DefaultErrorMessages.java | 3 - .../resolve/DelegatedPropertyResolver.java | 40 ++-------- .../kotlin/resolve/calls/CallResolverUtil.kt | 8 -- .../calls/checkers/OperatorCallChecker.kt | 21 +----- .../calls/tower/NewResolutionOldInference.kt | 14 +--- ...recatedGetSetPropertyDelegateConvention.kt | 8 +- ...ecatedGetSetPropertyDelegateConvention.txt | 4 +- .../DeprecatedUnaryOperatorConventions.kt | 8 +- .../staticCallsInDynamicContext.kt | 2 +- .../inspections/KotlinCleanupInspection.kt | 2 - .../DeprecatedFunctionConventionFix.kt | 75 ------------------- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 3 - .../kotlin/conventions/plus.results.txt | 1 - idea/testData/inspections/cleanup/cleanup.kt | 7 -- .../inspections/cleanup/cleanup.kt.after | 7 -- .../deprecatedDelegatesGetSetExtension.kt | 10 --- ...eprecatedDelegatesGetSetExtension.kt.after | 10 --- .../deprecatedDelegatesGetSetMember.kt | 13 ---- .../deprecatedDelegatesGetSetMember.kt.after | 13 ---- .../idea/quickfix/QuickFixTestGenerated.java | 12 --- 21 files changed, 20 insertions(+), 244 deletions(-) delete mode 100644 idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedFunctionConventionFix.kt delete mode 100644 idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetExtension.kt delete mode 100644 idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetExtension.kt.after delete mode 100644 idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetMember.kt delete mode 100644 idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetMember.kt.after diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index b49e69db0e6..f2dd3be540d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -580,8 +580,6 @@ public interface Errors { DiagnosticFactory0 NO_GET_METHOD = DiagnosticFactory0.create(ERROR, ARRAY_ACCESS); DiagnosticFactory0 NO_SET_METHOD = DiagnosticFactory0.create(ERROR, ARRAY_ACCESS); - DiagnosticFactory2 DEPRECATED_UNARY_PLUS_MINUS = DiagnosticFactory2.create(ERROR); - DiagnosticFactory0 INC_DEC_SHOULD_NOT_RETURN_UNIT = DiagnosticFactory0.create(ERROR); DiagnosticFactory2 ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT = DiagnosticFactory2.create(ERROR); @@ -607,7 +605,6 @@ public interface Errors { DiagnosticFactory1>> ITERATOR_AMBIGUITY = DiagnosticFactory1.create(ERROR); DiagnosticFactory2 DELEGATE_SPECIAL_FUNCTION_MISSING = DiagnosticFactory2.create(ERROR); - DiagnosticFactory3 DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION = DiagnosticFactory3.create(ERROR); DiagnosticFactory2>> DELEGATE_SPECIAL_FUNCTION_AMBIGUITY = DiagnosticFactory2.create(ERROR); DiagnosticFactory2>> DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE = DiagnosticFactory2.create(ERROR); DiagnosticFactory3 DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index c4fb7c989b9..225cd067a82 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -312,8 +312,6 @@ public class DefaultErrorMessages { MAP.put(NO_GET_METHOD, "No get method providing array access"); MAP.put(NO_SET_METHOD, "No set method providing array access"); - MAP.put(DEPRECATED_UNARY_PLUS_MINUS, "Unary operation must be named ''{1}'', not ''{0}''", NAME, STRING); - MAP.put(INC_DEC_SHOULD_NOT_RETURN_UNIT, "Functions inc(), dec() shouldn't return Unit to be used by operators ++, --"); MAP.put(ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT, "Function ''{0}'' should return Unit to be used by corresponding operator ''{1}''", NAME, ELEMENT_TEXT); @@ -365,7 +363,6 @@ public class DefaultErrorMessages { MAP.put(ITERATOR_AMBIGUITY, "Method ''iterator()'' is ambiguous for this expression: {0}", AMBIGUOUS_CALLS); MAP.put(DELEGATE_SPECIAL_FUNCTION_MISSING, "Missing ''{0}'' method on delegate of type ''{1}''", STRING, RENDER_TYPE); - MAP.put(DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION, "''{0}'' method convention on type ''{1}'' is no longer supported. Rename to ''{2}''", NAME, RENDER_TYPE, STRING); MAP.put(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, "Overload resolution ambiguity on method ''{0}'': {1}", STRING, AMBIGUOUS_CALLS); MAP.put(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, "Property delegate must have a ''{0}'' method. None of the following functions is suitable: {1}", STRING, AMBIGUOUS_CALLS); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java index 1823a718957..0ae7acac342 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java @@ -63,9 +63,6 @@ import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.creat public class DelegatedPropertyResolver { public static final Name PROPERTY_DELEGATED_FUNCTION_NAME = Name.identifier("propertyDelegated"); - private static final Name OLD_GETTER_NAME = Name.identifier("get"); - private static final Name OLD_SETTER_NAME = Name.identifier("set"); - private final ExpressionTypingServices expressionTypingServices; private final FakeCallResolver fakeCallResolver; private final KotlinBuiltIns builtIns; @@ -142,7 +139,7 @@ public class DelegatedPropertyResolver { return resolvedCall != null ? resolvedCall.getResultingDescriptor().getReturnType() : null; } - public void resolveDelegatedPropertyGetMethod( + private void resolveDelegatedPropertyGetMethod( @NotNull VariableDescriptorWithAccessors variableDescriptor, @NotNull KtExpression delegateExpression, @NotNull KotlinType delegateType, @@ -162,7 +159,7 @@ public class DelegatedPropertyResolver { } } - public void resolveDelegatedPropertySetMethod( + private void resolveDelegatedPropertySetMethod( @NotNull VariableDescriptorWithAccessors variableDescriptor, @NotNull KtExpression delegateExpression, @NotNull KotlinType delegateType, @@ -177,7 +174,7 @@ public class DelegatedPropertyResolver { return psiFactory.createExpression("null as " + KotlinBuiltIns.FQ_NAMES.kProperty.asSingleFqName().asString() + "<*>"); } - public void resolveDelegatedPropertyPDMethod( + private void resolveDelegatedPropertyPDMethod( @NotNull VariableDescriptorWithAccessors variableDescriptor, @NotNull KtExpression delegateExpression, @NotNull KotlinType delegateType, @@ -273,7 +270,7 @@ public class DelegatedPropertyResolver { } /* Resolve getValue() or setValue() methods from delegate */ - public OverloadResolutionResults getDelegatedPropertyConventionMethod( + private OverloadResolutionResults getDelegatedPropertyConventionMethod( @NotNull VariableDescriptorWithAccessors propertyDescriptor, @NotNull KtExpression delegateExpression, @NotNull KotlinType delegateType, @@ -314,35 +311,8 @@ public class DelegatedPropertyResolver { Pair> resolutionResult = fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, functionName, delegateExpression); - OverloadResolutionResults resolutionResults = resolutionResult.getSecond(); - - // Resolve get/set is getValue/setValue was not found. Temporary, for code migration - if (!resolutionResults.isSuccess() && !resolutionResults.isAmbiguity()) { - Name oldFunctionName = isGet ? OLD_GETTER_NAME : OLD_SETTER_NAME; - Pair> additionalResolutionResult = - fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, oldFunctionName, delegateExpression); - if (additionalResolutionResult.getSecond().isSuccess()) { - FunctionDescriptor resultingDescriptor = additionalResolutionResult.getSecond().getResultingDescriptor(); - - PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(propertyDescriptor); - if (declaration instanceof KtProperty) { - KtProperty property = (KtProperty) declaration; - KtPropertyDelegate delegate = property.getDelegate(); - if (delegate != null) { - PsiElement byKeyword = delegate.getByKeywordNode().getPsi(); - - trace.report(DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION.on( - byKeyword, resultingDescriptor, delegateType, functionName.asString())); - } - } - - trace.record(BindingContext.DELEGATED_PROPERTY_CALL, accessor, additionalResolutionResult.getFirst()); - return additionalResolutionResult.getSecond(); - } - } - trace.record(BindingContext.DELEGATED_PROPERTY_CALL, accessor, resolutionResult.getFirst()); - return resolutionResults; + return resolutionResult.getSecond(); } //TODO: diagnostics rendering does not belong here diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt index a1f611d6d5c..5de4b332c76 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt @@ -24,7 +24,6 @@ import org.jetbrains.kotlin.builtins.isExtensionFunctionType import org.jetbrains.kotlin.coroutines.getExpectedTypeForCoroutineControllerHandleResult import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.incremental.KotlinLookupLocation -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.CallTransformer @@ -138,13 +137,6 @@ fun isConventionCall(call: Call): Boolean { fun isInfixCall(call: Call): Boolean = InfixCallChecker.isInfixCall(call.calleeExpression) -fun getUnaryPlusOrMinusOperatorFunctionName(call: Call): Name? { - if (call.callElement !is KtPrefixExpression) return null - val calleeExpression = call.calleeExpression as? KtOperationReferenceExpression ?: return null - val name = calleeExpression.getNameForConventionalOperation(unaryOperations = true, binaryOperations = false) - return if (name == OperatorNameConventions.UNARY_PLUS || name == OperatorNameConventions.UNARY_MINUS) name else null -} - fun isInvokeCallOnVariable(call: Call): Boolean { if (call.callType !== Call.CallType.INVOKE) return false val dispatchReceiver = call.dispatchReceiver diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/OperatorCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/OperatorCallChecker.kt index a028efbae40..4950823a668 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/OperatorCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/OperatorCallChecker.kt @@ -20,7 +20,9 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.diagnostics.DiagnosticSink import org.jetbrains.kotlin.diagnostics.Errors -import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.KtArrayAccessExpression +import org.jetbrains.kotlin.psi.KtDestructuringDeclarationEntry +import org.jetbrains.kotlin.psi.KtOperationReferenceExpression import org.jetbrains.kotlin.resolve.calls.CallTransformer import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isConventionCall import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall @@ -28,10 +30,6 @@ import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.util.OperatorNameConventions.MINUS -import org.jetbrains.kotlin.util.OperatorNameConventions.PLUS -import org.jetbrains.kotlin.util.OperatorNameConventions.UNARY_MINUS -import org.jetbrains.kotlin.util.OperatorNameConventions.UNARY_PLUS class OperatorCallChecker : CallChecker { override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { @@ -62,19 +60,6 @@ class OperatorCallChecker : CallChecker { if (!functionDescriptor.isOperator) { report(reportOn, functionDescriptor, context.trace) } - if (isConventionOperator) { - checkDeprecatedUnaryConventions(call, functionDescriptor, context.trace) - } - } - } - - private fun checkDeprecatedUnaryConventions(call: Call, functionDescriptor: FunctionDescriptor, sink: DiagnosticSink) { - (call.callElement as? KtPrefixExpression)?.let { expr -> - val functionName = functionDescriptor.name - if (functionName == PLUS || functionName == MINUS) { - val newName = if (functionName == PLUS) UNARY_PLUS else UNARY_MINUS - sink.report(Errors.DEPRECATED_UNARY_PLUS_MINUS.on(expr, functionDescriptor, newName.asString())) - } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index a80998739c8..bbbdcf7f2f7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.psi.Call import org.jetbrains.kotlin.resolve.TemporaryBindingTrace import org.jetbrains.kotlin.resolve.calls.CallTransformer import org.jetbrains.kotlin.resolve.calls.CandidateResolver -import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getUnaryPlusOrMinusOperatorFunctionName import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isConventionCall import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInfixCall import org.jetbrains.kotlin.resolve.calls.callUtil.createLookupLocation @@ -141,22 +140,11 @@ class NewResolutionOldInference( val dynamicScope = dynamicCallableDescriptors.createDynamicDescriptorScope(context.call, context.scope.ownerDescriptor) val scopeTower = ScopeTowerImpl(context, dynamicScope, syntheticScopes, context.call.createLookupLocation()) - var processor = kind.createTowerProcessor(this, name, tracing, scopeTower, explicitReceiver, context) + val processor = kind.createTowerProcessor(this, name, tracing, scopeTower, explicitReceiver, context) if (context.collectAllCandidates) { return allCandidatesResult(towerResolver.collectAllCandidates(scopeTower, processor)) } - // Temporary fix for code migration (unaryPlus()/unaryMinus()) - val unaryConventionName = getUnaryPlusOrMinusOperatorFunctionName(context.call) - if (unaryConventionName != null) { - val deprecatedName = if (name == OperatorNameConventions.UNARY_PLUS) - OperatorNameConventions.PLUS - else - OperatorNameConventions.MINUS - - val deprecatedProcessor = kind.createTowerProcessor(this, deprecatedName, tracing, scopeTower, explicitReceiver, context) - processor = CompositeScopeTowerProcessor(processor, deprecatedProcessor) - } val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = kind != ResolutionKind.CallableReference) return convertToOverloadResults(candidates, tracing, context) diff --git a/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.kt b/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.kt index 8e2d976c51d..7d65d6c930a 100644 --- a/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.kt +++ b/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.kt @@ -33,15 +33,15 @@ operator fun CustomDelegate3.setValue(thisRef: Any?, prop: KProperty<*>, value: class Example { - var a by CustomDelegate() - val aval by CustomDelegate() + var a by CustomDelegate() + val aval by CustomDelegate() var b by OkDelegate() var c by CustomDelegate2() var d by CustomDelegate3() fun test() { - requireString(a) - requireString(aval) + requireString(a) + requireString(aval) requireString(b) requireInt(c) requireInt(d) diff --git a/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.txt b/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.txt index 3b00c151055..f77c3760afd 100644 --- a/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.txt +++ b/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.txt @@ -36,8 +36,8 @@ public final class CustomDelegate3 { public final class Example { public constructor Example() - public final var a: kotlin.String - public final val aval: kotlin.String + public final var a: [ERROR : Type from delegate] + public final val aval: [ERROR : Type from delegate] public final var b: kotlin.String public final var c: kotlin.Int public final var d: kotlin.Int diff --git a/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.kt b/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.kt index 26cf5014740..6d714fe9908 100644 --- a/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.kt +++ b/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.kt @@ -15,7 +15,7 @@ operator fun String.unaryPlus(): Int = 0 fun test() { requireInt(+ "") requireInt(+ Example()) - requireString(+ ExampleDeprecated()) + requireString(+ ExampleDeprecated()) } fun requireInt(n: Int) {} @@ -26,7 +26,7 @@ class Example2 { operator fun minus() = this fun test() { - +this - -this + +this + -this } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticCallsInDynamicContext.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticCallsInDynamicContext.kt index 53ff9b7b1b4..b5b9a1399f2 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticCallsInDynamicContext.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticCallsInDynamicContext.kt @@ -27,7 +27,7 @@ fun dynamic.test() { this() C() + C() - +C() + +C() this + C() diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt index 2126243945e..04e50708c6c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt @@ -92,8 +92,6 @@ class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspectionTo Errors.DEPRECATION_ERROR, Errors.NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION, Errors.OPERATOR_MODIFIER_REQUIRED, - Errors.DEPRECATED_UNARY_PLUS_MINUS, - Errors.DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION, Errors.INFIX_MODIFIER_REQUIRED, Errors.CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS, Errors.DEPRECATED_TYPE_PARAMETER_SYNTAX, diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedFunctionConventionFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedFunctionConventionFix.kt deleted file mode 100644 index 8aaf3e249df..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedFunctionConventionFix.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.quickfix - -import com.intellij.codeInsight.intention.IntentionAction -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.project.Project -import com.intellij.psi.PsiElement -import com.intellij.refactoring.rename.RenameProcessor -import com.intellij.usageView.UsageInfo -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters2 -import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters3 -import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.psi.KtNamedFunction -import org.jetbrains.kotlin.psi.KtOperationReferenceExpression - -class DeprecatedFunctionConventionFix( - element: KtNamedFunction, - private val newName: String -) : KotlinQuickFixAction(element), CleanupFix { - override fun getText(): String = "Rename to '$newName'" - override fun getFamilyName(): String = text - - override fun invoke(project: Project, editor: Editor?, file: KtFile) { - FilteredRenameProcessor(project, element, newName, false, false).run() - } - - override fun startInWriteAction(): Boolean = false - - companion object : KotlinSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic): IntentionAction? { - val (functionDescriptor, newName) = when (diagnostic) { - is DiagnosticWithParameters3<*, *, *, *> -> Pair(diagnostic.a, diagnostic.c) - is DiagnosticWithParameters2<*, *, *> -> Pair(diagnostic.a, diagnostic.b) - else -> Pair(null, null) - } - if (functionDescriptor !is FunctionDescriptor || newName !is String) return null - - val element = DescriptorToSourceUtilsIde.getAnyDeclaration(diagnostic.psiFile.project, functionDescriptor) - as? KtNamedFunction ?: return null - return DeprecatedFunctionConventionFix(element, newName) - } - } - - private class FilteredRenameProcessor( - project: Project, - element: PsiElement, - newName: String, - isSearchInComments: Boolean, - isSearchTextOccurrences: Boolean - ) : RenameProcessor(project, element, newName, isSearchInComments, isSearchTextOccurrences) { - override fun findUsages(): Array { - return super.findUsages().filter { - it.element !is KtOperationReferenceExpression - }.toTypedArray() - } - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 6051e7ee931..668ca51ec2e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -386,9 +386,6 @@ class QuickFixRegistrar : QuickFixContributor { MISPLACED_TYPE_PARAMETER_CONSTRAINTS.registerFactory(MoveTypeParameterConstraintFix) - DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION.registerFactory(DeprecatedFunctionConventionFix) - DEPRECATED_UNARY_PLUS_MINUS.registerFactory(DeprecatedFunctionConventionFix) - COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT.registerFactory(CommaInWhenConditionWithoutArgumentFix) DATA_CLASS_NOT_PROPERTY_PARAMETER.registerFactory(AddValVarToConstructorParameterAction.QuickFixFactory) diff --git a/idea/testData/findUsages/kotlin/conventions/plus.results.txt b/idea/testData/findUsages/kotlin/conventions/plus.results.txt index 0dd61ab69c0..0d0cf18c482 100644 --- a/idea/testData/findUsages/kotlin/conventions/plus.results.txt +++ b/idea/testData/findUsages/kotlin/conventions/plus.results.txt @@ -3,4 +3,3 @@ Function call 11 A(0) plus A(1) plus 2 Function call 12 A(0).plus(A(1).plus(2)) Function call 15 a += 1 Function call 6 fun plus(a: A): A = this + a.n -Unclassified usage 18 +A(0) diff --git a/idea/testData/inspections/cleanup/cleanup.kt b/idea/testData/inspections/cleanup/cleanup.kt index 0d5f78e6ace..c19d1adf313 100644 --- a/idea/testData/inspections/cleanup/cleanup.kt +++ b/idea/testData/inspections/cleanup/cleanup.kt @@ -38,14 +38,7 @@ annotation class Fancy(val param: Int) @Fancy(i) class D -class CustomDelegate { - operator fun get(thisRef: Any?, prop: KProperty<*>): String = "" - operator fun set(thisRef: Any?, prop: KProperty<*>, value: String) {} -} - class B { - var a: String by CustomDelegate() - fun plus(a: A): A = A() } diff --git a/idea/testData/inspections/cleanup/cleanup.kt.after b/idea/testData/inspections/cleanup/cleanup.kt.after index 58ec1acd121..eff61ccc3d0 100644 --- a/idea/testData/inspections/cleanup/cleanup.kt.after +++ b/idea/testData/inspections/cleanup/cleanup.kt.after @@ -37,14 +37,7 @@ annotation class Fancy(val param: Int) @Fancy(i) class D -class CustomDelegate { - operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = "" - operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: String) {} -} - class B { - var a: String by CustomDelegate() - operator fun plus(a: A): A = A() } diff --git a/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetExtension.kt b/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetExtension.kt deleted file mode 100644 index a3437560425..00000000000 --- a/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetExtension.kt +++ /dev/null @@ -1,10 +0,0 @@ -// "Rename to 'getValue'" "true" -import kotlin.reflect.KProperty - -class CustomDelegate - -operator fun CustomDelegate.get(thisRef: Any?, prop: KProperty<*>): String = "" - -class Example { - val a: String by CustomDelegate() -} diff --git a/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetExtension.kt.after b/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetExtension.kt.after deleted file mode 100644 index b0e39ad01f5..00000000000 --- a/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetExtension.kt.after +++ /dev/null @@ -1,10 +0,0 @@ -// "Rename to 'getValue'" "true" -import kotlin.reflect.KProperty - -class CustomDelegate - -operator fun CustomDelegate.getValue(thisRef: Any?, prop: KProperty<*>): String = "" - -class Example { - val a: String by CustomDelegate() -} diff --git a/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetMember.kt b/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetMember.kt deleted file mode 100644 index 35e091fbfc7..00000000000 --- a/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetMember.kt +++ /dev/null @@ -1,13 +0,0 @@ -// "Rename to 'setValue'" "true" -// ERROR: 'get' method convention on type 'CustomDelegate' is no longer supported. Rename to 'getValue' - -import kotlin.reflect.KProperty - -class CustomDelegate { - operator fun get(thisRef: Any?, prop: KProperty<*>): String = "" - operator fun set(thisRef: Any?, prop: KProperty<*>, value: String) {} -} - -class Example { - var a: String by CustomDelegate() -} diff --git a/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetMember.kt.after b/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetMember.kt.after deleted file mode 100644 index 8bd2d20fc26..00000000000 --- a/idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetMember.kt.after +++ /dev/null @@ -1,13 +0,0 @@ -// "Rename to 'setValue'" "true" -// ERROR: 'get' method convention on type 'CustomDelegate' is no longer supported. Rename to 'getValue' - -import kotlin.reflect.KProperty - -class CustomDelegate { - operator fun get(thisRef: Any?, prop: KProperty<*>): String = "" - operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: String) {} -} - -class Example { - var a: String by CustomDelegate() -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 423ca4a19b8..6fba904f0bf 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -5466,18 +5466,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } - @TestMetadata("deprecatedDelegatesGetSetExtension.kt") - public void testDeprecatedDelegatesGetSetExtension() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetExtension.kt"); - doTest(fileName); - } - - @TestMetadata("deprecatedDelegatesGetSetMember.kt") - public void testDeprecatedDelegatesGetSetMember() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/deprecatedDelegatesGetSetMember.kt"); - doTest(fileName); - } - @TestMetadata("finalTrait.kt") public void testFinalTrait() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/finalTrait.kt");