Extracted "preserve original" flag.
This commit is contained in:
+8
-2
@@ -23,6 +23,7 @@ import org.jetbrains.jet.descriptors.serialization.Flags;
|
||||
import org.jetbrains.jet.descriptors.serialization.NameResolver;
|
||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl;
|
||||
@@ -47,11 +48,16 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
|
||||
this.nameResolver = nameResolver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
return new DeserializedSimpleFunctionDescriptor(
|
||||
newOwner,
|
||||
preserveOriginal ? getOriginal() : null,
|
||||
(DeserializedSimpleFunctionDescriptor) original,
|
||||
getAnnotations(),
|
||||
getName(),
|
||||
kind,
|
||||
|
||||
+7
-1
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
|
||||
|
||||
@@ -54,8 +55,13 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl {
|
||||
this.hasStableParameterNames = hasStableParameterNames;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JavaConstructorDescriptor createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
protected JavaConstructorDescriptor createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
if (kind != Kind.DECLARATION) {
|
||||
throw new IllegalStateException("Attempt at creating a constructor that is not a declaration: \n" +
|
||||
"copy from: " + this + "\n" +
|
||||
|
||||
+8
-2
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve.java.descriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl;
|
||||
@@ -57,11 +58,16 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
|
||||
this.hasStableParameterNames = hasStableParameterNames;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
JavaMethodDescriptor result = new JavaMethodDescriptor(
|
||||
newOwner,
|
||||
preserveOriginal ? getOriginal() : null,
|
||||
(SimpleFunctionDescriptor) original,
|
||||
getAnnotations(),
|
||||
getName(),
|
||||
kind
|
||||
|
||||
+7
-2
@@ -105,15 +105,20 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
throw new UnsupportedOperationException("Constructors cannot override anything");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
if (kind != Kind.DECLARATION) {
|
||||
throw new IllegalStateException("Attempt at creating a constructor that is not a declaration: \n" +
|
||||
"copy from: " + this + "\n" +
|
||||
"newOwner: " + newOwner + "\n" +
|
||||
"kind: " + kind);
|
||||
}
|
||||
assert preserveOriginal : "Attempt to create copy of constructor without preserving original: " + this;
|
||||
assert original != null : "Attempt to create copy of constructor without preserving original: " + this;
|
||||
return new ConstructorDescriptorImpl(
|
||||
(ClassDescriptor) newOwner,
|
||||
this,
|
||||
|
||||
+17
-5
@@ -180,12 +180,19 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, visibility, true, true, getKind());
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, visibility, getOriginal(), true, getKind());
|
||||
}
|
||||
|
||||
protected FunctionDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, Visibility newVisibility, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, preserveOriginal, kind);
|
||||
@Nullable
|
||||
protected FunctionDescriptor doSubstitute(@NotNull TypeSubstitutor originalSubstitutor,
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@NotNull Modality newModality,
|
||||
@NotNull Visibility newVisibility,
|
||||
@Nullable FunctionDescriptor original,
|
||||
boolean copyOverrides,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, original, kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
@@ -233,7 +240,12 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
protected abstract FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind);
|
||||
@NotNull
|
||||
protected abstract FunctionDescriptorImpl createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind
|
||||
);
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
|
||||
+13
-5
@@ -195,12 +195,20 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, visibility, true, true, getKind());
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, visibility, getOriginal(), true, getKind());
|
||||
}
|
||||
|
||||
private PropertyDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, Visibility newVisibility, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
PropertyDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, newModality, newVisibility, preserveOriginal ? getOriginal() : null, kind);
|
||||
@Nullable
|
||||
private PropertyDescriptor doSubstitute(
|
||||
@NotNull TypeSubstitutor originalSubstitutor,
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@NotNull Modality newModality,
|
||||
@NotNull Visibility newVisibility,
|
||||
@Nullable PropertyDescriptor original,
|
||||
boolean copyOverrides,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
PropertyDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, newModality, newVisibility, original, kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
@@ -326,6 +334,6 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
||||
return doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, false, copyOverrides, kind);
|
||||
return doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, null, copyOverrides, kind);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -39,8 +40,13 @@ public class ScriptCodeDescriptor extends FunctionDescriptorImpl {
|
||||
super.initialize(null, expectedThisObject, Collections.<TypeParameterDescriptor>emptyList(), valueParameters, returnType, Modality.FINAL, Visibilities.LOCAL);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
throw new IllegalStateException("no need to copy script code descriptor");
|
||||
}
|
||||
|
||||
|
||||
+8
-3
@@ -75,11 +75,16 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
return (SimpleFunctionDescriptor) super.getOriginal();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
return new SimpleFunctionDescriptorImpl(
|
||||
newOwner,
|
||||
preserveOriginal ? getOriginal() : null,
|
||||
(SimpleFunctionDescriptor) original,
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName(),
|
||||
@@ -89,7 +94,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
||||
return (SimpleFunctionDescriptorImpl)doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, false, copyOverrides, kind);
|
||||
return (SimpleFunctionDescriptorImpl)doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, null, copyOverrides, kind);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+7
-1
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.types.error;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl;
|
||||
@@ -34,8 +35,13 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI
|
||||
this.ownerScope = ownerScope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user