Search in sources :

Example 1 with KtScriptInfo

use of org.jetbrains.kotlin.resolve.lazy.data.KtScriptInfo 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)

Aggregations

Function (com.intellij.util.Function)1 NotNull (org.jetbrains.annotations.NotNull)1 ReadOnly (org.jetbrains.annotations.ReadOnly)1 KtClassLikeInfo (org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo)1 KtClassOrObjectInfo (org.jetbrains.kotlin.resolve.lazy.data.KtClassOrObjectInfo)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