Add ability to set up source element when copying descriptor
This commit is contained in:
+2
-1
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||||
|
import org.jetbrains.kotlin.descriptors.SourceElement;
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor;
|
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor;
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
|
import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
|
||||||
@@ -58,7 +59,7 @@ import org.jetbrains.kotlin.name.Name;
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@Nullable Name newName,
|
@Nullable Name newName,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
boolean preserveSource
|
@NotNull SourceElement source
|
||||||
) {
|
) {
|
||||||
return new SamAdapterFunctionDescriptor(newOwner, (SimpleFunctionDescriptor) original, kind, declaration);
|
return new SamAdapterFunctionDescriptor(newOwner, (SimpleFunctionDescriptor) original, kind, declaration);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -147,7 +147,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope
|
|||||||
kind: CallableMemberDescriptor.Kind,
|
kind: CallableMemberDescriptor.Kind,
|
||||||
newName: Name?,
|
newName: Name?,
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
preserveSource: Boolean
|
source: SourceElement
|
||||||
): MyFunctionDescriptor {
|
): MyFunctionDescriptor {
|
||||||
return MyFunctionDescriptor(
|
return MyFunctionDescriptor(
|
||||||
containingDeclaration, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, source
|
containingDeclaration, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, source
|
||||||
|
|||||||
+1
-1
@@ -283,7 +283,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@Nullable Name newName,
|
@Nullable Name newName,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
boolean preserveSource
|
@NotNull SourceElement source
|
||||||
) {
|
) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -79,7 +79,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@Nullable Name newName,
|
@Nullable Name newName,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
boolean preserveSource
|
@NotNull SourceElement source
|
||||||
) {
|
) {
|
||||||
if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) {
|
if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
@@ -92,8 +92,8 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
|||||||
|
|
||||||
assert newName == null : "Attempt to rename constructor: " + this;
|
assert newName == null : "Attempt to rename constructor: " + this;
|
||||||
|
|
||||||
JavaConstructorDescriptor result = createDescriptor((ClassDescriptor) newOwner, (JavaConstructorDescriptor) original, kind,
|
JavaConstructorDescriptor result =
|
||||||
getSourceToUseForCopy(preserveSource, original), annotations);
|
createDescriptor((ClassDescriptor) newOwner, (JavaConstructorDescriptor) original, kind, source, annotations);
|
||||||
result.setHasStableParameterNames(hasStableParameterNames());
|
result.setHasStableParameterNames(hasStableParameterNames());
|
||||||
result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
|
result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
|
||||||
return result;
|
return result;
|
||||||
@@ -121,7 +121,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
|||||||
@NotNull KotlinType enhancedReturnType
|
@NotNull KotlinType enhancedReturnType
|
||||||
) {
|
) {
|
||||||
JavaConstructorDescriptor enhanced = createSubstitutedCopy(
|
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
|
// We do not use doSubstitute here as in JavaMethodDescriptor.enhance because type parameters of constructor belongs to class
|
||||||
enhanced.initialize(
|
enhanced.initialize(
|
||||||
enhancedReceiverType,
|
enhancedReceiverType,
|
||||||
|
|||||||
+2
-2
@@ -115,7 +115,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@Nullable Name newName,
|
@Nullable Name newName,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
boolean preserveSource
|
@NotNull SourceElement source
|
||||||
) {
|
) {
|
||||||
JavaMethodDescriptor result = new JavaMethodDescriptor(
|
JavaMethodDescriptor result = new JavaMethodDescriptor(
|
||||||
newOwner,
|
newOwner,
|
||||||
@@ -123,7 +123,7 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
|
|||||||
annotations,
|
annotations,
|
||||||
newName != null ? newName : getName(),
|
newName != null ? newName : getName(),
|
||||||
kind,
|
kind,
|
||||||
getSourceToUseForCopy(preserveSource, original)
|
source
|
||||||
);
|
);
|
||||||
result.setParameterNamesStatus(hasStableParameterNames(), hasSynthesizedParameterNames());
|
result.setParameterNamesStatus(hasStableParameterNames(), hasSynthesizedParameterNames());
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+1
-1
@@ -47,7 +47,7 @@ class FunctionInvokeDescriptor private constructor(
|
|||||||
kind: CallableMemberDescriptor.Kind,
|
kind: CallableMemberDescriptor.Kind,
|
||||||
newName: Name?,
|
newName: Name?,
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
preserveSource: Boolean
|
source: SourceElement
|
||||||
): FunctionDescriptorImpl {
|
): FunctionDescriptorImpl {
|
||||||
return FunctionInvokeDescriptor(newOwner, original as FunctionInvokeDescriptor?, kind)
|
return FunctionInvokeDescriptor(newOwner, original as FunctionInvokeDescriptor?, kind)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ public interface FunctionDescriptor extends CallableMemberDescriptor {
|
|||||||
@NotNull
|
@NotNull
|
||||||
CopyBuilder<D> setPreserveSourceElement();
|
CopyBuilder<D> setPreserveSourceElement();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
CopyBuilder<D> setSource(@NotNull SourceElement source);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
CopyBuilder<D> setDropOriginalInContainingParts();
|
CopyBuilder<D> setDropOriginalInContainingParts();
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -135,7 +135,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@Nullable Name newName,
|
@Nullable Name newName,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
boolean preserveSource
|
@NotNull SourceElement source
|
||||||
) {
|
) {
|
||||||
if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) {
|
if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) {
|
||||||
throw new IllegalStateException("Attempt at creating a constructor that is not a declaration: \n" +
|
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,
|
annotations,
|
||||||
isPrimary,
|
isPrimary,
|
||||||
Kind.DECLARATION,
|
Kind.DECLARATION,
|
||||||
getSourceToUseForCopy(preserveSource, original)
|
source
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-3
@@ -340,6 +340,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
|||||||
private List<TypeParameterDescriptor> newTypeParameters = null;
|
private List<TypeParameterDescriptor> newTypeParameters = null;
|
||||||
private Annotations additionalAnnotations = null;
|
private Annotations additionalAnnotations = null;
|
||||||
private boolean isHiddenForResolutionEverywhereBesideSupercalls;
|
private boolean isHiddenForResolutionEverywhereBesideSupercalls;
|
||||||
|
private SourceElement sourceElement;
|
||||||
|
|
||||||
public CopyConfiguration(
|
public CopyConfiguration(
|
||||||
@NotNull TypeSubstitution substitution,
|
@NotNull TypeSubstitution substitution,
|
||||||
@@ -464,6 +465,13 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public CopyBuilder<FunctionDescriptor> setSource(@NotNull SourceElement source) {
|
||||||
|
this.sourceElement = source;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public CopyConfiguration setDropOriginalInContainingParts() {
|
public CopyConfiguration setDropOriginalInContainingParts() {
|
||||||
@@ -539,7 +547,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
|||||||
|
|
||||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(
|
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(
|
||||||
configuration.newOwner, configuration.original, configuration.kind, configuration.name, resultAnnotations,
|
configuration.newOwner, configuration.original, configuration.kind, configuration.name, resultAnnotations,
|
||||||
configuration.preserveSourceElement);
|
getSourceToUseForCopy(configuration.preserveSourceElement, configuration.original, configuration.sourceElement));
|
||||||
|
|
||||||
List<TypeParameterDescriptor> substitutedTypeParameters;
|
List<TypeParameterDescriptor> substitutedTypeParameters;
|
||||||
final TypeSubstitutor substitutor;
|
final TypeSubstitutor substitutor;
|
||||||
@@ -655,11 +663,16 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@Nullable Name newName,
|
@Nullable Name newName,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
boolean preserveSource
|
@NotNull SourceElement source
|
||||||
);
|
);
|
||||||
|
|
||||||
@NotNull
|
@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
|
return preserveSource
|
||||||
? (original != null ? original.getSource() : getOriginal().getSource())
|
? (original != null ? original.getSource() : getOriginal().getSource())
|
||||||
: SourceElement.NO_SOURCE;
|
: SourceElement.NO_SOURCE;
|
||||||
|
|||||||
+2
-2
@@ -78,7 +78,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@Nullable Name newName,
|
@Nullable Name newName,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
boolean preserveSource
|
@NotNull SourceElement source
|
||||||
) {
|
) {
|
||||||
return new SimpleFunctionDescriptorImpl(
|
return new SimpleFunctionDescriptorImpl(
|
||||||
newOwner,
|
newOwner,
|
||||||
@@ -86,7 +86,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
|||||||
annotations,
|
annotations,
|
||||||
newName != null ? newName : getName(),
|
newName != null ? newName : getName(),
|
||||||
kind,
|
kind,
|
||||||
getSourceToUseForCopy(preserveSource, original)
|
source
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -63,7 +63,7 @@ class TypeAliasConstructorDescriptorImpl private constructor(
|
|||||||
kind: Kind,
|
kind: Kind,
|
||||||
newName: Name?,
|
newName: Name?,
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
preserveSource: Boolean
|
source: SourceElement
|
||||||
): TypeAliasConstructorDescriptorImpl {
|
): TypeAliasConstructorDescriptorImpl {
|
||||||
assert(kind == Kind.DECLARATION || kind == Kind.SYNTHESIZED) {
|
assert(kind == Kind.DECLARATION || kind == Kind.SYNTHESIZED) {
|
||||||
"Creating a type alias constructor that is not a declaration: \ncopy from: ${this}\nnewOwner: $newOwner\nkind: $kind"
|
"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,
|
typeAliasDescriptor,
|
||||||
newOwner as ClassDescriptor,
|
newOwner as ClassDescriptor,
|
||||||
this, annotations, isPrimary, Kind.DECLARATION,
|
this, annotations, isPrimary, Kind.DECLARATION,
|
||||||
getSourceToUseForCopy(preserveSource, original))
|
source)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+7
-1
@@ -48,7 +48,7 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@Nullable Name newName,
|
@Nullable Name newName,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
boolean preserveSource
|
@NotNull SourceElement source
|
||||||
) {
|
) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -153,6 +153,12 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public CopyBuilder<SimpleFunctionDescriptor> setSource(@NotNull SourceElement source) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public CopyBuilder<SimpleFunctionDescriptor> setDropOriginalInContainingParts() {
|
public CopyBuilder<SimpleFunctionDescriptor> setDropOriginalInContainingParts() {
|
||||||
|
|||||||
+9
-6
@@ -50,9 +50,12 @@ class DeserializedSimpleFunctionDescriptor(
|
|||||||
override val proto: ProtoBuf.Function,
|
override val proto: ProtoBuf.Function,
|
||||||
override val nameResolver: NameResolver,
|
override val nameResolver: NameResolver,
|
||||||
override val typeTable: TypeTable,
|
override val typeTable: TypeTable,
|
||||||
override val containerSource: SourceElement?
|
override val containerSource: SourceElement?,
|
||||||
|
source: SourceElement? = null
|
||||||
) : DeserializedCallableMemberDescriptor,
|
) : 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(
|
override fun createSubstitutedCopy(
|
||||||
newOwner: DeclarationDescriptor,
|
newOwner: DeclarationDescriptor,
|
||||||
@@ -60,11 +63,11 @@ class DeserializedSimpleFunctionDescriptor(
|
|||||||
kind: CallableMemberDescriptor.Kind,
|
kind: CallableMemberDescriptor.Kind,
|
||||||
newName: Name?,
|
newName: Name?,
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
preserveSource: Boolean
|
source: SourceElement
|
||||||
): FunctionDescriptorImpl {
|
): FunctionDescriptorImpl {
|
||||||
return DeserializedSimpleFunctionDescriptor(
|
return DeserializedSimpleFunctionDescriptor(
|
||||||
newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind,
|
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,
|
kind: CallableMemberDescriptor.Kind,
|
||||||
newName: Name?,
|
newName: Name?,
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
preserveSource: Boolean
|
source: SourceElement
|
||||||
): DeserializedConstructorDescriptor {
|
): DeserializedConstructorDescriptor {
|
||||||
return DeserializedConstructorDescriptor(
|
return DeserializedConstructorDescriptor(
|
||||||
newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind,
|
newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind,
|
||||||
proto, nameResolver, typeTable, containerSource
|
proto, nameResolver, typeTable, source
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user