Rename: this object, receiver argument -> dispatch receiver, extension receiver

This commit is contained in:
Svetlana Isakova
2014-09-29 21:09:07 +04:00
parent 1d2d2f4845
commit 20f3403c80
185 changed files with 681 additions and 687 deletions
@@ -237,8 +237,8 @@ public class LazyJavaClassMemberScope(
}
}
override fun getExpectedThisObject(): ReceiverParameterDescriptor? =
DescriptorUtils.getExpectedThisObjectIfNeeded(getContainingDeclaration())
override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? =
DescriptorUtils.getDispatchReceiverParameterIfNeeded(getContainingDeclaration())
override fun getClassifier(name: Name): ClassifierDescriptor? = nestedClasses(name)
override fun getAllClassNames(): Collection<Name> = nestedClassIndex().keySet() + enumEntryIndex().keySet()
@@ -69,7 +69,7 @@ public abstract class LazyJavaMemberScope(
protected abstract fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name)
protected abstract fun getExpectedThisObject(): ReceiverParameterDescriptor?
protected abstract fun getDispatchReceiverParameter(): ReceiverParameterDescriptor?
protected abstract fun computeAdditionalFunctions(name: Name): Collection<SimpleFunctionDescriptor>
@@ -140,7 +140,7 @@ public abstract class LazyJavaMemberScope(
functionDescriptorImpl.initialize(
effectiveSignature.getReceiverType(),
getExpectedThisObject(),
getDispatchReceiverParameter(),
effectiveSignature.getTypeParameters(),
effectiveSignature.getValueParameters(),
effectiveSignature.getReturnType(),
@@ -258,7 +258,7 @@ public abstract class LazyJavaMemberScope(
c.externalSignatureResolver.reportSignatureErrors(propertyDescriptor, signatureErrors)
}
propertyDescriptor.setType(effectiveSignature.getReturnType(), listOf(), getExpectedThisObject(), null : JetType?)
propertyDescriptor.setType(effectiveSignature.getReturnType(), listOf(), getDispatchReceiverParameter(), null : JetType?)
if (DescriptorUtils.shouldRecordInitializerForProperty(propertyDescriptor, propertyDescriptor.getType())) {
propertyDescriptor.setCompileTimeInitializer(
@@ -40,7 +40,7 @@ public abstract class LazyJavaStaticScope(
descriptor: ClassOrPackageFragmentDescriptor
) : LazyJavaMemberScope(c.withTypes(), descriptor) {
override fun getExpectedThisObject() = null
override fun getDispatchReceiverParameter() = null
// Package fragments are not nested
override fun getPackage(name: Name) = null
@@ -189,7 +189,7 @@ public class SingleAbstractMethodUtils {
) {
result.initialize(
null,
original.getExpectedThisObject(),
original.getDispatchReceiverParameter(),
typeParameters,
valueParameters,
returnType,
@@ -27,10 +27,10 @@ import java.util.Set;
public interface CallableDescriptor extends DeclarationDescriptorWithVisibility, DeclarationDescriptorNonRoot {
@Nullable
ReceiverParameterDescriptor getReceiverParameter();
ReceiverParameterDescriptor getExtensionReceiverParameter();
@Nullable
ReceiverParameterDescriptor getExpectedThisObject();
ReceiverParameterDescriptor getDispatchReceiverParameter();
@KotlinSignature("fun getTypeParameters(): List<TypeParameterDescriptor>")
@NotNull
@@ -54,13 +54,13 @@ public abstract class AbstractReceiverParameterDescriptor extends DeclarationDes
@Nullable
@Override
public ReceiverParameterDescriptor getReceiverParameter() {
public ReceiverParameterDescriptor getExtensionReceiverParameter() {
return null;
}
@Nullable
@Override
public ReceiverParameterDescriptor getExpectedThisObject() {
public ReceiverParameterDescriptor getDispatchReceiverParameter() {
return null;
}
@@ -61,12 +61,12 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
@NotNull Visibility visibility
) {
super.initialize(null, calculateExpectedThisObject(), typeParameters, unsubstitutedValueParameters, null, Modality.FINAL, visibility);
super.initialize(null, calculateDispatchReceiverParameter(), typeParameters, unsubstitutedValueParameters, null, Modality.FINAL, visibility);
return this;
}
@Nullable
private ReceiverParameterDescriptor calculateExpectedThisObject() {
private ReceiverParameterDescriptor calculateDispatchReceiverParameter() {
ClassDescriptor classDescriptor = getContainingDeclaration();
if (classDescriptor.isInner()) {
DeclarationDescriptor classContainer = classDescriptor.getContainingDeclaration();
@@ -37,8 +37,8 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
private List<TypeParameterDescriptor> typeParameters;
private List<ValueParameterDescriptor> unsubstitutedValueParameters;
private JetType unsubstitutedReturnType;
private ReceiverParameterDescriptor receiverParameter;
private ReceiverParameterDescriptor expectedThisObject;
private ReceiverParameterDescriptor extensionReceiverParameter;
private ReceiverParameterDescriptor dispatchReceiverParameter;
private Modality modality;
private Visibility visibility;
private final Set<FunctionDescriptor> overriddenFunctions = new LinkedHashSet<FunctionDescriptor>(); // LinkedHashSet is essential here
@@ -61,7 +61,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
@NotNull
public FunctionDescriptorImpl initialize(
@Nullable JetType receiverParameterType,
@Nullable ReceiverParameterDescriptor expectedThisObject,
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
@Nullable JetType unsubstitutedReturnType,
@@ -73,8 +73,8 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
this.unsubstitutedReturnType = unsubstitutedReturnType;
this.modality = modality;
this.visibility = visibility;
this.receiverParameter = DescriptorFactory.createReceiverParameterForCallable(this, receiverParameterType);
this.expectedThisObject = expectedThisObject;
this.extensionReceiverParameter = DescriptorFactory.createExtensionReceiverParameterForCallable(this, receiverParameterType);
this.dispatchReceiverParameter = dispatchReceiverParameter;
for (int i = 0; i < typeParameters.size(); ++i) {
TypeParameterDescriptor typeParameterDescriptor = typeParameters.get(i);
@@ -109,14 +109,14 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
@Nullable
@Override
public ReceiverParameterDescriptor getReceiverParameter() {
return receiverParameter;
public ReceiverParameterDescriptor getExtensionReceiverParameter() {
return extensionReceiverParameter;
}
@Nullable
@Override
public ReceiverParameterDescriptor getExpectedThisObject() {
return expectedThisObject;
public ReceiverParameterDescriptor getDispatchReceiverParameter() {
return dispatchReceiverParameter;
}
@NotNull
@@ -207,16 +207,16 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
);
JetType substitutedReceiverParameterType = null;
if (receiverParameter != null) {
substitutedReceiverParameterType = substitutor.substitute(getReceiverParameter().getType(), Variance.IN_VARIANCE);
if (extensionReceiverParameter != null) {
substitutedReceiverParameterType = substitutor.substitute(getExtensionReceiverParameter().getType(), Variance.IN_VARIANCE);
if (substitutedReceiverParameterType == null) {
return null;
}
}
ReceiverParameterDescriptor substitutedExpectedThis = null;
if (expectedThisObject != null) {
substitutedExpectedThis = expectedThisObject.substitute(substitutor);
if (dispatchReceiverParameter != null) {
substitutedExpectedThis = dispatchReceiverParameter.substitute(substitutor);
if (substitutedExpectedThis == null) {
return null;
}
@@ -119,14 +119,14 @@ public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescript
@Nullable
@Override
public ReceiverParameterDescriptor getReceiverParameter() {
return getCorrespondingProperty().getReceiverParameter();
public ReceiverParameterDescriptor getExtensionReceiverParameter() {
return getCorrespondingProperty().getExtensionReceiverParameter();
}
@Nullable
@Override
public ReceiverParameterDescriptor getExpectedThisObject() {
return getCorrespondingProperty().getExpectedThisObject();
public ReceiverParameterDescriptor getDispatchReceiverParameter() {
return getCorrespondingProperty().getDispatchReceiverParameter();
}
@NotNull
@@ -39,8 +39,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
private final PropertyDescriptor original;
private final Kind kind;
private ReceiverParameterDescriptor expectedThisObject;
private ReceiverParameterDescriptor receiverParameter;
private ReceiverParameterDescriptor dispatchReceiverParameter;
private ReceiverParameterDescriptor extensionReceiverParameter;
private List<TypeParameterDescriptor> typeParameters;
private PropertyGetterDescriptorImpl getter;
private PropertySetterDescriptor setter;
@@ -82,25 +82,25 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
public void setType(
@NotNull JetType outType,
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
@Nullable ReceiverParameterDescriptor expectedThisObject,
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
@Nullable JetType receiverType
) {
ReceiverParameterDescriptor receiverParameter = DescriptorFactory.createReceiverParameterForCallable(this, receiverType);
setType(outType, typeParameters, expectedThisObject, receiverParameter);
ReceiverParameterDescriptor extensionReceiverParameter = DescriptorFactory.createExtensionReceiverParameterForCallable(this, receiverType);
setType(outType, typeParameters, dispatchReceiverParameter, extensionReceiverParameter);
}
public void setType(
@NotNull JetType outType,
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
@Nullable ReceiverParameterDescriptor expectedThisObject,
@Nullable ReceiverParameterDescriptor receiverParameter
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
@Nullable ReceiverParameterDescriptor extensionReceiverParameter
) {
setOutType(outType);
this.typeParameters = new ArrayList<TypeParameterDescriptor>(typeParameters);
this.receiverParameter = receiverParameter;
this.expectedThisObject = expectedThisObject;
this.extensionReceiverParameter = extensionReceiverParameter;
this.dispatchReceiverParameter = dispatchReceiverParameter;
}
public void initialize(@Nullable PropertyGetterDescriptorImpl getter, @Nullable PropertySetterDescriptor setter) {
@@ -124,14 +124,14 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
@Override
@Nullable
public ReceiverParameterDescriptor getReceiverParameter() {
return receiverParameter;
public ReceiverParameterDescriptor getExtensionReceiverParameter() {
return extensionReceiverParameter;
}
@Nullable
@Override
public ReceiverParameterDescriptor getExpectedThisObject() {
return expectedThisObject;
public ReceiverParameterDescriptor getDispatchReceiverParameter() {
return dispatchReceiverParameter;
}
@NotNull
@@ -220,26 +220,26 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
}
ReceiverParameterDescriptor substitutedExpectedThisObject;
ReceiverParameterDescriptor expectedThisObject = getExpectedThisObject();
if (expectedThisObject != null) {
substitutedExpectedThisObject = expectedThisObject.substitute(substitutor);
if (substitutedExpectedThisObject == null) return null;
ReceiverParameterDescriptor substitutedDispatchReceiver;
ReceiverParameterDescriptor dispatchReceiver = getDispatchReceiverParameter();
if (dispatchReceiver != null) {
substitutedDispatchReceiver = dispatchReceiver.substitute(substitutor);
if (substitutedDispatchReceiver == null) return null;
}
else {
substitutedExpectedThisObject = null;
substitutedDispatchReceiver = null;
}
JetType substitutedReceiverType;
if (receiverParameter != null) {
substitutedReceiverType = substitutor.substitute(receiverParameter.getType(), Variance.IN_VARIANCE);
if (extensionReceiverParameter != null) {
substitutedReceiverType = substitutor.substitute(extensionReceiverParameter.getType(), Variance.IN_VARIANCE);
if (substitutedReceiverType == null) return null;
}
else {
substitutedReceiverType = null;
}
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedExpectedThisObject, substitutedReceiverType);
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedDispatchReceiver, substitutedReceiverType);
PropertyGetterDescriptorImpl newGetter = getter == null ? null : new PropertyGetterDescriptorImpl(
substitutedDescriptor, getter.getAnnotations(), newModality, convertVisibility(getter.getVisibility(), newVisibility),
@@ -33,10 +33,10 @@ public class ScriptCodeDescriptor extends FunctionDescriptorImpl {
}
public void initialize(
@NotNull ReceiverParameterDescriptor expectedThisObject,
@NotNull ReceiverParameterDescriptor dispatchReceiverParameter,
@NotNull List<ValueParameterDescriptor> valueParameters,
@NotNull JetType returnType) {
super.initialize(null, expectedThisObject, Collections.<TypeParameterDescriptor>emptyList(), valueParameters, returnType, Modality.FINAL, Visibilities.INTERNAL);
super.initialize(null, dispatchReceiverParameter, Collections.<TypeParameterDescriptor>emptyList(), valueParameters, returnType, Modality.FINAL, Visibilities.INTERNAL);
}
@NotNull
@@ -59,14 +59,14 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
@Override
public SimpleFunctionDescriptorImpl initialize(
@Nullable JetType receiverParameterType,
@Nullable ReceiverParameterDescriptor expectedThisObject,
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
@Nullable JetType unsubstitutedReturnType,
@Nullable Modality modality,
@NotNull Visibility visibility
) {
super.initialize(receiverParameterType, expectedThisObject, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType,
super.initialize(receiverParameterType, dispatchReceiverParameter, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType,
modality, visibility);
this.inlineStrategy = InlineUtil.getInlineType(this);
return this;
@@ -105,12 +105,12 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorNonRoo
}
@Override
public ReceiverParameterDescriptor getReceiverParameter() {
public ReceiverParameterDescriptor getExtensionReceiverParameter() {
return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
}
@Override
public ReceiverParameterDescriptor getExpectedThisObject() {
public ReceiverParameterDescriptor getDispatchReceiverParameter() {
return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
}
@@ -108,7 +108,7 @@ public class DescriptorFactory {
}
@Nullable
public static ReceiverParameterDescriptor createReceiverParameterForCallable(
public static ReceiverParameterDescriptor createExtensionReceiverParameterForCallable(
@NotNull CallableDescriptor owner,
@Nullable JetType receiverParameterType
) {
@@ -48,7 +48,7 @@ public class DescriptorUtils {
}
@Nullable
public static ReceiverParameterDescriptor getExpectedThisObjectIfNeeded(@NotNull DeclarationDescriptor containingDeclaration) {
public static ReceiverParameterDescriptor getDispatchReceiverParameterIfNeeded(@NotNull DeclarationDescriptor containingDeclaration) {
if (containingDeclaration instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
return classDescriptor.getThisAsReceiverParameter();
@@ -139,7 +139,7 @@ public class DescriptorUtils {
DeclarationDescriptor container = descriptor.getContainingDeclaration();
return container instanceof PackageFragmentDescriptor ||
(container instanceof ClassDescriptor && descriptor.getExpectedThisObject() == null);
(container instanceof ClassDescriptor && descriptor.getDispatchReceiverParameter() == null);
}
// WARNING! Don't use this method in JVM backend, use JvmCodegenUtil.isCallInsideSameModuleAsDeclared() instead.
@@ -31,4 +31,4 @@ public fun DeclarationDescriptor.getImportableDescriptor(): DeclarationDescripto
if (this is ConstructorDescriptor || DescriptorUtils.isClassObject(this)) getContainingDeclaration()!! else this
public val DeclarationDescriptor.isExtension: Boolean
get() = this is CallableDescriptor && getReceiverParameter() != null
get() = this is CallableDescriptor && getExtensionReceiverParameter() != null
@@ -182,7 +182,7 @@ public class OverridingUtil {
CallableDescriptor superDescriptor,
CallableDescriptor subDescriptor
) {
if ((superDescriptor.getReceiverParameter() == null) != (subDescriptor.getReceiverParameter() == null)) {
if ((superDescriptor.getExtensionReceiverParameter() == null) != (subDescriptor.getExtensionReceiverParameter() == null)) {
return OverrideCompatibilityInfo.receiverPresenceMismatch();
}
@@ -206,7 +206,7 @@ public class OverridingUtil {
}
static List<JetType> compiledValueParameters(CallableDescriptor callableDescriptor) {
ReceiverParameterDescriptor receiverParameter = callableDescriptor.getReceiverParameter();
ReceiverParameterDescriptor receiverParameter = callableDescriptor.getExtensionReceiverParameter();
ArrayList<JetType> parameters = new ArrayList<JetType>();
if (receiverParameter != null) {
parameters.add(receiverParameter.getType());
@@ -50,7 +50,7 @@ public class ErrorUtils {
if (containsErrorType(function.getReturnType())) {
return true;
}
ReceiverParameterDescriptor receiverParameter = function.getReceiverParameter();
ReceiverParameterDescriptor receiverParameter = function.getExtensionReceiverParameter();
if (receiverParameter != null && containsErrorType(receiverParameter.getType())) {
return true;
}
@@ -654,14 +654,14 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
private void renderReceiverAfterName(CallableDescriptor callableDescriptor, StringBuilder builder) {
if (!receiverAfterName) return;
ReceiverParameterDescriptor receiver = callableDescriptor.getReceiverParameter();
ReceiverParameterDescriptor receiver = callableDescriptor.getExtensionReceiverParameter();
if (receiver != null) {
builder.append(" on ").append(escape(renderType(receiver.getType())));
}
}
private void renderReceiver(CallableDescriptor callableDescriptor, StringBuilder builder) {
ReceiverParameterDescriptor receiver = callableDescriptor.getReceiverParameter();
ReceiverParameterDescriptor receiver = callableDescriptor.getExtensionReceiverParameter();
if (receiver != null) {
builder.append(escape(renderType(receiver.getType()))).append(".");
}
@@ -214,7 +214,7 @@ public class DescriptorSerializer {
builder.addTypeParameter(local.typeParameter(typeParameterDescriptor));
}
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();
if (receiverParameter != null) {
builder.setReceiverType(local.type(receiverParameter.getType()));
}
@@ -83,7 +83,7 @@ public class MemberDeserializer {
property.setType(
local.getTypeDeserializer().type(proto.getReturnType()),
typeParameters,
getExpectedThisObject(),
getDispatchReceiverParameter(),
local.getTypeDeserializer().typeOrNull(proto.hasReceiverType() ? proto.getReceiverType() : null)
);
@@ -161,7 +161,7 @@ public class MemberDeserializer {
DeserializationContextWithTypes local = context.childContext(function, proto.getTypeParameterList(), typeParameters);
function.initialize(
local.getTypeDeserializer().typeOrNull(proto.hasReceiverType() ? proto.getReceiverType() : null),
getExpectedThisObject(),
getDispatchReceiverParameter(),
typeParameters,
local.getDeserializer().valueParameters(proto, AnnotatedCallableKind.FUNCTION),
local.getTypeDeserializer().type(proto.getReturnType()),
@@ -172,7 +172,7 @@ public class MemberDeserializer {
}
@Nullable
private ReceiverParameterDescriptor getExpectedThisObject() {
private ReceiverParameterDescriptor getDispatchReceiverParameter() {
DeclarationDescriptor containingDeclaration = context.getContainingDeclaration();
return containingDeclaration instanceof ClassDescriptor
? ((ClassDescriptor) containingDeclaration).getThisAsReceiverParameter() : null;