Introduce and implement SimpleFunctionDescriptor.createRenamedCopy

This commit is contained in:
Denis Zharkov
2015-10-23 11:22:11 +03:00
parent 69038063a6
commit ce34550c42
13 changed files with 76 additions and 28 deletions
@@ -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<KotlinType> 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,
@@ -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;