Implement copy in FunctionDescriptorImpl, call doSubstitute only in CopyConfiguration#build

This commit is contained in:
Alexander Udalov
2016-06-08 17:28:37 +03:00
parent ee8ca0b850
commit dc2972d99e
4 changed files with 32 additions and 34 deletions
@@ -269,9 +269,10 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
ConstructorDescriptor primaryConstructor = getUnsubstitutedPrimaryConstructor(); ConstructorDescriptor primaryConstructor = getUnsubstitutedPrimaryConstructor();
if (primaryConstructor != null) return primaryConstructor; if (primaryConstructor != null) return primaryConstructor;
return new FunctionDescriptorImpl(LazyClassDescriptor.this, null, Annotations.Companion.getEMPTY(), return new FunctionDescriptorImpl(
Name.special("<init-blocks>"), LazyClassDescriptor.this, null, Annotations.Companion.getEMPTY(), Name.special("<init-blocks>"),
CallableMemberDescriptor.Kind.SYNTHESIZED, SourceElement.NO_SOURCE) { CallableMemberDescriptor.Kind.SYNTHESIZED, SourceElement.NO_SOURCE
) {
@NotNull @NotNull
@Override @Override
protected FunctionDescriptorImpl createSubstitutedCopy( protected FunctionDescriptorImpl createSubstitutedCopy(
@@ -284,18 +285,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
) { ) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@NotNull
@Override
public FunctionDescriptor copy(
DeclarationDescriptor newOwner,
Modality modality,
Visibility visibility,
Kind kind,
boolean copyOverrides
) {
throw new UnsupportedOperationException();
}
}; };
} }
@@ -156,15 +156,13 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
@NotNull @NotNull
@Override @Override
public ConstructorDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) { public ConstructorDescriptor copy(
//noinspection ConstantConditions DeclarationDescriptor newOwner,
return (ConstructorDescriptor) doSubstitute( Modality modality,
(CopyConfiguration) newCopyBuilder() Visibility visibility,
.setOwner(newOwner) Kind kind,
.setModality(modality) boolean copyOverrides
.setVisibility(visibility) ) {
.setKind(kind) return (ConstructorDescriptor) super.copy(newOwner, modality, visibility, kind, copyOverrides);
.setCopyOverrides(copyOverrides)
);
} }
} }
@@ -315,7 +315,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
if (originalSubstitutor.isEmpty()) { if (originalSubstitutor.isEmpty()) {
return this; return this;
} }
return doSubstitute(newCopyBuilder(originalSubstitutor).setOriginal(getOriginal())); return newCopyBuilder(originalSubstitutor).setOriginal(getOriginal()).build();
} }
@Nullable @Nullable
@@ -691,6 +691,24 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
return substitutedDescriptor; return substitutedDescriptor;
} }
@NotNull
@Override
public FunctionDescriptor copy(
DeclarationDescriptor newOwner,
Modality modality,
Visibility visibility,
Kind kind,
boolean copyOverrides
) {
return newCopyBuilder()
.setOwner(newOwner)
.setModality(modality)
.setVisibility(visibility)
.setKind(kind)
.setCopyOverrides(copyOverrides)
.build();
}
@NotNull @NotNull
protected abstract FunctionDescriptorImpl createSubstitutedCopy( protected abstract FunctionDescriptorImpl createSubstitutedCopy(
@NotNull DeclarationDescriptor newOwner, @NotNull DeclarationDescriptor newOwner,
@@ -99,14 +99,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
Kind kind, Kind kind,
boolean copyOverrides boolean copyOverrides
) { ) {
//noinspection ConstantConditions return (SimpleFunctionDescriptor) super.copy(newOwner, modality, visibility, kind, copyOverrides);
return newCopyBuilder()
.setOwner(newOwner)
.setModality(modality)
.setVisibility(visibility)
.setKind(kind)
.setCopyOverrides(copyOverrides)
.build();
} }
@NotNull @NotNull