diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java index aa2cb7d0154..8cda92835f4 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.FunctionDescriptor; import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor; +import org.jetbrains.kotlin.descriptors.SourceElement; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor; import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor; @@ -58,7 +59,7 @@ import org.jetbrains.kotlin.name.Name; @NotNull Kind kind, @Nullable Name newName, @NotNull Annotations annotations, - boolean preserveSource + @NotNull SourceElement source ) { return new SamAdapterFunctionDescriptor(newOwner, (SimpleFunctionDescriptor) original, kind, declaration); } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt index ba7d0af57a5..443ccd3d3fe 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt @@ -147,7 +147,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope kind: CallableMemberDescriptor.Kind, newName: Name?, annotations: Annotations, - preserveSource: Boolean + source: SourceElement ): MyFunctionDescriptor { return MyFunctionDescriptor( containingDeclaration, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, source diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java index 96620c8c207..24f8337e4f6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java @@ -283,7 +283,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes @NotNull Kind kind, @Nullable Name newName, @NotNull Annotations annotations, - boolean preserveSource + @NotNull SourceElement source ) { throw new UnsupportedOperationException(); } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaConstructorDescriptor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaConstructorDescriptor.java index a94972ecc54..b49826bff30 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaConstructorDescriptor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaConstructorDescriptor.java @@ -79,7 +79,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme @NotNull Kind kind, @Nullable Name newName, @NotNull Annotations annotations, - boolean preserveSource + @NotNull SourceElement source ) { if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) { throw new IllegalStateException( @@ -92,8 +92,8 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme assert newName == null : "Attempt to rename constructor: " + this; - JavaConstructorDescriptor result = createDescriptor((ClassDescriptor) newOwner, (JavaConstructorDescriptor) original, kind, - getSourceToUseForCopy(preserveSource, original), annotations); + JavaConstructorDescriptor result = + createDescriptor((ClassDescriptor) newOwner, (JavaConstructorDescriptor) original, kind, source, annotations); result.setHasStableParameterNames(hasStableParameterNames()); result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames()); return result; @@ -121,7 +121,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme @NotNull KotlinType enhancedReturnType ) { JavaConstructorDescriptor enhanced = createSubstitutedCopy( - getContainingDeclaration(), /* original = */ null, getKind(), null, getAnnotations(), true); + getContainingDeclaration(), /* original = */ null, getKind(), null, getAnnotations(), getSource()); // We do not use doSubstitute here as in JavaMethodDescriptor.enhance because type parameters of constructor belongs to class enhanced.initialize( enhancedReceiverType, diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java index 2e91527027d..bc0751bb13e 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaMethodDescriptor.java @@ -115,7 +115,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement @NotNull Kind kind, @Nullable Name newName, @NotNull Annotations annotations, - boolean preserveSource + @NotNull SourceElement source ) { JavaMethodDescriptor result = new JavaMethodDescriptor( newOwner, @@ -123,7 +123,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement annotations, newName != null ? newName : getName(), kind, - getSourceToUseForCopy(preserveSource, original) + source ); result.setParameterNamesStatus(hasStableParameterNames(), hasSynthesizedParameterNames()); return result; diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionInvokeDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionInvokeDescriptor.kt index 67a86787b66..df6d93b438d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionInvokeDescriptor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionInvokeDescriptor.kt @@ -47,7 +47,7 @@ class FunctionInvokeDescriptor private constructor( kind: CallableMemberDescriptor.Kind, newName: Name?, annotations: Annotations, - preserveSource: Boolean + source: SourceElement ): FunctionDescriptorImpl { return FunctionInvokeDescriptor(newOwner, original as FunctionInvokeDescriptor?, kind) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/FunctionDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/FunctionDescriptor.java index 685cd0436f9..dd0cf664aca 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/FunctionDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/FunctionDescriptor.java @@ -128,6 +128,9 @@ public interface FunctionDescriptor extends CallableMemberDescriptor { @NotNull CopyBuilder setPreserveSourceElement(); + @NotNull + CopyBuilder setSource(@NotNull SourceElement source); + @NotNull CopyBuilder setDropOriginalInContainingParts(); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ConstructorDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ConstructorDescriptorImpl.java index 16200421f4d..cb7ac3086db 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ConstructorDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ConstructorDescriptorImpl.java @@ -135,7 +135,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements @NotNull Kind kind, @Nullable Name newName, @NotNull Annotations annotations, - boolean preserveSource + @NotNull SourceElement source ) { if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) { throw new IllegalStateException("Attempt at creating a constructor that is not a declaration: \n" + @@ -150,7 +150,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements annotations, isPrimary, Kind.DECLARATION, - getSourceToUseForCopy(preserveSource, original) + source ); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java index 5a8423d1632..42f6417a3e6 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java @@ -340,6 +340,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo private List newTypeParameters = null; private Annotations additionalAnnotations = null; private boolean isHiddenForResolutionEverywhereBesideSupercalls; + private SourceElement sourceElement; public CopyConfiguration( @NotNull TypeSubstitution substitution, @@ -464,6 +465,13 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo return this; } + @NotNull + @Override + public CopyBuilder setSource(@NotNull SourceElement source) { + this.sourceElement = source; + return this; + } + @Override @NotNull public CopyConfiguration setDropOriginalInContainingParts() { @@ -539,7 +547,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy( configuration.newOwner, configuration.original, configuration.kind, configuration.name, resultAnnotations, - configuration.preserveSourceElement); + getSourceToUseForCopy(configuration.preserveSourceElement, configuration.original, configuration.sourceElement)); List substitutedTypeParameters; final TypeSubstitutor substitutor; @@ -655,11 +663,16 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo @NotNull Kind kind, @Nullable Name newName, @NotNull Annotations annotations, - boolean preserveSource + @NotNull SourceElement source ); @NotNull - protected SourceElement getSourceToUseForCopy(boolean preserveSource, @Nullable FunctionDescriptor original) { + private SourceElement getSourceToUseForCopy( + boolean preserveSource, + @Nullable FunctionDescriptor original, + @Nullable SourceElement sourceElement + ) { + if (sourceElement != null) return sourceElement; return preserveSource ? (original != null ? original.getSource() : getOriginal().getSource()) : SourceElement.NO_SOURCE; diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/SimpleFunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/SimpleFunctionDescriptorImpl.java index dc8513340ce..b6ed33aa910 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/SimpleFunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/SimpleFunctionDescriptorImpl.java @@ -78,7 +78,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme @NotNull Kind kind, @Nullable Name newName, @NotNull Annotations annotations, - boolean preserveSource + @NotNull SourceElement source ) { return new SimpleFunctionDescriptorImpl( newOwner, @@ -86,7 +86,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme annotations, newName != null ? newName : getName(), kind, - getSourceToUseForCopy(preserveSource, original) + source ); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeAliasConstructorDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeAliasConstructorDescriptor.kt index 595df285988..a11910b17d5 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeAliasConstructorDescriptor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeAliasConstructorDescriptor.kt @@ -63,7 +63,7 @@ class TypeAliasConstructorDescriptorImpl private constructor( kind: Kind, newName: Name?, annotations: Annotations, - preserveSource: Boolean + source: SourceElement ): TypeAliasConstructorDescriptorImpl { assert(kind == Kind.DECLARATION || kind == Kind.SYNTHESIZED) { "Creating a type alias constructor that is not a declaration: \ncopy from: ${this}\nnewOwner: $newOwner\nkind: $kind" @@ -73,7 +73,7 @@ class TypeAliasConstructorDescriptorImpl private constructor( typeAliasDescriptor, newOwner as ClassDescriptor, this, annotations, isPrimary, Kind.DECLARATION, - getSourceToUseForCopy(preserveSource, original)) + source) } companion object { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java index 352437395ea..9e14ebf0cc1 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/error/ErrorSimpleFunctionDescriptorImpl.java @@ -48,7 +48,7 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI @NotNull Kind kind, @Nullable Name newName, @NotNull Annotations annotations, - boolean preserveSource + @NotNull SourceElement source ) { return this; } @@ -153,6 +153,12 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI return this; } + @NotNull + @Override + public CopyBuilder setSource(@NotNull SourceElement source) { + return this; + } + @NotNull @Override public CopyBuilder setDropOriginalInContainingParts() { diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt index 12f4c07e62e..d27d92b9e01 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt @@ -50,9 +50,12 @@ class DeserializedSimpleFunctionDescriptor( override val proto: ProtoBuf.Function, override val nameResolver: NameResolver, override val typeTable: TypeTable, - override val containerSource: SourceElement? + override val containerSource: SourceElement?, + source: SourceElement? = null ) : DeserializedCallableMemberDescriptor, - SimpleFunctionDescriptorImpl(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE) { + SimpleFunctionDescriptorImpl( + containingDeclaration, original, annotations, name, kind, + source ?: org.jetbrains.kotlin.descriptors.SourceElement.NO_SOURCE) { override fun createSubstitutedCopy( newOwner: DeclarationDescriptor, @@ -60,11 +63,11 @@ class DeserializedSimpleFunctionDescriptor( kind: CallableMemberDescriptor.Kind, newName: Name?, annotations: Annotations, - preserveSource: Boolean + source: SourceElement ): FunctionDescriptorImpl { return DeserializedSimpleFunctionDescriptor( newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, - proto, nameResolver, typeTable, containerSource + proto, nameResolver, typeTable, containerSource, source ) } } @@ -121,11 +124,11 @@ class DeserializedConstructorDescriptor( kind: CallableMemberDescriptor.Kind, newName: Name?, annotations: Annotations, - preserveSource: Boolean + source: SourceElement ): DeserializedConstructorDescriptor { return DeserializedConstructorDescriptor( newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind, - proto, nameResolver, typeTable, containerSource + proto, nameResolver, typeTable, source ) }