Add 'preserveSource' parameter to methods making substitution copies
This commit is contained in:
+2
-1
@@ -55,7 +55,8 @@ import org.jetbrains.kotlin.name.Name;
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName
|
||||
@Nullable Name newName,
|
||||
boolean preserveSource
|
||||
) {
|
||||
return new SamAdapterFunctionDescriptor(newOwner, (SimpleFunctionDescriptor) original, kind, declaration);
|
||||
}
|
||||
|
||||
+6
-3
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.synthetic
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils
|
||||
@@ -145,7 +146,8 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?
|
||||
newName: Name?,
|
||||
preserveSource: Boolean
|
||||
): MyFunctionDescriptor {
|
||||
return MyFunctionDescriptor(
|
||||
containingDeclaration, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, source
|
||||
@@ -170,12 +172,13 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc
|
||||
newValueParameterDescriptors: MutableList<ValueParameterDescriptor>,
|
||||
newExtensionReceiverParameterType: KotlinType?,
|
||||
newReturnType: KotlinType,
|
||||
name: Name?
|
||||
name: Name?,
|
||||
preserveSource: Boolean
|
||||
): FunctionDescriptor? {
|
||||
val descriptor = super.doSubstitute(
|
||||
originalSubstitutor, newOwner, newModality, newVisibility,
|
||||
newIsOperator, newIsInfix, newIsExternal, newIsInline, newIsTailrec, original,
|
||||
copyOverrides, kind, newValueParameterDescriptors, newExtensionReceiverParameterType, newReturnType, name)
|
||||
copyOverrides, kind, newValueParameterDescriptors, newExtensionReceiverParameterType, newReturnType, name, preserveSource)
|
||||
as MyFunctionDescriptor? ?: return null
|
||||
|
||||
if (original == null) {
|
||||
|
||||
+4
-3
@@ -77,7 +77,8 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName
|
||||
@Nullable Name newName,
|
||||
boolean preserveSource
|
||||
) {
|
||||
if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) {
|
||||
throw new IllegalStateException(
|
||||
@@ -91,7 +92,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
assert newName == null : "Attempt to rename constructor: " + this;
|
||||
|
||||
JavaConstructorDescriptor result = new JavaConstructorDescriptor(
|
||||
(ClassDescriptor) newOwner, this, getAnnotations(), isPrimary, kind, SourceElement.NO_SOURCE
|
||||
(ClassDescriptor) newOwner, this, getAnnotations(), isPrimary, kind, getSourceToUseForCopy(preserveSource, original)
|
||||
);
|
||||
result.setHasStableParameterNames(hasStableParameterNames());
|
||||
result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
|
||||
@@ -105,7 +106,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
@NotNull List<KotlinType> enhancedValueParametersTypes,
|
||||
@NotNull KotlinType enhancedReturnType
|
||||
) {
|
||||
JavaConstructorDescriptor enhanced = createSubstitutedCopy(getContainingDeclaration(), getOriginal(), getKind(), null);
|
||||
JavaConstructorDescriptor enhanced = createSubstitutedCopy(getContainingDeclaration(), getOriginal(), getKind(), null, false);
|
||||
// We do not use doSubstitute here as in JavaMethodDescriptor.enhance because type parameters of constructor belongs to class
|
||||
enhanced.initialize(
|
||||
enhancedReceiverType,
|
||||
|
||||
+4
-3
@@ -114,7 +114,8 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName
|
||||
@Nullable Name newName,
|
||||
boolean preserveSource
|
||||
) {
|
||||
JavaMethodDescriptor result = new JavaMethodDescriptor(
|
||||
newOwner,
|
||||
@@ -122,7 +123,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
|
||||
getAnnotations(),
|
||||
newName != null ? newName : getName(),
|
||||
kind,
|
||||
original != null ? original.getSource() : SourceElement.NO_SOURCE
|
||||
getSourceToUseForCopy(preserveSource, original)
|
||||
);
|
||||
result.setParameterNamesStatus(hasStableParameterNames(), hasSynthesizedParameterNames());
|
||||
return result;
|
||||
@@ -146,7 +147,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
|
||||
isOperator(), isInfix(), isExternal(), isInline(), isTailrec(), getOriginal(),
|
||||
/* copyOverrides = */ true, getKind(),
|
||||
enhancedValueParameters, enhancedReceiverType, enhancedReturnType,
|
||||
null);
|
||||
null, false);
|
||||
|
||||
assert enhancedMethod != null : "null after substitution while enhancing " + toString();
|
||||
return enhancedMethod;
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.builtins.functions
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -42,8 +43,8 @@ public class FunctionInvokeDescriptor private constructor(
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?
|
||||
): FunctionInvokeDescriptor {
|
||||
newName: Name?, preserveSource: Boolean
|
||||
): FunctionDescriptorImpl {
|
||||
return FunctionInvokeDescriptor(newOwner, original as FunctionInvokeDescriptor?, kind)
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -115,7 +115,8 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName
|
||||
@Nullable Name newName,
|
||||
boolean preserveSource
|
||||
) {
|
||||
if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) {
|
||||
throw new IllegalStateException("Attempt at creating a constructor that is not a declaration: \n" +
|
||||
@@ -131,7 +132,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
getAnnotations(),
|
||||
isPrimary,
|
||||
Kind.DECLARATION,
|
||||
SourceElement.NO_SOURCE
|
||||
getSourceToUseForCopy(preserveSource, original)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+15
-6
@@ -269,9 +269,9 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
return doSubstitute(originalSubstitutor,
|
||||
newOwner, newModality, newVisibility, isOperator, isInfix, isExternal, isInline, isTailrec, original, copyOverrides, kind,
|
||||
getValueParameters(), getExtensionReceiverParameterType(), getReturnType(),
|
||||
null);
|
||||
newOwner, newModality, newVisibility, isOperator, isInfix, isExternal, isInline, isTailrec, original, copyOverrides, kind,
|
||||
getValueParameters(), getExtensionReceiverParameterType(), getReturnType(),
|
||||
null, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -298,9 +298,10 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
@NotNull List<ValueParameterDescriptor> newValueParameterDescriptors,
|
||||
@Nullable KotlinType newExtensionReceiverParameterType,
|
||||
@NotNull KotlinType newReturnType,
|
||||
@Nullable Name name
|
||||
@Nullable Name name,
|
||||
boolean preserveSource
|
||||
) {
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, original, kind, name);
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, original, kind, name, preserveSource);
|
||||
|
||||
List<TypeParameterDescriptor> originalTypeParameters = getTypeParameters();
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = new ArrayList<TypeParameterDescriptor>(originalTypeParameters.size());
|
||||
@@ -375,9 +376,17 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName
|
||||
@Nullable Name newName,
|
||||
boolean preserveSource
|
||||
);
|
||||
|
||||
@NotNull
|
||||
protected SourceElement getSourceToUseForCopy(boolean preserveSource, @Nullable FunctionDescriptor original) {
|
||||
return preserveSource
|
||||
? (original != null ? original.getSource() : getOriginal().getSource())
|
||||
: SourceElement.NO_SOURCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitFunctionDescriptor(this, data);
|
||||
|
||||
+2
-1
@@ -46,7 +46,8 @@ public class ScriptCodeDescriptor extends FunctionDescriptorImpl {
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName
|
||||
@Nullable Name newName,
|
||||
boolean preserveSource
|
||||
) {
|
||||
throw new IllegalStateException("no need to copy script code descriptor");
|
||||
}
|
||||
|
||||
+9
-6
@@ -77,7 +77,8 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName
|
||||
@Nullable Name newName,
|
||||
boolean preserveSource
|
||||
) {
|
||||
return new SimpleFunctionDescriptorImpl(
|
||||
newOwner,
|
||||
@@ -86,7 +87,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
getAnnotations(),
|
||||
newName != null ? newName : getName(),
|
||||
kind,
|
||||
SourceElement.NO_SOURCE
|
||||
getSourceToUseForCopy(preserveSource, original)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -109,20 +110,22 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleFunctionDescriptor createRenamedCopy(@NotNull Name name) {
|
||||
//noinspection ConstantConditions
|
||||
return (SimpleFunctionDescriptorImpl) doSubstitute(
|
||||
TypeSubstitutor.EMPTY, getContainingDeclaration(), getModality(), getVisibility(),
|
||||
isOperator(), isInfix(), isExternal(), isInline(), isTailrec(),
|
||||
null, /* copyOverrides = */ true, getKind(), getValueParameters(), getExtensionReceiverParameterType(), getReturnType(), name
|
||||
);
|
||||
null, /* copyOverrides = */ true, getKind(), getValueParameters(), getExtensionReceiverParameterType(), getReturnType(), name,
|
||||
/* preserveSource = */ true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleFunctionDescriptor createCopyWithNewValueParameters(@NotNull List<ValueParameterDescriptor> valueParameters) {
|
||||
//noinspection ConstantConditions
|
||||
return (SimpleFunctionDescriptorImpl) doSubstitute(
|
||||
TypeSubstitutor.EMPTY, getContainingDeclaration(), getModality(), getVisibility(),
|
||||
isOperator(), isInfix(), isExternal(), isInline(), isTailrec(),
|
||||
null, /* copyOverrides = */ true, getKind(), valueParameters, getExtensionReceiverParameterType(), getReturnType(), null
|
||||
);
|
||||
null, /* copyOverrides = */ true, getKind(), valueParameters, getExtensionReceiverParameterType(), getReturnType(), null,
|
||||
/* preserveSource = */ true);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -43,7 +43,8 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName
|
||||
@Nullable Name newName,
|
||||
boolean preserveSource
|
||||
) {
|
||||
return this;
|
||||
}
|
||||
|
||||
+3
-1
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.serialization.deserialization.descriptors
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
@@ -40,7 +41,8 @@ public class DeserializedConstructorDescriptor(
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?
|
||||
newName: Name?,
|
||||
preserveSource: Boolean
|
||||
): DeserializedConstructorDescriptor {
|
||||
return DeserializedConstructorDescriptor(
|
||||
newOwner as ClassDescriptor, original as ConstructorDescriptor?,
|
||||
|
||||
+2
-1
@@ -60,7 +60,8 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName
|
||||
@Nullable Name newName,
|
||||
boolean preserveSource
|
||||
) {
|
||||
return new DeserializedSimpleFunctionDescriptor(
|
||||
newOwner,
|
||||
|
||||
Reference in New Issue
Block a user