From 2ee31916c780959a6ed1f20c33e8b3808fff62f3 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 6 Dec 2016 10:45:41 +0300 Subject: [PATCH] 'createDelegate' operator renamed to 'toDelegateFor' --- .../kotlin/resolve/BindingContext.java | 4 +- .../resolve/DelegatedPropertyResolver.kt | 60 +++++++------- .../kotlin/resolve/OperatorModifierChecker.kt | 4 +- .../createDelegateOperatorDeclaration.kt | 32 -------- .../genericToDelegateFor.kt} | 2 +- .../genericToDelegateFor.txt} | 2 +- .../noOperatorModifierOnToDelegateFor.kt} | 2 +- .../noOperatorModifierOnToDelegateFor.txt} | 2 +- .../simpleToDelegateFor.kt} | 2 +- .../simpleToDelegateFor.txt} | 2 +- .../toDelegateForOperatorDeclaration.kt | 32 ++++++++ .../toDelegateForOperatorDeclaration.txt} | 18 ++--- .../unsupportedOperatorToDelegateFor.kt} | 4 +- .../unsupportedOperatorToDelegateFor.txt} | 2 +- .../checkers/DiagnosticsTestGenerated.java | 78 +++++++++---------- .../kotlin/config/LanguageVersionSettings.kt | 2 +- .../kotlin/util/OperatorNameConventions.kt | 2 +- .../jetbrains/kotlin/util/modifierChecks.kt | 4 +- 18 files changed, 127 insertions(+), 127 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/createDelegateOperatorDeclaration.kt rename compiler/testData/diagnostics/tests/delegatedProperty/{createDelegate/genericCreateDelegate.kt => toDelegateFor/genericToDelegateFor.kt} (77%) rename compiler/testData/diagnostics/tests/delegatedProperty/{createDelegate/genericCreateDelegate.txt => toDelegateFor/genericToDelegateFor.txt} (90%) rename compiler/testData/diagnostics/tests/delegatedProperty/{createDelegate/noOperatorModifierOnCreateDelegate.kt => toDelegateFor/noOperatorModifierOnToDelegateFor.kt} (83%) rename compiler/testData/diagnostics/tests/delegatedProperty/{createDelegate/noOperatorModifierOnCreateDelegate.txt => toDelegateFor/noOperatorModifierOnToDelegateFor.txt} (86%) rename compiler/testData/diagnostics/tests/delegatedProperty/{createDelegate/simpleCreateDelegate.kt => toDelegateFor/simpleToDelegateFor.kt} (72%) rename compiler/testData/diagnostics/tests/delegatedProperty/{createDelegate/simpleCreateDelegate.txt => toDelegateFor/simpleToDelegateFor.txt} (60%) create mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/toDelegateForOperatorDeclaration.kt rename compiler/testData/diagnostics/tests/delegatedProperty/{createDelegateOperatorDeclaration.txt => toDelegateFor/toDelegateForOperatorDeclaration.txt} (60%) rename compiler/testData/diagnostics/tests/delegatedProperty/{createDelegate/unsupportedOperatorCreateDelegate.kt => toDelegateFor/unsupportedOperatorToDelegateFor.kt} (59%) rename compiler/testData/diagnostics/tests/delegatedProperty/{createDelegate/unsupportedOperatorCreateDelegate.txt => toDelegateFor/unsupportedOperatorToDelegateFor.txt} (85%) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java index afafb1b3378..535782e41f6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java @@ -141,8 +141,8 @@ public interface BindingContext { WritableSlice> DELEGATED_PROPERTY_RESOLVED_CALL = Slices.createSimpleSlice(); WritableSlice DELEGATED_PROPERTY_CALL = Slices.createSimpleSlice(); - WritableSlice> CREATE_DELEGATE_RESOLVED_CALL = Slices.createSimpleSlice(); - WritableSlice CREATE_DELEGATE_CALL = Slices.createSimpleSlice(); + WritableSlice> TO_DELEGATE_FOR_RESOLVED_CALL = Slices.createSimpleSlice(); + WritableSlice TO_DELEGATE_FOR_CALL = Slices.createSimpleSlice(); WritableSlice> DELEGATED_PROPERTY_PD_RESOLVED_CALL = Slices.createSimpleSlice(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt index c51a2b57692..86dd26d91e1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt @@ -86,7 +86,7 @@ class DelegatedPropertyResolver( val byExpressionType = resolveDelegateExpression(delegateExpression, property, variableDescriptor, initializerScope, trace, outerDataFlowInfo) - resolveCreateDelegateMethod(variableDescriptor, delegateExpression, byExpressionType, trace, delegateFunctionsScope, outerDataFlowInfo) + resolveToDelegateForMethod(variableDescriptor, delegateExpression, byExpressionType, trace, delegateFunctionsScope, outerDataFlowInfo) val delegateType = getResolvedDelegateType(variableDescriptor, delegateExpression, byExpressionType, trace) resolveGetValueMethod(variableDescriptor, delegateExpression, delegateType, trace, delegateFunctionsScope, outerDataFlowInfo) @@ -103,10 +103,10 @@ class DelegatedPropertyResolver( byExpressionType: KotlinType, trace: BindingTrace ): KotlinType { - val createDelegateResolvedCall = trace.bindingContext.get(CREATE_DELEGATE_RESOLVED_CALL, variableDescriptor) + val createDelegateResolvedCall = trace.bindingContext.get(TO_DELEGATE_FOR_RESOLVED_CALL, variableDescriptor) if (createDelegateResolvedCall != null) { return createDelegateResolvedCall.resultingDescriptor.returnType - ?: throw AssertionError("No return type fore 'createDelegate' of ${delegateExpression.text}") + ?: throw AssertionError("No return type fore 'toDelegateFor' of ${delegateExpression.text}") } return byExpressionType } @@ -119,7 +119,7 @@ class DelegatedPropertyResolver( delegateFunctionsScope: LexicalScope, dataFlowInfo: DataFlowInfo ): KotlinType? { - resolveCreateDelegateMethod(variableDescriptor, delegateExpression, byExpressionType, trace, delegateFunctionsScope, dataFlowInfo) + resolveToDelegateForMethod(variableDescriptor, delegateExpression, byExpressionType, trace, delegateFunctionsScope, dataFlowInfo) val delegateType = getResolvedDelegateType(variableDescriptor, delegateExpression, byExpressionType, trace) resolveGetSetValueMethod(variableDescriptor, delegateExpression, delegateType, trace, delegateFunctionsScope, dataFlowInfo, true) @@ -127,8 +127,8 @@ class DelegatedPropertyResolver( return if (resolvedCall != null) resolvedCall.resultingDescriptor.returnType else null } - private val isOperatorCreateDelegateSupported: Boolean - get() = languageVersionSettings.supportsFeature(LanguageFeature.OperatorCreateDelegate) + private val isOperatorToDelegateForSupported: Boolean + get() = languageVersionSettings.supportsFeature(LanguageFeature.OperatorToDelegateFor) private fun resolveGetValueMethod( variableDescriptor: VariableDescriptorWithAccessors, @@ -268,7 +268,7 @@ class DelegatedPropertyResolver( } } - private fun resolveCreateDelegateMethod( + private fun resolveToDelegateForMethod( propertyDescriptor: VariableDescriptorWithAccessors, byExpression: KtExpression, byExpressionType: KotlinType, @@ -276,27 +276,27 @@ class DelegatedPropertyResolver( delegateFunctionsScope: LexicalScope, dataFlowInfo: DataFlowInfo ) { - if (!isOperatorCreateDelegateSupported) return - if (trace.bindingContext.get(BindingContext.CREATE_DELEGATE_CALL, propertyDescriptor) != null) return + if (!isOperatorToDelegateForSupported) return + if (trace.bindingContext.get(BindingContext.TO_DELEGATE_FOR_CALL, propertyDescriptor) != null) return - val createDelegateResults = getCreateDelegateMethod(propertyDescriptor, byExpression, byExpressionType, - trace, delegateFunctionsScope, dataFlowInfo) - if (!createDelegateResults.isSuccess) { - val call = trace.bindingContext.get(BindingContext.CREATE_DELEGATE_CALL, propertyDescriptor) + val toDelegateForResults = getToDelegateForMethod(propertyDescriptor, byExpression, byExpressionType, + trace, delegateFunctionsScope, dataFlowInfo) + if (!toDelegateForResults.isSuccess) { + val call = trace.bindingContext.get(BindingContext.TO_DELEGATE_FOR_CALL, propertyDescriptor) ?: throw AssertionError("'getDelegatedPropertyConventionMethod' didn't record a call") - reportDelegateOperatorResolutionError(trace, call, createDelegateResults, byExpression, byExpressionType, + reportDelegateOperatorResolutionError(trace, call, toDelegateForResults, byExpression, byExpressionType, operatorRequired = false) return } - val resultingDescriptor = createDelegateResults.resultingDescriptor + val resultingDescriptor = toDelegateForResults.resultingDescriptor if (!resultingDescriptor.isOperator) { // TODO resolved 'createDelegate' function, which is not an operator - warning? return } - val resultingCall = createDelegateResults.resultingCall - trace.record(CREATE_DELEGATE_RESOLVED_CALL, propertyDescriptor, resultingCall) + val resultingCall = toDelegateForResults.resultingCall + trace.record(TO_DELEGATE_FOR_RESOLVED_CALL, propertyDescriptor, resultingCall) } /* Resolve getValue() or setValue() methods from delegate */ @@ -345,7 +345,7 @@ class DelegatedPropertyResolver( return resolutionResult.second } - private fun getCreateDelegateMethod( + private fun getToDelegateForMethod( propertyDescriptor: VariableDescriptorWithAccessors, delegateExpression: KtExpression, delegateExpressionType: KotlinType, @@ -363,14 +363,14 @@ class DelegatedPropertyResolver( createExpressionForProperty() ) } - val functionName = OperatorNameConventions.CREATE_DELEGATE + val functionName = OperatorNameConventions.TO_DELEGATE_FOR val receiver = ExpressionReceiver.create(delegateExpression, delegateExpressionType, trace.bindingContext) - val (createDelegateCall, createDelegateResolutionResult) = + val (toDelegateForCall, toDelegateForResults) = fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, functionName, delegateExpression) - trace.record(BindingContext.CREATE_DELEGATE_CALL, propertyDescriptor, createDelegateCall) + trace.record(BindingContext.TO_DELEGATE_FOR_CALL, propertyDescriptor, toDelegateForCall) - return createDelegateResolutionResult + return toDelegateForResults } //TODO: diagnostics rendering does not belong here @@ -480,17 +480,17 @@ class DelegatedPropertyResolver( typeVariableSubstitutor: TypeSubstitutor, traceToResolveConventionMethods: TemporaryBindingTrace ): KotlinType { - if (isOperatorCreateDelegateSupported) { - val createDelegateResults = getCreateDelegateMethod( + if (isOperatorToDelegateForSupported) { + val toDelegateForResults = getToDelegateForMethod( variableDescriptor, delegateExpression, byExpressionType, traceToResolveConventionMethods, delegateFunctionsScope, dataFlowInfo ) - if (conventionMethodFound(createDelegateResults)) { - val createDelegateDescriptor = createDelegateResults.resultingDescriptor - val createDelegateReturnType = createDelegateDescriptor.returnType - if (createDelegateDescriptor.isOperator) { - addConstraintForThisValue(constraintSystem, typeVariableSubstitutor, createDelegateDescriptor) - return createDelegateReturnType + if (conventionMethodFound(toDelegateForResults)) { + val toDelegateForDescriptor = toDelegateForResults.resultingDescriptor + val toDelegateForReturnType = toDelegateForDescriptor.returnType + if (toDelegateForDescriptor.isOperator) { + addConstraintForThisValue(constraintSystem, typeVariableSubstitutor, toDelegateForDescriptor) + return toDelegateForReturnType ?: throw AssertionError("No return type fore 'createDelegate' of ${delegateExpression.text}") } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OperatorModifierChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OperatorModifierChecker.kt index 13da0f3a6ee..e17ace107e5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OperatorModifierChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OperatorModifierChecker.kt @@ -48,8 +48,8 @@ object OperatorModifierChecker { checkSupportsFeature(LanguageFeature.Coroutines, languageVersionSettings, diagnosticHolder, modifier) in REM_TO_MOD_OPERATION_NAMES.keys -> checkSupportsFeature(LanguageFeature.OperatorRem, languageVersionSettings, diagnosticHolder, modifier) - OperatorNameConventions.CREATE_DELEGATE -> - checkSupportsFeature(LanguageFeature.OperatorCreateDelegate, languageVersionSettings, diagnosticHolder, modifier) + OperatorNameConventions.TO_DELEGATE_FOR -> + checkSupportsFeature(LanguageFeature.OperatorToDelegateFor, languageVersionSettings, diagnosticHolder, modifier) } if (functionDescriptor.name in REM_TO_MOD_OPERATION_NAMES.values diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegateOperatorDeclaration.kt b/compiler/testData/diagnostics/tests/delegatedProperty/createDelegateOperatorDeclaration.kt deleted file mode 100644 index fbf856c7a94..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegateOperatorDeclaration.kt +++ /dev/null @@ -1,32 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KProperty - -operator fun createDelegate(x: Any?, p: KProperty<*>) {} - -operator fun Any.createDelegate(x: Any?, p: KProperty<*>) {} - -operator fun Any.createDelegate(x: Any?, p: Any) {} - -operator fun Any.createDelegate(x: Any?, p: Int) {} - -class Host1 { - operator fun createDelegate(x: Any?, p: KProperty<*>) {} -} - -class Host2 { - operator fun Any.createDelegate(x: Any?, p: KProperty<*>) {} -} - -class Host3 { - operator fun createDelegate(x: Any?, p: KProperty<*>, foo: Int) {} -} - -class Host4 { - operator fun createDelegate(x: Any?, p: KProperty<*>, foo: Int = 0) {} -} - -class Host5 { - operator fun createDelegate(x: Any?, p: KProperty<*>, vararg foo: Int) {} -} - diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/genericCreateDelegate.kt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/genericToDelegateFor.kt similarity index 77% rename from compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/genericCreateDelegate.kt rename to compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/genericToDelegateFor.kt index bf40701f3ad..fa6f288130a 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/genericCreateDelegate.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/genericToDelegateFor.kt @@ -4,7 +4,7 @@ class Cell(val value: V) class GenericDelegate(val value: V) -operator fun T.createDelegate(a: Any?, p: Any?) = GenericDelegate(this) +operator fun T.toDelegateFor(a: Any?, p: Any?) = GenericDelegate(this) operator fun GenericDelegate.getValue(a: Any?, p: Any?) = Cell(value) diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/genericCreateDelegate.txt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/genericToDelegateFor.txt similarity index 90% rename from compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/genericCreateDelegate.txt rename to compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/genericToDelegateFor.txt index a27190dbbc6..091a4c816e7 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/genericCreateDelegate.txt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/genericToDelegateFor.txt @@ -3,8 +3,8 @@ package public val test1: Cell public val test2: Cell public val test3: Cell -public operator fun T.createDelegate(/*0*/ a: kotlin.Any?, /*1*/ p: kotlin.Any?): GenericDelegate public operator fun GenericDelegate.getValue(/*0*/ a: kotlin.Any?, /*1*/ p: kotlin.Any?): Cell +public operator fun T.toDelegateFor(/*0*/ a: kotlin.Any?, /*1*/ p: kotlin.Any?): GenericDelegate public final class Cell { public constructor Cell(/*0*/ value: V) diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/noOperatorModifierOnCreateDelegate.kt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/noOperatorModifierOnToDelegateFor.kt similarity index 83% rename from compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/noOperatorModifierOnCreateDelegate.kt rename to compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/noOperatorModifierOnToDelegateFor.kt index ad88012409e..937d02a803c 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/noOperatorModifierOnCreateDelegate.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/noOperatorModifierOnToDelegateFor.kt @@ -7,7 +7,7 @@ class StringDelegate(val s: String) { } // NB no operator -fun String.createDelegate(a: Any?, p: KProperty<*>) = StringDelegate(this) +fun String.toDelegateFor(a: Any?, p: KProperty<*>) = StringDelegate(this) operator fun String.getValue(a: Any?, p: KProperty<*>) = this diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/noOperatorModifierOnCreateDelegate.txt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/noOperatorModifierOnToDelegateFor.txt similarity index 86% rename from compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/noOperatorModifierOnCreateDelegate.txt rename to compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/noOperatorModifierOnToDelegateFor.txt index 1a8513e6904..acad04ada03 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/noOperatorModifierOnCreateDelegate.txt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/noOperatorModifierOnToDelegateFor.txt @@ -3,8 +3,8 @@ package public val test1: kotlin.String public val test2: kotlin.Int public val test3: kotlin.String -public fun kotlin.String.createDelegate(/*0*/ a: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): StringDelegate public operator fun kotlin.String.getValue(/*0*/ a: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.String +public fun kotlin.String.toDelegateFor(/*0*/ a: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): StringDelegate public final class StringDelegate { public constructor StringDelegate(/*0*/ s: kotlin.String) diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/simpleCreateDelegate.kt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/simpleToDelegateFor.kt similarity index 72% rename from compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/simpleCreateDelegate.kt rename to compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/simpleToDelegateFor.kt index d3adf675432..1bbf430a2a2 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/simpleCreateDelegate.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/simpleToDelegateFor.kt @@ -2,7 +2,7 @@ import kotlin.reflect.KProperty -operator fun String.createDelegate(a: Any?, p: KProperty<*>) = this +operator fun String.toDelegateFor(a: Any?, p: KProperty<*>) = this operator fun String.getValue(a: Any?, p: KProperty<*>) = this val test1: String by "OK" diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/simpleCreateDelegate.txt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/simpleToDelegateFor.txt similarity index 60% rename from compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/simpleCreateDelegate.txt rename to compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/simpleToDelegateFor.txt index 14fdf89b94d..ff40f0214b6 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/simpleCreateDelegate.txt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/simpleToDelegateFor.txt @@ -2,5 +2,5 @@ package public val test1: kotlin.String public val test2: kotlin.String -public operator fun kotlin.String.createDelegate(/*0*/ a: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.String public operator fun kotlin.String.getValue(/*0*/ a: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.String +public operator fun kotlin.String.toDelegateFor(/*0*/ a: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.String diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/toDelegateForOperatorDeclaration.kt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/toDelegateForOperatorDeclaration.kt new file mode 100644 index 00000000000..dac09f1b84c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/toDelegateForOperatorDeclaration.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty + +operator fun toDelegateFor(x: Any?, p: KProperty<*>) {} + +operator fun Any.toDelegateFor(x: Any?, p: KProperty<*>) {} + +operator fun Any.toDelegateFor(x: Any?, p: Any) {} + +operator fun Any.toDelegateFor(x: Any?, p: Int) {} + +class Host1 { + operator fun toDelegateFor(x: Any?, p: KProperty<*>) {} +} + +class Host2 { + operator fun Any.toDelegateFor(x: Any?, p: KProperty<*>) {} +} + +class Host3 { + operator fun toDelegateFor(x: Any?, p: KProperty<*>, foo: Int) {} +} + +class Host4 { + operator fun toDelegateFor(x: Any?, p: KProperty<*>, foo: Int = 0) {} +} + +class Host5 { + operator fun toDelegateFor(x: Any?, p: KProperty<*>, vararg foo: Int) {} +} + diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegateOperatorDeclaration.txt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/toDelegateForOperatorDeclaration.txt similarity index 60% rename from compiler/testData/diagnostics/tests/delegatedProperty/createDelegateOperatorDeclaration.txt rename to compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/toDelegateForOperatorDeclaration.txt index b4485233d01..07e3e13399d 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegateOperatorDeclaration.txt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/toDelegateForOperatorDeclaration.txt @@ -1,15 +1,15 @@ package -public operator fun createDelegate(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit -public operator fun kotlin.Any.createDelegate(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.Any): kotlin.Unit -public operator fun kotlin.Any.createDelegate(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.Int): kotlin.Unit -public operator fun kotlin.Any.createDelegate(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit +public operator fun toDelegateFor(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit +public operator fun kotlin.Any.toDelegateFor(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.Any): kotlin.Unit +public operator fun kotlin.Any.toDelegateFor(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.Int): kotlin.Unit +public operator fun kotlin.Any.toDelegateFor(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit public final class Host1 { public constructor Host1() - public final operator fun createDelegate(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final operator fun toDelegateFor(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } @@ -18,29 +18,29 @@ public final class Host2 { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - public final operator fun kotlin.Any.createDelegate(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit + public final operator fun kotlin.Any.toDelegateFor(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit } public final class Host3 { public constructor Host3() - public final operator fun createDelegate(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>, /*2*/ foo: kotlin.Int): kotlin.Unit public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final operator fun toDelegateFor(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>, /*2*/ foo: kotlin.Int): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } public final class Host4 { public constructor Host4() - public final operator fun createDelegate(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>, /*2*/ foo: kotlin.Int = ...): kotlin.Unit public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final operator fun toDelegateFor(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>, /*2*/ foo: kotlin.Int = ...): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } public final class Host5 { public constructor Host5() - public final operator fun createDelegate(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>, /*2*/ vararg foo: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final operator fun toDelegateFor(/*0*/ x: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>, /*2*/ vararg foo: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/unsupportedOperatorCreateDelegate.kt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/unsupportedOperatorToDelegateFor.kt similarity index 59% rename from compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/unsupportedOperatorCreateDelegate.kt rename to compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/unsupportedOperatorToDelegateFor.kt index a920d0e2685..6aae15583a0 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/unsupportedOperatorCreateDelegate.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/unsupportedOperatorToDelegateFor.kt @@ -1,11 +1,11 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -// !LANGUAGE: -OperatorCreateDelegate +// !LANGUAGE: -OperatorToDelegateFor class WrongDelegate(val x: Int) { operator fun getValue(thisRef: Any?, prop: Any): Int = x } -operator fun String.createDelegate(thisRef: Any?, prop: Any) = WrongDelegate(this.length) +operator fun String.toDelegateFor(thisRef: Any?, prop: Any) = WrongDelegate(this.length) operator fun String.getValue(thisRef: Any?, prop: Any) = this diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/unsupportedOperatorCreateDelegate.txt b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/unsupportedOperatorToDelegateFor.txt similarity index 85% rename from compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/unsupportedOperatorCreateDelegate.txt rename to compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/unsupportedOperatorToDelegateFor.txt index 1b5cc65f256..5b6e627f07b 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/unsupportedOperatorCreateDelegate.txt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/unsupportedOperatorToDelegateFor.txt @@ -3,8 +3,8 @@ package public val test1: kotlin.String public val test2: kotlin.Int public val test3: kotlin.String -public operator fun kotlin.String.createDelegate(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.Any): WrongDelegate public operator fun kotlin.String.getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.Any): kotlin.String +public operator fun kotlin.String.toDelegateFor(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.Any): WrongDelegate public final class WrongDelegate { public constructor WrongDelegate(/*0*/ x: kotlin.Int) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index d745d8c64b0..668667f18da 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -5524,12 +5524,6 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } - @TestMetadata("createDelegateOperatorDeclaration.kt") - public void testCreateDelegateOperatorDeclaration() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/createDelegateOperatorDeclaration.kt"); - doTest(fileName); - } - @TestMetadata("defaultGetter.kt") public void testDefaultGetter() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/defaultGetter.kt"); @@ -5758,39 +5752,6 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } - @TestMetadata("compiler/testData/diagnostics/tests/delegatedProperty/createDelegate") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class CreateDelegate extends AbstractDiagnosticsTest { - public void testAllFilesPresentInCreateDelegate() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/delegatedProperty/createDelegate"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("genericCreateDelegate.kt") - public void testGenericCreateDelegate() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/genericCreateDelegate.kt"); - doTest(fileName); - } - - @TestMetadata("noOperatorModifierOnCreateDelegate.kt") - public void testNoOperatorModifierOnCreateDelegate() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/noOperatorModifierOnCreateDelegate.kt"); - doTest(fileName); - } - - @TestMetadata("simpleCreateDelegate.kt") - public void testSimpleCreateDelegate() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/simpleCreateDelegate.kt"); - doTest(fileName); - } - - @TestMetadata("unsupportedOperatorCreateDelegate.kt") - public void testUnsupportedOperatorCreateDelegate() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/createDelegate/unsupportedOperatorCreateDelegate.kt"); - doTest(fileName); - } - } - @TestMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -5871,6 +5832,45 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } } + + @TestMetadata("compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ToDelegateFor extends AbstractDiagnosticsTest { + public void testAllFilesPresentInToDelegateFor() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("genericToDelegateFor.kt") + public void testGenericToDelegateFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/genericToDelegateFor.kt"); + doTest(fileName); + } + + @TestMetadata("noOperatorModifierOnToDelegateFor.kt") + public void testNoOperatorModifierOnToDelegateFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/noOperatorModifierOnToDelegateFor.kt"); + doTest(fileName); + } + + @TestMetadata("simpleToDelegateFor.kt") + public void testSimpleToDelegateFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/simpleToDelegateFor.kt"); + doTest(fileName); + } + + @TestMetadata("toDelegateForOperatorDeclaration.kt") + public void testToDelegateForOperatorDeclaration() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/toDelegateForOperatorDeclaration.kt"); + doTest(fileName); + } + + @TestMetadata("unsupportedOperatorToDelegateFor.kt") + public void testUnsupportedOperatorToDelegateFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/toDelegateFor/unsupportedOperatorToDelegateFor.kt"); + doTest(fileName); + } + } } @TestMetadata("compiler/testData/diagnostics/tests/delegation") diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index a85ba7ad07a..75df3f967fb 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -36,7 +36,7 @@ enum class LanguageFeature(val sinceVersion: LanguageVersion?) { DivisionByZeroInConstantExpressions(KOTLIN_1_1), InlineConstVals(KOTLIN_1_1), OperatorRem(KOTLIN_1_1), - OperatorCreateDelegate(KOTLIN_1_1), + OperatorToDelegateFor(KOTLIN_1_1), // Experimental features MultiPlatformProjects(null), diff --git a/core/descriptors/src/org/jetbrains/kotlin/util/OperatorNameConventions.kt b/core/descriptors/src/org/jetbrains/kotlin/util/OperatorNameConventions.kt index 5da4771ba98..cd4413b8a6f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/util/OperatorNameConventions.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/util/OperatorNameConventions.kt @@ -22,7 +22,7 @@ object OperatorNameConventions { @JvmField val GET_VALUE = Name.identifier("getValue") @JvmField val SET_VALUE = Name.identifier("setValue") @JvmField val PROPERTY_DELEGATED = Name.identifier("propertyDelegated") - @JvmField val CREATE_DELEGATE = Name.identifier("createDelegate") + @JvmField val TO_DELEGATE_FOR = Name.identifier("toDelegateFor") @JvmField val EQUALS = Name.identifier("equals") @JvmField val COMPARE_TO = Name.identifier("compareTo") diff --git a/core/descriptors/src/org/jetbrains/kotlin/util/modifierChecks.kt b/core/descriptors/src/org/jetbrains/kotlin/util/modifierChecks.kt index 4699921d996..b99df7bf56f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/util/modifierChecks.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/util/modifierChecks.kt @@ -37,7 +37,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions.CONTAINS import org.jetbrains.kotlin.util.OperatorNameConventions.COROUTINE_HANDLE_EXCEPTION import org.jetbrains.kotlin.util.OperatorNameConventions.COROUTINE_HANDLE_RESULT import org.jetbrains.kotlin.util.OperatorNameConventions.COROUTINE_INTERCEPT_RESUME -import org.jetbrains.kotlin.util.OperatorNameConventions.CREATE_DELEGATE +import org.jetbrains.kotlin.util.OperatorNameConventions.TO_DELEGATE_FOR import org.jetbrains.kotlin.util.OperatorNameConventions.DEC import org.jetbrains.kotlin.util.OperatorNameConventions.EQUALS import org.jetbrains.kotlin.util.OperatorNameConventions.GET @@ -186,7 +186,7 @@ object OperatorChecks : AbstractModifierChecks() { }, Checks(GET_VALUE, MemberOrExtension, NoDefaultAndVarargsCheck, ValueParameterCountCheck.AtLeast(2), IsKPropertyCheck), Checks(SET_VALUE, MemberOrExtension, NoDefaultAndVarargsCheck, ValueParameterCountCheck.AtLeast(3), IsKPropertyCheck), - Checks(CREATE_DELEGATE, MemberOrExtension, NoDefaultAndVarargsCheck, ValueParameterCountCheck.Equals(2), IsKPropertyCheck), + Checks(TO_DELEGATE_FOR, MemberOrExtension, NoDefaultAndVarargsCheck, ValueParameterCountCheck.Equals(2), IsKPropertyCheck), Checks(INVOKE, MemberOrExtension), Checks(CONTAINS, MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck, ReturnsBoolean), Checks(ITERATOR, MemberOrExtension, NoValueParameters),