properly rewrite *Descriptor owner in FunctionDescriptorImpl.copy()
This commit is contained in:
+4
-3
@@ -23,8 +23,8 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
this.isPrimary = isPrimary;
|
||||
}
|
||||
|
||||
public ConstructorDescriptorImpl(@NotNull ConstructorDescriptor original, @NotNull List<AnnotationDescriptor> annotations, boolean isPrimary) {
|
||||
super(original.getContainingDeclaration(), original, annotations, "<init>");
|
||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull ConstructorDescriptor original, @NotNull List<AnnotationDescriptor> annotations, boolean isPrimary) {
|
||||
super(containingDeclaration, original, annotations, "<init>");
|
||||
this.isPrimary = isPrimary;
|
||||
}
|
||||
|
||||
@@ -85,8 +85,9 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy() {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal) {
|
||||
return new ConstructorDescriptorImpl(
|
||||
(ClassDescriptor) newOwner,
|
||||
this,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||
isPrimary);
|
||||
|
||||
+9
-4
@@ -135,7 +135,12 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy();
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, true);
|
||||
}
|
||||
|
||||
protected FunctionDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, boolean preserveOriginal) {
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, preserveOriginal);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
@@ -147,7 +152,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ReceiverDescriptor substitutedExpectedThis = NO_RECEIVER;
|
||||
if (expectedThisObject.exists()) {
|
||||
JetType substitutedType = substitutor.substitute(expectedThisObject.getType(), Variance.INVARIANT);
|
||||
@@ -173,7 +178,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
substitutedTypeParameters,
|
||||
substitutedValueParameters,
|
||||
substitutedReturnType,
|
||||
modality,
|
||||
newModality,
|
||||
visibility
|
||||
);
|
||||
for (FunctionDescriptor overriddenFunction : overriddenFunctions) {
|
||||
@@ -182,7 +187,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
protected abstract FunctionDescriptorImpl createSubstitutedCopy();
|
||||
protected abstract FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal);
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
|
||||
+17
-18
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,28 +28,26 @@ public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy() {
|
||||
return new NamedFunctionDescriptorImpl(
|
||||
getContainingDeclaration(),
|
||||
this,
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName());
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal) {
|
||||
if (preserveOriginal) {
|
||||
return new NamedFunctionDescriptorImpl(
|
||||
newOwner,
|
||||
getOriginal(),
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName());
|
||||
} else {
|
||||
return new NamedFunctionDescriptorImpl(
|
||||
newOwner,
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
NamedFunctionDescriptorImpl copy = new NamedFunctionDescriptorImpl(newOwner, Lists.newArrayList(getAnnotations()), getName());
|
||||
copy.initialize(
|
||||
getReceiverParameter().exists() ? getReceiverParameter().getType() : null,
|
||||
expectedThisObject,
|
||||
DescriptorUtils.copyTypeParameters(copy, typeParameters),
|
||||
DescriptorUtils.copyValueParameters(copy, unsubstitutedValueParameters),
|
||||
unsubstitutedReturnType,
|
||||
DescriptorUtils.convertModality(modality, makeNonAbstract),
|
||||
visibility
|
||||
);
|
||||
return copy;
|
||||
return (NamedFunctionDescriptor) doSubstitute(TypeSubstitutor.EMPTY, newOwner, DescriptorUtils.convertModality(modality, makeNonAbstract), false);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy() {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ public class ExpressionAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy() {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class NamedFunctionDescriptorErrorImpl extends NamedFunctionDescriptorImp
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy() {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user