Search in sources :

Example 1 with KtClassLikeInfo

use of org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo in project kotlin by JetBrains.

the class ResolveSession method getTopLevelClassifierDescriptors.

@Override
@NotNull
@ReadOnly
public Collection<ClassifierDescriptor> getTopLevelClassifierDescriptors(@NotNull FqName fqName, @NotNull final LookupLocation location) {
    if (fqName.isRoot())
        return Collections.emptyList();
    PackageMemberDeclarationProvider provider = declarationProviderFactory.getPackageMemberDeclarationProvider(fqName.parent());
    if (provider == null)
        return Collections.emptyList();
    Collection<ClassifierDescriptor> result = new SmartList<ClassifierDescriptor>();
    result.addAll(ContainerUtil.mapNotNull(provider.getClassOrObjectDeclarations(fqName.shortName()), new Function<KtClassLikeInfo, ClassifierDescriptor>() {

        @Override
        public ClassDescriptor fun(KtClassLikeInfo classLikeInfo) {
            if (classLikeInfo instanceof KtClassOrObjectInfo) {
                //noinspection RedundantCast
                return getClassDescriptor(((KtClassOrObjectInfo) classLikeInfo).getCorrespondingClassOrObject(), location);
            } else if (classLikeInfo instanceof KtScriptInfo) {
                return getScriptDescriptor(((KtScriptInfo) classLikeInfo).getScript());
            } else {
                throw new IllegalStateException("Unexpected " + classLikeInfo + " of type " + classLikeInfo.getClass().getName());
            }
        }
    }));
    result.addAll(ContainerUtil.map(provider.getTypeAliasDeclarations(fqName.shortName()), new Function<KtTypeAlias, ClassifierDescriptor>() {

        @Override
        public ClassifierDescriptor fun(KtTypeAlias alias) {
            return (ClassifierDescriptor) lazyDeclarationResolver.resolveToDescriptor(alias);
        }
    }));
    return result;
}
Also used : Function(com.intellij.util.Function) KtClassLikeInfo(org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo) PackageMemberDeclarationProvider(org.jetbrains.kotlin.resolve.lazy.declarations.PackageMemberDeclarationProvider) KtScriptInfo(org.jetbrains.kotlin.resolve.lazy.data.KtScriptInfo) SmartList(org.jetbrains.kotlin.utils.SmartList) KtClassOrObjectInfo(org.jetbrains.kotlin.resolve.lazy.data.KtClassOrObjectInfo) ReadOnly(org.jetbrains.annotations.ReadOnly) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with KtClassLikeInfo

use of org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo in project kotlin by JetBrains.

the class LazyClassDescriptor method computeCompanionObjectDescriptor.

@Nullable
private ClassDescriptorWithResolutionScopes computeCompanionObjectDescriptor(@Nullable KtObjectDeclaration companionObject) {
    if (companionObject == null)
        return createSyntheticCompanionObjectDescriptor();
    KtClassLikeInfo companionObjectInfo = getCompanionObjectInfo(companionObject);
    if (!(companionObjectInfo instanceof KtClassOrObjectInfo)) {
        return null;
    }
    Name name = ((KtClassOrObjectInfo) companionObjectInfo).getName();
    assert name != null;
    getUnsubstitutedMemberScope().getContributedClassifier(name, NoLookupLocation.WHEN_GET_COMPANION_OBJECT);
    ClassDescriptor companionObjectDescriptor = c.getTrace().get(BindingContext.CLASS, companionObject);
    if (companionObjectDescriptor instanceof ClassDescriptorWithResolutionScopes) {
        assert DescriptorUtils.isCompanionObject(companionObjectDescriptor) : "Not a companion object: " + companionObjectDescriptor;
        return (ClassDescriptorWithResolutionScopes) companionObjectDescriptor;
    } else {
        return null;
    }
}
Also used : KtClassLikeInfo(org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo) KtClassOrObjectInfo(org.jetbrains.kotlin.resolve.lazy.data.KtClassOrObjectInfo) Name(org.jetbrains.kotlin.name.Name) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

KtClassLikeInfo (org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo)2 KtClassOrObjectInfo (org.jetbrains.kotlin.resolve.lazy.data.KtClassOrObjectInfo)2 Function (com.intellij.util.Function)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 ReadOnly (org.jetbrains.annotations.ReadOnly)1 Name (org.jetbrains.kotlin.name.Name)1 KtScriptInfo (org.jetbrains.kotlin.resolve.lazy.data.KtScriptInfo)1 PackageMemberDeclarationProvider (org.jetbrains.kotlin.resolve.lazy.declarations.PackageMemberDeclarationProvider)1 SmartList (org.jetbrains.kotlin.utils.SmartList)1