Search in sources :

Example 1 with LazyTypeAliasDescriptor

use of org.jetbrains.kotlin.resolve.lazy.descriptors.LazyTypeAliasDescriptor in project kotlin by JetBrains.

the class DescriptorResolver method resolveTypeAliasDescriptor.

@NotNull
public TypeAliasDescriptor resolveTypeAliasDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull LexicalScope scope, @NotNull KtTypeAlias typeAlias, @NotNull final BindingTrace trace) {
    if (!(containingDeclaration instanceof PackageFragmentDescriptor)) {
        trace.report(TOPLEVEL_TYPEALIASES_ONLY.on(typeAlias));
    }
    KtModifierList modifierList = typeAlias.getModifierList();
    Visibility visibility = resolveVisibilityFromModifiers(typeAlias, getDefaultVisibility(typeAlias, containingDeclaration));
    Annotations allAnnotations = annotationResolver.resolveAnnotationsWithArguments(scope, modifierList, trace);
    final Name name = KtPsiUtil.safeName(typeAlias.getName());
    SourceElement sourceElement = KotlinSourceElementKt.toSourceElement(typeAlias);
    final LazyTypeAliasDescriptor typeAliasDescriptor = LazyTypeAliasDescriptor.create(storageManager, trace, containingDeclaration, allAnnotations, name, sourceElement, visibility);
    List<TypeParameterDescriptorImpl> typeParameterDescriptors;
    final LexicalScope scopeWithTypeParameters;
    {
        List<KtTypeParameter> typeParameters = typeAlias.getTypeParameters();
        if (typeParameters.isEmpty()) {
            scopeWithTypeParameters = scope;
            typeParameterDescriptors = Collections.emptyList();
        } else {
            LexicalWritableScope writableScope = new LexicalWritableScope(scope, containingDeclaration, false, new TraceBasedLocalRedeclarationChecker(trace, overloadChecker), LexicalScopeKind.TYPE_ALIAS_HEADER);
            typeParameterDescriptors = resolveTypeParametersForDescriptor(typeAliasDescriptor, writableScope, scope, typeParameters, trace);
            writableScope.freeze();
            checkNoGenericBoundsOnTypeAliasParameters(typeAlias, trace);
            resolveGenericBounds(typeAlias, typeAliasDescriptor, writableScope, typeParameterDescriptors, trace);
            scopeWithTypeParameters = writableScope;
        }
    }
    final KtTypeReference typeReference = typeAlias.getTypeReference();
    if (typeReference == null) {
        typeAliasDescriptor.initialize(typeParameterDescriptors, ErrorUtils.createErrorType(name.asString()), ErrorUtils.createErrorType(name.asString()));
    } else if (!languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases)) {
        typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
        PsiElement typeAliasKeyword = typeAlias.getTypeAliasKeyword();
        trace.report(UNSUPPORTED_FEATURE.on(typeAliasKeyword != null ? typeAliasKeyword : typeAlias, TuplesKt.to(LanguageFeature.TypeAliases, languageVersionSettings)));
        typeAliasDescriptor.initialize(typeParameterDescriptors, ErrorUtils.createErrorType(name.asString()), ErrorUtils.createErrorType(name.asString()));
    } else {
        typeAliasDescriptor.initialize(typeParameterDescriptors, storageManager.createRecursionTolerantLazyValue(new Function0<SimpleType>() {

            @Override
            public SimpleType invoke() {
                return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
            }
        }, ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString())), storageManager.createRecursionTolerantLazyValue(new Function0<SimpleType>() {

            @Override
            public SimpleType invoke() {
                return typeResolver.resolveExpandedTypeForTypeAlias(typeAliasDescriptor);
            }
        }, ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString())));
    }
    trace.record(TYPE_ALIAS, typeAlias, typeAliasDescriptor);
    return typeAliasDescriptor;
}
Also used : FqName(org.jetbrains.kotlin.name.FqName) Name(org.jetbrains.kotlin.name.Name) CompositeAnnotations(org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations) Annotations(org.jetbrains.kotlin.descriptors.annotations.Annotations) LazyTypeAliasDescriptor(org.jetbrains.kotlin.resolve.lazy.descriptors.LazyTypeAliasDescriptor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 NotNull (org.jetbrains.annotations.NotNull)1 Annotations (org.jetbrains.kotlin.descriptors.annotations.Annotations)1 CompositeAnnotations (org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations)1 FqName (org.jetbrains.kotlin.name.FqName)1 Name (org.jetbrains.kotlin.name.Name)1 LazyTypeAliasDescriptor (org.jetbrains.kotlin.resolve.lazy.descriptors.LazyTypeAliasDescriptor)1