Search in sources :

Example 11 with Annotations

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);
}
Also used : Annotations(org.jetbrains.kotlin.descriptors.annotations.Annotations) Method(org.jetbrains.org.objectweb.asm.commons.Method)

Example 12 with Annotations

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;
}
Also used : SmartSet(org.jetbrains.kotlin.utils.SmartSet) SmartSet(org.jetbrains.kotlin.utils.SmartSet) Annotations(org.jetbrains.kotlin.descriptors.annotations.Annotations) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Annotations (org.jetbrains.kotlin.descriptors.annotations.Annotations)12 CompositeAnnotations (org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations)8 NotNull (org.jetbrains.annotations.NotNull)6 AnnotationSplitter (org.jetbrains.kotlin.descriptors.annotations.AnnotationSplitter)4 FqName (org.jetbrains.kotlin.name.FqName)3 Name (org.jetbrains.kotlin.name.Name)3 Nullable (org.jetbrains.annotations.Nullable)2 LazyTypeAliasDescriptor (org.jetbrains.kotlin.resolve.lazy.descriptors.LazyTypeAliasDescriptor)2 PsiElement (com.intellij.psi.PsiElement)1 AnnotatedWithFakeAnnotations (org.jetbrains.kotlin.codegen.annotation.AnnotatedWithFakeAnnotations)1 AnnotationDescriptor (org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor)1 FilteredAnnotations (org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations)1 TransientReceiver (org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 SmartSet (org.jetbrains.kotlin.utils.SmartSet)1 Method (org.jetbrains.org.objectweb.asm.commons.Method)1