Drop 'propertyDelegated' convention (without additional deprecation ceremony).

This commit is contained in:
Dmitry Petrov
2016-12-06 15:35:23 +03:00
committed by Stanislav Erokhin
parent 5ddf8e60e6
commit e2b6d2d849
25 changed files with 8 additions and 300 deletions
@@ -4086,7 +4086,6 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
if (isDelegatedLocalVariable(variableDescriptor)) {
StackValue metadataValue = getVariableMetadataValue(variableDescriptor);
initializePropertyMetadata((KtProperty) variableDeclaration, variableDescriptor, metadataValue);
invokePropertyDelegatedOnLocalVar(variableDescriptor, storeTo, metadataValue);
}
}
@@ -4097,19 +4096,6 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
return descriptor;
}
private void invokePropertyDelegatedOnLocalVar(
@NotNull LocalVariableDescriptor variableDescriptor,
@NotNull StackValue delegateValue,
@NotNull StackValue metadataValue
) {
ResolvedCall<FunctionDescriptor> pdResolvedCall =
bindingContext.get(BindingContext.DELEGATED_PROPERTY_PD_RESOLVED_CALL, variableDescriptor);
if (pdResolvedCall == null) return;
tempVariables.put(pdResolvedCall.getCall().getValueArguments().get(0).asElement(), metadataValue);
invokeFunction(pdResolvedCall, delegateValue).put(Type.VOID_TYPE, v);
}
private void initializePropertyMetadata(
@NotNull KtProperty variable,
@NotNull LocalVariableDescriptor variableDescriptor,
@@ -118,9 +118,9 @@ public class DebugInfoUtil {
VariableDescriptor descriptor = bindingContext.get(VARIABLE, property);
if (descriptor instanceof PropertyDescriptor && property.getDelegate() != null) {
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
reportIfDynamicCall(property.getDelegate(), propertyDescriptor, TO_DELEGATE_FOR_RESOLVED_CALL);
reportIfDynamicCall(property.getDelegate(), propertyDescriptor.getGetter(), DELEGATED_PROPERTY_RESOLVED_CALL);
reportIfDynamicCall(property.getDelegate(), propertyDescriptor.getSetter(), DELEGATED_PROPERTY_RESOLVED_CALL);
reportIfDynamicCall(property.getDelegate(), propertyDescriptor, DELEGATED_PROPERTY_PD_RESOLVED_CALL);
}
super.visitProperty(property);
}
@@ -144,8 +144,6 @@ public interface BindingContext {
WritableSlice<VariableDescriptorWithAccessors, ResolvedCall<FunctionDescriptor>> TO_DELEGATE_FOR_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice<VariableDescriptorWithAccessors, Call> TO_DELEGATE_FOR_CALL = Slices.createSimpleSlice();
WritableSlice<VariableDescriptorWithAccessors, ResolvedCall<FunctionDescriptor>> DELEGATED_PROPERTY_PD_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice<KtDestructuringDeclarationEntry, ResolvedCall<FunctionDescriptor>> COMPONENT_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice<KtExpression, ResolvedCall<FunctionDescriptor>> INDEXED_LVALUE_GET = Slices.createSimpleSlice();
@@ -72,17 +72,10 @@ class DelegatedPropertyResolver(
if (setter.hasBody()) trace.report(ACCESSOR_FOR_DELEGATED_PROPERTY.on(setter))
}
val delegateFunctionsScope: LexicalScope
val initializerScope: LexicalScope
if (variableDescriptor is PropertyDescriptor) {
delegateFunctionsScope = ScopeUtils.makeScopeForDelegateConventionFunctions(propertyHeaderScope, variableDescriptor)
initializerScope = ScopeUtils.makeScopeForPropertyInitializer(propertyHeaderScope, variableDescriptor)
}
else {
initializerScope = propertyHeaderScope
delegateFunctionsScope = initializerScope
}
val initializerScope: LexicalScope =
if (variableDescriptor is PropertyDescriptor)
ScopeUtils.makeScopeForPropertyInitializer(propertyHeaderScope, variableDescriptor)
else propertyHeaderScope
val byExpressionType = resolveDelegateExpression(delegateExpression, property, variableDescriptor, initializerScope, trace, outerDataFlowInfo)
@@ -93,8 +86,6 @@ class DelegatedPropertyResolver(
if (property.isVar) {
resolveSetValueMethod(variableDescriptor, delegateExpression, delegateType, trace, initializerScope, outerDataFlowInfo)
}
resolvePropertyDelegatedMethod(variableDescriptor, delegateExpression, delegateType, trace, delegateFunctionsScope, outerDataFlowInfo)
}
private fun getResolvedDelegateType(
@@ -166,42 +157,6 @@ class DelegatedPropertyResolver(
return createExpression("null as ${KotlinBuiltIns.FQ_NAMES.kProperty.asSingleFqName().asString()}<*>")
}
private fun resolvePropertyDelegatedMethod(
variableDescriptor: VariableDescriptorWithAccessors,
delegateExpression: KtExpression,
delegateType: KotlinType,
trace: BindingTrace,
delegateFunctionsScope: LexicalScope,
dataFlowInfo: DataFlowInfo
) {
val traceToResolvePDMethod = TemporaryBindingTrace.create(trace, "Trace to resolve propertyDelegated method in delegated property")
val context = ExpressionTypingContext.newContext(traceToResolvePDMethod, delegateFunctionsScope, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE)
val psiFactory = KtPsiFactory(delegateExpression)
val arguments = listOf(psiFactory.createExpressionForProperty())
val receiver = ExpressionReceiver.create(delegateExpression, delegateType, trace.bindingContext)
val resolutionResult = fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments,
OperatorNameConventions.PROPERTY_DELEGATED, delegateExpression)
val call = resolutionResult.first
val functionResults = resolutionResult.second
if (!functionResults.isSuccess) {
val expectedFunction = renderCall(call, traceToResolvePDMethod.bindingContext)
if (functionResults.isIncomplete || functionResults.isSingleResult ||
functionResults.resultCode == OverloadResolutionResults.Code.MANY_FAILED_CANDIDATES) {
trace.report(DELEGATE_PD_METHOD_NONE_APPLICABLE.on(delegateExpression, expectedFunction, functionResults.resultingCalls))
}
else if (functionResults.isAmbiguity) {
trace.report(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY.on(delegateExpression, expectedFunction, functionResults.resultingCalls))
}
return
}
trace.record(DELEGATED_PROPERTY_PD_RESOLVED_CALL, variableDescriptor, functionResults.resultingCall)
}
/* Resolve getValue() or setValue() methods from delegate */
private fun resolveGetSetValueMethod(
propertyDescriptor: VariableDescriptorWithAccessors,
@@ -1,15 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a: Int by <!DELEGATE_SPECIAL_FUNCTION_AMBIGUITY!>Delegate()<!>
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
fun propertyDelegated(p: KProperty<*>, i: Int = 1) {}
fun propertyDelegated(p: KProperty<*>, s: String = "") {}
}
@@ -1,13 +0,0 @@
package
public val a: kotlin.Int
public final class Delegate {
public constructor Delegate()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun getValue(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun propertyDelegated(/*0*/ p: kotlin.reflect.KProperty<*>, /*1*/ i: kotlin.Int = ...): kotlin.Unit
public final fun propertyDelegated(/*0*/ p: kotlin.reflect.KProperty<*>, /*1*/ s: kotlin.String = ...): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,13 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a: Int by <!DELEGATE_PD_METHOD_NONE_APPLICABLE!>Delegate()<!>
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
fun <T> propertyDelegated(p: KProperty<*>) {}
}
@@ -1,12 +0,0 @@
package
public val a: kotlin.Int
public final class Delegate {
public constructor Delegate()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun getValue(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun </*0*/ T> propertyDelegated(/*0*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,11 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a: Int by Delegate()
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -1,11 +0,0 @@
package
public val a: kotlin.Int
public final class Delegate {
public constructor Delegate()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun getValue(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,13 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a: Int by <!DELEGATE_PD_METHOD_NONE_APPLICABLE!>Delegate()<!>
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
private fun propertyDelegated(p: KProperty<*>) {}
}
@@ -1,12 +0,0 @@
package
public val a: kotlin.Int
public final class Delegate {
public constructor Delegate()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun getValue(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
private final fun propertyDelegated(/*0*/ p: kotlin.reflect.KProperty<*>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,19 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a: Int by <!DELEGATE_PD_METHOD_NONE_APPLICABLE!>Delegate()<!>
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
fun propertyDelegated() {}
fun propertyDelegated(a: Int) {}
fun propertyDelegated(a: String) {}
fun propertyDelegated(p: KProperty<*>, a: Int) {}
}
@@ -1,15 +0,0 @@
package
public val a: kotlin.Int
public final class Delegate {
public constructor Delegate()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun getValue(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun propertyDelegated(): kotlin.Unit
public final fun propertyDelegated(/*0*/ a: kotlin.Int): kotlin.Unit
public final fun propertyDelegated(/*0*/ a: kotlin.String): kotlin.Unit
public final fun propertyDelegated(/*0*/ p: kotlin.reflect.KProperty<*>, /*1*/ a: kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -60,7 +60,5 @@ public final fun divAssign(/*0*/ p0: dynamic): dynamic
public final fun get(/*0*/ p0: dynamic): dynamic
public final fun remAssign(/*0*/ p0: dynamic): dynamic
public final fun getValue(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic
public final fun propertyDelegated(/*0*/ p0: dynamic): dynamic
public final fun getValue(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic
public final fun setValue(/*0*/ p0: dynamic, /*1*/ p1: dynamic, /*2*/ p2: dynamic): dynamic
public final fun propertyDelegated(/*0*/ p0: dynamic): dynamic
@@ -89,5 +89,5 @@ fun test(d: dynamic) {
}
val dyn: dynamic = null
val foo : Int <!DEBUG_INFO_DYNAMIC, DEBUG_INFO_DYNAMIC!>by dyn<!>
var bar : Int <!DEBUG_INFO_DYNAMIC, DEBUG_INFO_DYNAMIC, DEBUG_INFO_DYNAMIC!>by dyn<!>
val foo : Int <!DEBUG_INFO_DYNAMIC!>by dyn<!>
var bar : Int <!DEBUG_INFO_DYNAMIC, DEBUG_INFO_DYNAMIC!>by dyn<!>
@@ -5620,36 +5620,6 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("propertyDelegatedAmbiguity.kt")
public void testPropertyDelegatedAmbiguity() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/propertyDelegatedAmbiguity.kt");
doTest(fileName);
}
@TestMetadata("propertyDelegatedIncomplete.kt")
public void testPropertyDelegatedIncomplete() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/propertyDelegatedIncomplete.kt");
doTest(fileName);
}
@TestMetadata("propertyDelegatedMissing.kt")
public void testPropertyDelegatedMissing() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/propertyDelegatedMissing.kt");
doTest(fileName);
}
@TestMetadata("propertyDelegatedPrivate.kt")
public void testPropertyDelegatedPrivate() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/propertyDelegatedPrivate.kt");
doTest(fileName);
}
@TestMetadata("propertyDelegatedWrongArguments.kt")
public void testPropertyDelegatedWrongArguments() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/propertyDelegatedWrongArguments.kt");
doTest(fileName);
}
@TestMetadata("recursiveType.kt")
public void testRecursiveType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.kt");
@@ -40,7 +40,7 @@ class KtPropertyDelegationMethodsReference(element: KtPropertyDelegate) : KtMult
return (descriptor.accessors.mapNotNull {
accessor ->
context.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, accessor)?.candidateDescriptor
} + listOfNotNull(context.get(BindingContext.DELEGATED_PROPERTY_PD_RESOLVED_CALL, descriptor)?.candidateDescriptor))
} + listOfNotNull(context.get(BindingContext.TO_DELEGATE_FOR_RESOLVED_CALL, descriptor)?.candidateDescriptor))
}
override val resolvesByNames: Collection<Name> get() = NAMES
@@ -1,16 +0,0 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: usages
import kotlin.reflect.KProperty
class Delegate() {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String = ":)"
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
}
operator fun <caret>propertyDelegated(property: KProperty<*>) {
}
}
var p: String by Delegate()
@@ -1,4 +0,0 @@
Resolved by Delegate()
Searched references to Delegate
Used plain search of Delegate.propertyDelegated(property: KProperty<*>) in LocalSearchScope:
CLASS:Delegate
@@ -1 +0,0 @@
Property delegation 16 var p: String by Delegate()
@@ -1,13 +0,0 @@
var x: Int <caret>by Foo()
class Foo
fun Foo.getValue(_this: Any?, p: Any?): Int = 1
fun Foo.setValue(_this: Any?, p: Any?, val: Any?) {}
fun Foo.propertyDelegated(p: Any?) {}
// MULTIRESOLVE
// REF: (for Foo in <root>).getValue(Any?, Any?)
// REF: (for Foo in <root>).setValue(Any?, Any?, Any?)
// REF: (for Foo in <root>).propertyDelegated(Any?)
@@ -1,13 +0,0 @@
var x: Int <caret>by Foo()
class Foo {
fun getValue(_this: Any?, p: Any?): Int = 1
fun setValue(_this: Any?, p: Any?, val: Any?) {}
fun propertyDelegated(p: Any?)
}
// MULTIRESOLVE
// REF: (in Foo).getValue(Any?, Any?)
// REF: (in Foo).setValue(Any?, Any?, Any?)
// REF: (in Foo).propertyDelegated(Any?)
@@ -145,12 +145,6 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
doTest(fileName);
}
@TestMetadata("propertyDelegatedFunction.0.kt")
public void testPropertyDelegatedFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/propertyDelegatedFunction.0.kt");
doTest(fileName);
}
@TestMetadata("set.0.kt")
public void testSet() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/set.0.kt");
@@ -519,18 +519,6 @@ public class ReferenceResolveTestGenerated extends AbstractReferenceResolveTest
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/resolve/references/delegatedPropertyAccessors/inSource/getOneFakeOverride.kt");
doTest(fileName);
}
@TestMetadata("getSetPropertyDelegatedExtension.kt")
public void testGetSetPropertyDelegatedExtension() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/resolve/references/delegatedPropertyAccessors/inSource/getSetPropertyDelegatedExtension.kt");
doTest(fileName);
}
@TestMetadata("getSetPropertyDelegatedMember.kt")
public void testGetSetPropertyDelegatedMember() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/resolve/references/delegatedPropertyAccessors/inSource/getSetPropertyDelegatedMember.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/resolve/references/delegatedPropertyAccessors/inStandardLibrary")