Add possibility to add annotations when building FunctionDescriptor copy
It's being used in next commits to add Deprecated annotation to unknown additional built-ins members
This commit is contained in:
+3
-2
@@ -53,9 +53,10 @@ import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
|
||||
@NotNull ClassDescriptor newOwner,
|
||||
@Nullable JavaConstructorDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@NotNull SourceElement sourceElement
|
||||
@NotNull SourceElement sourceElement,
|
||||
@NotNull Annotations annotations
|
||||
) {
|
||||
return new SamAdapterConstructorDescriptor(newOwner, original, getAnnotations(), isPrimary, kind, sourceElement, declaration);
|
||||
return new SamAdapterConstructorDescriptor(newOwner, original, annotations, isPrimary, kind, sourceElement, declaration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+2
@@ -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.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -56,6 +57,7 @@ import org.jetbrains.kotlin.name.Name;
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName,
|
||||
@NotNull Annotations annotations,
|
||||
boolean preserveSource
|
||||
) {
|
||||
return new SamAdapterFunctionDescriptor(newOwner, (SimpleFunctionDescriptor) original, kind, declaration);
|
||||
|
||||
@@ -144,6 +144,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?,
|
||||
annotations: Annotations,
|
||||
preserveSource: Boolean
|
||||
): MyFunctionDescriptor {
|
||||
return MyFunctionDescriptor(
|
||||
|
||||
+1
@@ -282,6 +282,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName,
|
||||
@NotNull Annotations annotations,
|
||||
boolean preserveSource
|
||||
) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
+7
-4
@@ -78,6 +78,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName,
|
||||
@NotNull Annotations annotations,
|
||||
boolean preserveSource
|
||||
) {
|
||||
if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) {
|
||||
@@ -92,7 +93,7 @@ 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));
|
||||
getSourceToUseForCopy(preserveSource, original), annotations);
|
||||
result.setHasStableParameterNames(hasStableParameterNames());
|
||||
result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
|
||||
return result;
|
||||
@@ -103,10 +104,11 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
@NotNull ClassDescriptor newOwner,
|
||||
@Nullable JavaConstructorDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@NotNull SourceElement sourceElement
|
||||
@NotNull SourceElement sourceElement,
|
||||
@NotNull Annotations annotations
|
||||
) {
|
||||
return new JavaConstructorDescriptor(
|
||||
newOwner, original, getAnnotations(), isPrimary, kind,
|
||||
newOwner, original, annotations, isPrimary, kind,
|
||||
sourceElement
|
||||
);
|
||||
}
|
||||
@@ -118,7 +120,8 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
@NotNull List<KotlinType> enhancedValueParametersTypes,
|
||||
@NotNull KotlinType enhancedReturnType
|
||||
) {
|
||||
JavaConstructorDescriptor enhanced = createSubstitutedCopy(getContainingDeclaration(), /* original = */ null, getKind(), null, true);
|
||||
JavaConstructorDescriptor enhanced = createSubstitutedCopy(
|
||||
getContainingDeclaration(), /* original = */ null, getKind(), null, getAnnotations(), true);
|
||||
// We do not use doSubstitute here as in JavaMethodDescriptor.enhance because type parameters of constructor belongs to class
|
||||
enhanced.initialize(
|
||||
enhancedReceiverType,
|
||||
|
||||
+2
-1
@@ -114,12 +114,13 @@ public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implement
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName,
|
||||
@NotNull Annotations annotations,
|
||||
boolean preserveSource
|
||||
) {
|
||||
JavaMethodDescriptor result = new JavaMethodDescriptor(
|
||||
newOwner,
|
||||
(SimpleFunctionDescriptor) original,
|
||||
getAnnotations(),
|
||||
annotations,
|
||||
newName != null ? newName : getName(),
|
||||
kind,
|
||||
getSourceToUseForCopy(preserveSource, original)
|
||||
|
||||
+3
-1
@@ -45,7 +45,9 @@ class FunctionInvokeDescriptor private constructor(
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?, preserveSource: Boolean
|
||||
newName: Name?,
|
||||
annotations: Annotations,
|
||||
preserveSource: Boolean
|
||||
): FunctionDescriptorImpl {
|
||||
return FunctionInvokeDescriptor(newOwner, original as FunctionInvokeDescriptor?, kind)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeSubstitution;
|
||||
@@ -128,6 +129,9 @@ public interface FunctionDescriptor extends CallableMemberDescriptor {
|
||||
@NotNull
|
||||
CopyBuilder<D> setHiddenToOvercomeSignatureClash();
|
||||
|
||||
@NotNull
|
||||
CopyBuilder<D> setAdditionalAnnotations(@NotNull Annotations additionalAnnotations);
|
||||
|
||||
@NotNull
|
||||
CopyBuilder<D> setSubstitution(@NotNull TypeSubstitution substitution);
|
||||
|
||||
|
||||
@@ -132,3 +132,10 @@ class CompositeAnnotations(
|
||||
|
||||
override fun iterator() = delegates.asSequence().flatMap { it.asSequence() }.iterator()
|
||||
}
|
||||
|
||||
fun composeAnnotations(first: Annotations, second: Annotations) =
|
||||
when {
|
||||
first.isEmpty() -> second
|
||||
second.isEmpty() -> first
|
||||
else -> CompositeAnnotations(first, second)
|
||||
}
|
||||
|
||||
+2
-1
@@ -134,6 +134,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName,
|
||||
@NotNull Annotations annotations,
|
||||
boolean preserveSource
|
||||
) {
|
||||
if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) {
|
||||
@@ -146,7 +147,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
return new ConstructorDescriptorImpl(
|
||||
(ClassDescriptor) newOwner,
|
||||
this,
|
||||
getAnnotations(),
|
||||
annotations,
|
||||
isPrimary,
|
||||
Kind.DECLARATION,
|
||||
getSourceToUseForCopy(preserveSource, original)
|
||||
|
||||
+16
-1
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationsKt;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
@@ -308,6 +309,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
protected boolean dropOriginalInContainingParts = false;
|
||||
private boolean isHiddenToOvercomeSignatureClash;
|
||||
private List<TypeParameterDescriptor> newTypeParameters = null;
|
||||
private Annotations additionalAnnotations = null;
|
||||
|
||||
public CopyConfiguration(
|
||||
@NotNull TypeSubstitution substitution,
|
||||
@@ -445,6 +447,13 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CopyConfiguration setAdditionalAnnotations(@NotNull Annotations additionalAnnotations) {
|
||||
this.additionalAnnotations = additionalAnnotations;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CopyConfiguration setSubstitution(@NotNull TypeSubstitution substitution) {
|
||||
@@ -485,8 +494,13 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
|
||||
@Nullable
|
||||
protected FunctionDescriptor doSubstitute(@NotNull CopyConfiguration configuration) {
|
||||
Annotations resultAnnotations =
|
||||
configuration.additionalAnnotations != null
|
||||
? AnnotationsKt.composeAnnotations(getAnnotations(), configuration.additionalAnnotations)
|
||||
: getAnnotations();
|
||||
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(
|
||||
configuration.newOwner, configuration.original, configuration.kind, configuration.name,
|
||||
configuration.newOwner, configuration.original, configuration.kind, configuration.name, resultAnnotations,
|
||||
configuration.preserveSourceElement);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters;
|
||||
@@ -600,6 +614,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName,
|
||||
@NotNull Annotations annotations,
|
||||
boolean preserveSource
|
||||
);
|
||||
|
||||
|
||||
+2
-2
@@ -77,13 +77,13 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName,
|
||||
@NotNull Annotations annotations,
|
||||
boolean preserveSource
|
||||
) {
|
||||
return new SimpleFunctionDescriptorImpl(
|
||||
newOwner,
|
||||
(SimpleFunctionDescriptor) original,
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
annotations,
|
||||
newName != null ? newName : getName(),
|
||||
kind,
|
||||
getSourceToUseForCopy(preserveSource, original)
|
||||
|
||||
+7
@@ -47,6 +47,7 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@Nullable Name newName,
|
||||
@NotNull Annotations annotations,
|
||||
boolean preserveSource
|
||||
) {
|
||||
return this;
|
||||
@@ -164,6 +165,12 @@ public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorI
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CopyBuilder<SimpleFunctionDescriptor> setAdditionalAnnotations(@NotNull Annotations additionalAnnotations) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SimpleFunctionDescriptor build() {
|
||||
|
||||
+2
@@ -57,6 +57,7 @@ class DeserializedSimpleFunctionDescriptor(
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?,
|
||||
annotations: Annotations,
|
||||
preserveSource: Boolean
|
||||
): FunctionDescriptorImpl {
|
||||
return DeserializedSimpleFunctionDescriptor(
|
||||
@@ -117,6 +118,7 @@ class DeserializedConstructorDescriptor(
|
||||
original: FunctionDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name?,
|
||||
annotations: Annotations,
|
||||
preserveSource: Boolean
|
||||
): DeserializedConstructorDescriptor {
|
||||
return DeserializedConstructorDescriptor(
|
||||
|
||||
Reference in New Issue
Block a user