use of org.jetbrains.kotlin.descriptors.annotations.Annotations in project kotlin by JetBrains.
the class MemberCodegen method genTypeAliasAnnotationsMethodIfRequired.
private void genTypeAliasAnnotationsMethodIfRequired(TypeAliasDescriptor typeAliasDescriptor) {
boolean isAnnotationsMethodOwner = CodegenContextUtil.isImplClassOwner(context);
Annotations annotations = typeAliasDescriptor.getAnnotations();
if (!isAnnotationsMethodOwner || annotations.getAllAnnotations().isEmpty())
return;
String name = JvmAbi.getSyntheticMethodNameForAnnotatedTypeAlias(typeAliasDescriptor.getName());
generateSyntheticAnnotationsMethod(typeAliasDescriptor, new Method(name, "()V"), annotations, null);
}
use of org.jetbrains.kotlin.descriptors.annotations.Annotations in project kotlin by JetBrains.
the class FunctionDescriptorImpl method doSubstitute.
@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, resultAnnotations, getSourceToUseForCopy(configuration.preserveSourceElement, configuration.original, configuration.sourceElement));
List<TypeParameterDescriptor> unsubstitutedTypeParameters = configuration.newTypeParameters == null ? getTypeParameters() : configuration.newTypeParameters;
List<TypeParameterDescriptor> substitutedTypeParameters = new ArrayList<TypeParameterDescriptor>(unsubstitutedTypeParameters.size());
final TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(unsubstitutedTypeParameters, configuration.substitution, substitutedDescriptor, substitutedTypeParameters);
KotlinType substitutedReceiverParameterType = null;
if (configuration.newExtensionReceiverParameterType != null) {
substitutedReceiverParameterType = substitutor.substitute(configuration.newExtensionReceiverParameterType, Variance.IN_VARIANCE);
if (substitutedReceiverParameterType == null) {
return null;
}
}
ReceiverParameterDescriptor substitutedExpectedThis = null;
if (configuration.dispatchReceiverParameter != null) {
// When generating fake-overridden member it's dispatch receiver parameter has type of Base, and it's correct.
// E.g.
// class Base { fun foo() }
// class Derived : Base
// val x: Base
// if (x is Derived) {
// // `x` shouldn't be marked as smart-cast
// // but it would if fake-overridden `foo` had `Derived` as it's dispatch receiver parameter type
// x.foo()
// }
substitutedExpectedThis = configuration.dispatchReceiverParameter.substitute(substitutor);
if (substitutedExpectedThis == null) {
return null;
}
}
List<ValueParameterDescriptor> substitutedValueParameters = getSubstitutedValueParameters(substitutedDescriptor, configuration.newValueParameterDescriptors, substitutor, configuration.dropOriginalInContainingParts, configuration.preserveSourceElement);
if (substitutedValueParameters == null) {
return null;
}
KotlinType substitutedReturnType = substitutor.substitute(configuration.newReturnType, Variance.OUT_VARIANCE);
if (substitutedReturnType == null) {
return null;
}
substitutedDescriptor.initialize(substitutedReceiverParameterType, substitutedExpectedThis, substitutedTypeParameters, substitutedValueParameters, substitutedReturnType, configuration.newModality, configuration.newVisibility);
substitutedDescriptor.setOperator(isOperator);
substitutedDescriptor.setInfix(isInfix);
substitutedDescriptor.setExternal(isExternal);
substitutedDescriptor.setInline(isInline);
substitutedDescriptor.setTailrec(isTailrec);
substitutedDescriptor.setSuspend(isSuspend);
substitutedDescriptor.setHeader(isHeader);
substitutedDescriptor.setImpl(isImpl);
substitutedDescriptor.setHasStableParameterNames(hasStableParameterNames);
substitutedDescriptor.setHiddenToOvercomeSignatureClash(configuration.isHiddenToOvercomeSignatureClash);
substitutedDescriptor.setHiddenForResolutionEverywhereBesideSupercalls(configuration.isHiddenForResolutionEverywhereBesideSupercalls);
substitutedDescriptor.setHasSynthesizedParameterNames(configuration.newHasSynthesizedParameterNames != null ? configuration.newHasSynthesizedParameterNames : hasSynthesizedParameterNames);
if (!configuration.userDataMap.isEmpty() || userDataMap != null) {
Map<UserDataKey<?>, Object> newMap = configuration.userDataMap;
if (userDataMap != null) {
for (Map.Entry<UserDataKey<?>, Object> entry : userDataMap.entrySet()) {
if (!newMap.containsKey(entry.getKey())) {
newMap.put(entry.getKey(), entry.getValue());
}
}
}
if (newMap.size() == 1) {
substitutedDescriptor.userDataMap = Collections.<UserDataKey<?>, Object>singletonMap(newMap.keySet().iterator().next(), newMap.values().iterator().next());
} else {
substitutedDescriptor.userDataMap = newMap;
}
}
if (configuration.signatureChange || getInitialSignatureDescriptor() != null) {
FunctionDescriptor initialSignature = (getInitialSignatureDescriptor() != null ? getInitialSignatureDescriptor() : this);
FunctionDescriptor initialSignatureSubstituted = initialSignature.substitute(substitutor);
substitutedDescriptor.setInitialSignatureDescriptor(initialSignatureSubstituted);
}
if (configuration.copyOverrides && !getOriginal().getOverriddenDescriptors().isEmpty()) {
if (configuration.substitution.isEmpty()) {
Function0<Set<FunctionDescriptor>> overriddenFunctionsTask = lazyOverriddenFunctionsTask;
if (overriddenFunctionsTask != null) {
substitutedDescriptor.lazyOverriddenFunctionsTask = overriddenFunctionsTask;
} else {
substitutedDescriptor.setOverriddenDescriptors(getOverriddenDescriptors());
}
} else {
substitutedDescriptor.lazyOverriddenFunctionsTask = new Function0<Set<FunctionDescriptor>>() {
@Override
public Set<FunctionDescriptor> invoke() {
SmartSet<FunctionDescriptor> result = SmartSet.create();
for (FunctionDescriptor overriddenFunction : getOverriddenDescriptors()) {
result.add(overriddenFunction.substitute(substitutor));
}
return result;
}
};
}
}
return substitutedDescriptor;
}
Aggregations