Search in sources :

Example 11 with MemberScope

use of org.jetbrains.kotlin.resolve.scopes.MemberScope in project kotlin by JetBrains.

the class ResolveSessionUtils method findClassByRelativePath.

@Nullable
public static ClassDescriptor findClassByRelativePath(@NotNull MemberScope packageScope, @NotNull FqName path) {
    if (path.isRoot())
        return null;
    MemberScope scope = packageScope;
    ClassifierDescriptor classifier = null;
    for (Name name : path.pathSegments()) {
        classifier = scope.getContributedClassifier(name, NoLookupLocation.WHEN_FIND_BY_FQNAME);
        if (!(classifier instanceof ClassDescriptor))
            return null;
        scope = ((ClassDescriptor) classifier).getUnsubstitutedInnerClassesScope();
    }
    return (ClassDescriptor) classifier;
}
Also used : ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) ClassifierDescriptor(org.jetbrains.kotlin.descriptors.ClassifierDescriptor) MemberScope(org.jetbrains.kotlin.resolve.scopes.MemberScope) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with MemberScope

use of org.jetbrains.kotlin.resolve.scopes.MemberScope in project kotlin by JetBrains.

the class JetTestFunctionDetector method getTestFunctions.

@NotNull
private static List<FunctionDescriptor> getTestFunctions(@NotNull BindingContext bindingContext, @NotNull List<KtDeclaration> declarations) {
    List<FunctionDescriptor> answer = Lists.newArrayList();
    for (KtDeclaration declaration : declarations) {
        MemberScope scope = null;
        if (declaration instanceof KtClass) {
            KtClass klass = (KtClass) declaration;
            ClassDescriptor classDescriptor = BindingUtils.getClassDescriptor(bindingContext, klass);
            if (classDescriptor.getModality() != Modality.ABSTRACT) {
                scope = classDescriptor.getDefaultType().getMemberScope();
            }
        }
        if (scope != null) {
            Collection<DeclarationDescriptor> allDescriptors = DescriptorUtils.getAllDescriptors(scope);
            List<FunctionDescriptor> testFunctions = ContainerUtil.mapNotNull(allDescriptors, new Function<DeclarationDescriptor, FunctionDescriptor>() {

                @Override
                public FunctionDescriptor fun(DeclarationDescriptor descriptor) {
                    if (descriptor instanceof FunctionDescriptor) {
                        FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
                        if (isTest(functionDescriptor))
                            return functionDescriptor;
                    }
                    return null;
                }
            });
            answer.addAll(testFunctions);
        }
    }
    return answer;
}
Also used : KtDeclaration(org.jetbrains.kotlin.psi.KtDeclaration) ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) KtClass(org.jetbrains.kotlin.psi.KtClass) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) MemberScope(org.jetbrains.kotlin.resolve.scopes.MemberScope) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MemberScope (org.jetbrains.kotlin.resolve.scopes.MemberScope)12 NotNull (org.jetbrains.annotations.NotNull)9 FqName (org.jetbrains.kotlin.name.FqName)5 Name (org.jetbrains.kotlin.name.Name)5 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)3 Nullable (org.jetbrains.annotations.Nullable)2 ClassifierDescriptor (org.jetbrains.kotlin.descriptors.ClassifierDescriptor)2 ChainedMemberScope (org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope)2 ArrayList (java.util.ArrayList)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 TypeParameterDescriptor (org.jetbrains.kotlin.descriptors.TypeParameterDescriptor)1 SubpackagesScope (org.jetbrains.kotlin.descriptors.impl.SubpackagesScope)1 KtClass (org.jetbrains.kotlin.psi.KtClass)1 KtDeclaration (org.jetbrains.kotlin.psi.KtDeclaration)1 TypeProjection (org.jetbrains.kotlin.types.TypeProjection)1