Release original Java descriptors while enhancing

It's both more correct and helps to release memory retained by
descriptor before enhancement
This commit is contained in:
Denis Zharkov
2016-02-01 17:24:12 +03:00
parent beea2d5d10
commit 924d706e79
8 changed files with 80 additions and 25 deletions
@@ -91,14 +91,26 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
assert newName == null : "Attempt to rename constructor: " + this;
JavaConstructorDescriptor result = new JavaConstructorDescriptor(
(ClassDescriptor) newOwner, this, getAnnotations(), isPrimary, kind, getSourceToUseForCopy(preserveSource, original)
);
JavaConstructorDescriptor result = createDescriptor((ClassDescriptor) newOwner, (JavaConstructorDescriptor) original, kind,
getSourceToUseForCopy(preserveSource, original));
result.setHasStableParameterNames(hasStableParameterNames());
result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
return result;
}
@NotNull
protected JavaConstructorDescriptor createDescriptor(
@NotNull ClassDescriptor newOwner,
@Nullable JavaConstructorDescriptor original,
@NotNull Kind kind,
@NotNull SourceElement sourceElement
) {
return new JavaConstructorDescriptor(
newOwner, original, getAnnotations(), isPrimary, kind,
sourceElement
);
}
@Override
@NotNull
public JavaConstructorDescriptor enhance(
@@ -106,7 +118,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
@NotNull List<KotlinType> enhancedValueParametersTypes,
@NotNull KotlinType enhancedReturnType
) {
JavaConstructorDescriptor enhanced = createSubstitutedCopy(getContainingDeclaration(), getOriginal(), getKind(), null, false);
JavaConstructorDescriptor enhanced = createSubstitutedCopy(getContainingDeclaration(), /* original = */ null, getKind(), null, false);
// We do not use doSubstitute here as in JavaMethodDescriptor.enhance because type parameters of constructor belongs to class
enhanced.initialize(
enhancedReceiverType,
@@ -138,15 +138,13 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
List<ValueParameterDescriptor> enhancedValueParameters =
UtilKt.copyValueParameters(enhancedValueParametersTypes, getValueParameters(), this);
// We use `doSubstitute` here because it does exactly what we need:
// 1. creates full copy of descriptor
// 2. copies method's type parameters (with new containing declaration) and properly substitute to them in value parameters, return type and etc.
JavaMethodDescriptor enhancedMethod =
(JavaMethodDescriptor) newCopyBuilder()
.setValueParameters(enhancedValueParameters)
.setReturnType(enhancedReturnType)
.setExtensionReceiverType(enhancedReceiverType)
.setOriginal(getOriginal())
.setDropOriginalInContainingParts()
.setPreserveSourceElement()
.build();
assert enhancedMethod != null : "null after substitution while enhancing " + toString();
@@ -26,7 +26,7 @@ fun <D : CallableMemberDescriptor> enhanceSignatures(platformSignatures: Collect
}
}
fun <D : CallableMemberDescriptor> D.enhanceSignature(): D {
private fun <D : CallableMemberDescriptor> D.enhanceSignature(): D {
// TODO type parameters
// TODO use new type parameters while enhancing other types
// TODO Propagation into generic type arguments