diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java index 5701e1696d5..d1f22e28a67 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor; import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor; import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor; import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor; +import org.jetbrains.kotlin.name.Name; /* package */ class SamAdapterFunctionDescriptor extends JavaMethodDescriptor implements SamAdapterDescriptor { private final JavaMethodDescriptor declaration; @@ -53,7 +54,8 @@ import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor; protected JavaMethodDescriptor createSubstitutedCopy( @NotNull DeclarationDescriptor newOwner, @Nullable FunctionDescriptor original, - @NotNull Kind kind + @NotNull Kind kind, + @Nullable Name newName ) { return new SamAdapterFunctionDescriptor(newOwner, (SimpleFunctionDescriptor) original, kind, declaration); } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt index b3a14a5a814..85d6d0194f0 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt @@ -141,8 +141,15 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc override fun hasStableParameterNames() = sourceFunction.hasStableParameterNames() override fun hasSynthesizedParameterNames() = sourceFunction.hasSynthesizedParameterNames() - override fun createSubstitutedCopy(newOwner: DeclarationDescriptor, original: FunctionDescriptor?, kind: CallableMemberDescriptor.Kind): MyFunctionDescriptor { - return MyFunctionDescriptor(containingDeclaration, original as SimpleFunctionDescriptor?, annotations, name, kind, source).apply { + override fun createSubstitutedCopy( + newOwner: DeclarationDescriptor, + original: FunctionDescriptor?, + kind: CallableMemberDescriptor.Kind, + newName: Name? + ): MyFunctionDescriptor { + return MyFunctionDescriptor( + containingDeclaration, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, source + ).apply { sourceFunction = this@MyFunctionDescriptor.sourceFunction } } @@ -162,13 +169,14 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc kind: CallableMemberDescriptor.Kind, newValueParameterDescriptors: MutableList, newExtensionReceiverParameterType: KotlinType?, - newReturnType: KotlinType + newReturnType: KotlinType, + name: Name? ): FunctionDescriptor? { - val descriptor = super.doSubstitute( + val descriptor = super.doSubstitute( originalSubstitutor, newOwner, newModality, newVisibility, newIsOperator, newIsInfix, newIsExternal, newIsInline, newIsTailrec, original, - copyOverrides, kind, newValueParameterDescriptors, newExtensionReceiverParameterType, newReturnType) - as MyFunctionDescriptor? ?: return null + copyOverrides, kind, newValueParameterDescriptors, newExtensionReceiverParameterType, newReturnType, name) + as MyFunctionDescriptor? ?: return null if (original == null) { throw UnsupportedOperationException("doSubstitute with no original should not be called for synthetic extension") diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaConstructorDescriptor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaConstructorDescriptor.java index 63fdbb95b07..19eba28aa77 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaConstructorDescriptor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaConstructorDescriptor.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl; +import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.types.KotlinType; import java.util.List; @@ -75,7 +76,8 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme protected JavaConstructorDescriptor createSubstitutedCopy( @NotNull DeclarationDescriptor newOwner, @Nullable FunctionDescriptor original, - @NotNull Kind kind + @NotNull Kind kind, + @Nullable Name newName ) { if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) { throw new IllegalStateException( @@ -85,6 +87,9 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme "kind: " + kind ); } + + assert newName == null : "Attempt to rename constructor: " + this; + JavaConstructorDescriptor result = new JavaConstructorDescriptor( (ClassDescriptor) newOwner, this, getAnnotations(), isPrimary, kind, SourceElement.NO_SOURCE ); @@ -100,7 +105,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme @NotNull List enhancedValueParametersTypes, @NotNull KotlinType enhancedReturnType ) { - JavaConstructorDescriptor enhanced = createSubstitutedCopy(getContainingDeclaration(), getOriginal(), getKind()); + JavaConstructorDescriptor enhanced = createSubstitutedCopy(getContainingDeclaration(), getOriginal(), getKind(), null); // We do not use doSubstitute here as in JavaMethodDescriptor.enhance because type parameters of constructor belongs to class enhanced.initialize( enhancedReceiverType, diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java index 79acb46315f..82c9ea28b40 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java @@ -113,13 +113,14 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement protected JavaMethodDescriptor createSubstitutedCopy( @NotNull DeclarationDescriptor newOwner, @Nullable FunctionDescriptor original, - @NotNull Kind kind + @NotNull Kind kind, + @Nullable Name newName ) { JavaMethodDescriptor result = new JavaMethodDescriptor( newOwner, (SimpleFunctionDescriptor) original, getAnnotations(), - getName(), + newName != null ? newName : getName(), kind, original != null ? original.getSource() : SourceElement.NO_SOURCE ); @@ -144,8 +145,8 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement TypeSubstitutor.EMPTY, getContainingDeclaration(), getModality(), getVisibility(), isOperator(), isInfix(), isExternal(), isInline(), isTailrec(), getOriginal(), /* copyOverrides = */ true, getKind(), - enhancedValueParameters, enhancedReceiverType, enhancedReturnType - ); + enhancedValueParameters, enhancedReceiverType, enhancedReturnType, + null); assert enhancedMethod != null : "null after substitution while enhancing " + toString(); return enhancedMethod; diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionInvokeDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionInvokeDescriptor.kt index 051ea6877e5..177034ddd6b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionInvokeDescriptor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionInvokeDescriptor.kt @@ -41,7 +41,8 @@ public class FunctionInvokeDescriptor private constructor( override fun createSubstitutedCopy( newOwner: DeclarationDescriptor, original: FunctionDescriptor?, - kind: CallableMemberDescriptor.Kind + kind: CallableMemberDescriptor.Kind, + newName: Name? ): FunctionInvokeDescriptor { return FunctionInvokeDescriptor(newOwner, original as FunctionInvokeDescriptor?, kind) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/SimpleFunctionDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/SimpleFunctionDescriptor.java index 426c35fc462..62980e439f4 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/SimpleFunctionDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/SimpleFunctionDescriptor.java @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.descriptors; import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.name.Name; /** * Simple functions are the ones with 'fun' keyword and function literals @@ -26,6 +27,9 @@ public interface SimpleFunctionDescriptor extends FunctionDescriptor { @Override SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides); + @NotNull + SimpleFunctionDescriptor createRenamedCopy(@NotNull Name name); + @NotNull @Override SimpleFunctionDescriptor getOriginal(); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ConstructorDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ConstructorDescriptorImpl.java index 19349152458..e1425e8cb99 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ConstructorDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ConstructorDescriptorImpl.java @@ -114,7 +114,8 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements protected ConstructorDescriptorImpl createSubstitutedCopy( @NotNull DeclarationDescriptor newOwner, @Nullable FunctionDescriptor original, - @NotNull Kind kind + @NotNull Kind kind, + @Nullable Name newName ) { if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) { throw new IllegalStateException("Attempt at creating a constructor that is not a declaration: \n" + @@ -123,6 +124,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements "kind: " + kind); } assert original != null : "Attempt to create copy of constructor without preserving original: " + this; + assert newName == null : "Attempt to rename constructor: " + this; return new ConstructorDescriptorImpl( (ClassDescriptor) newOwner, this, diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java index ae4819d35af..b7e31037a95 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java @@ -270,8 +270,8 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo ) { return doSubstitute(originalSubstitutor, newOwner, newModality, newVisibility, isOperator, isInfix, isExternal, isInline, isTailrec, original, copyOverrides, kind, - getValueParameters(), getExtensionReceiverParameterType(), getReturnType() - ); + getValueParameters(), getExtensionReceiverParameterType(), getReturnType(), + null); } @Nullable @@ -282,7 +282,8 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo @Nullable - protected FunctionDescriptor doSubstitute(@NotNull TypeSubstitutor originalSubstitutor, + protected FunctionDescriptor doSubstitute( + @NotNull TypeSubstitutor originalSubstitutor, @NotNull DeclarationDescriptor newOwner, @NotNull Modality newModality, @NotNull Visibility newVisibility, @@ -296,9 +297,10 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo @NotNull Kind kind, @NotNull List newValueParameterDescriptors, @Nullable KotlinType newExtensionReceiverParameterType, - @NotNull KotlinType newReturnType + @NotNull KotlinType newReturnType, + @Nullable Name name ) { - FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, original, kind); + FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, original, kind, name); List originalTypeParameters = getTypeParameters(); List substitutedTypeParameters = new ArrayList(originalTypeParameters.size()); @@ -372,7 +374,8 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo protected abstract FunctionDescriptorImpl createSubstitutedCopy( @NotNull DeclarationDescriptor newOwner, @Nullable FunctionDescriptor original, - @NotNull Kind kind + @NotNull Kind kind, + @Nullable Name newName ); @Override diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ScriptCodeDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ScriptCodeDescriptor.java index 45eb4a0ab40..57828f0b43c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ScriptCodeDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ScriptCodeDescriptor.java @@ -45,7 +45,8 @@ public class ScriptCodeDescriptor extends FunctionDescriptorImpl { protected FunctionDescriptorImpl createSubstitutedCopy( @NotNull DeclarationDescriptor newOwner, @Nullable FunctionDescriptor original, - @NotNull Kind kind + @NotNull Kind kind, + @Nullable Name newName ) { throw new IllegalStateException("no need to copy script code descriptor"); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/SimpleFunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/SimpleFunctionDescriptorImpl.java index 1f64434f911..b2ea73386f5 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/SimpleFunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/SimpleFunctionDescriptorImpl.java @@ -76,14 +76,15 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme protected FunctionDescriptorImpl createSubstitutedCopy( @NotNull DeclarationDescriptor newOwner, @Nullable FunctionDescriptor original, - @NotNull Kind kind + @NotNull Kind kind, + @Nullable Name newName ) { return new SimpleFunctionDescriptorImpl( newOwner, (SimpleFunctionDescriptor) original, // TODO : safeSubstitute getAnnotations(), - getName(), + newName != null ? newName : getName(), kind, SourceElement.NO_SOURCE ); @@ -104,4 +105,14 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme null, copyOverrides, kind ); } + + @NotNull + @Override + public SimpleFunctionDescriptor createRenamedCopy(@NotNull Name name) { + return (SimpleFunctionDescriptorImpl) doSubstitute( + TypeSubstitutor.EMPTY, getContainingDeclaration(), getModality(), getVisibility(), + isOperator(), isInfix(), isExternal(), isInline(), isTailrec(), + null, /* copyOverrides = */ true, getKind(), getValueParameters(), getExtensionReceiverParameterType(), getReturnType(), name + ); + } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java index b2ada2d3c41..be659d3fb3c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java @@ -40,7 +40,8 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI protected FunctionDescriptorImpl createSubstitutedCopy( @NotNull DeclarationDescriptor newOwner, @Nullable FunctionDescriptor original, - @NotNull Kind kind + @NotNull Kind kind, + @Nullable Name newName ) { return this; } @@ -51,6 +52,12 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI return this; } + @NotNull + @Override + public SimpleFunctionDescriptor createRenamedCopy(@NotNull Name name) { + return this; + } + @Override public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overriddenFunction) { // nop diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedConstructorDescriptor.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedConstructorDescriptor.kt index aef1ca5689e..16c0bc7e36f 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedConstructorDescriptor.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedConstructorDescriptor.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.serialization.deserialization.descriptors import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.deserialization.NameResolver import org.jetbrains.kotlin.serialization.deserialization.TypeTable @@ -38,7 +39,8 @@ public class DeserializedConstructorDescriptor( override fun createSubstitutedCopy( newOwner: DeclarationDescriptor, original: FunctionDescriptor?, - kind: CallableMemberDescriptor.Kind + kind: CallableMemberDescriptor.Kind, + newName: Name? ): DeserializedConstructorDescriptor { return DeserializedConstructorDescriptor( newOwner as ClassDescriptor, original as ConstructorDescriptor?, diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedSimpleFunctionDescriptor.java b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedSimpleFunctionDescriptor.java index cdcaf5a4d05..be11d06c2cb 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedSimpleFunctionDescriptor.java +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedSimpleFunctionDescriptor.java @@ -59,13 +59,14 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript protected FunctionDescriptorImpl createSubstitutedCopy( @NotNull DeclarationDescriptor newOwner, @Nullable FunctionDescriptor original, - @NotNull Kind kind + @NotNull Kind kind, + @Nullable Name newName ) { return new DeserializedSimpleFunctionDescriptor( newOwner, (DeserializedSimpleFunctionDescriptor) original, getAnnotations(), - getName(), + newName != null ? newName : getName(), kind, proto, nameResolver,