Search in sources :

Example 6 with MemberScope

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

the class AbstractAnnotationDescriptorResolveTest method getFunctionDescriptor.

@NotNull
private static FunctionDescriptor getFunctionDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
    Name functionName = Name.identifier(name);
    MemberScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
    Collection<SimpleFunctionDescriptor> functions = memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST);
    assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + classDescriptor.getName();
    return functions.iterator().next();
}
Also used : MemberScope(org.jetbrains.kotlin.resolve.scopes.MemberScope) FqName(org.jetbrains.kotlin.name.FqName) Name(org.jetbrains.kotlin.name.Name) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with MemberScope

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

the class AbstractAnnotationDescriptorResolveTest method getInnerClassDescriptor.

@NotNull
private static ClassDescriptor getInnerClassDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
    Name propertyName = Name.identifier(name);
    MemberScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
    ClassifierDescriptor innerClass = memberScope.getContributedClassifier(propertyName, NoLookupLocation.FROM_TEST);
    assert innerClass instanceof ClassDescriptor : "Failed to find inner class " + propertyName + " in class " + classDescriptor.getName();
    return (ClassDescriptor) innerClass;
}
Also used : MemberScope(org.jetbrains.kotlin.resolve.scopes.MemberScope) FqName(org.jetbrains.kotlin.name.FqName) Name(org.jetbrains.kotlin.name.Name) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with MemberScope

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

the class AbstractAnnotationDescriptorResolveTest method getFunctionDescriptor.

@NotNull
protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
    Name functionName = Name.identifier(name);
    MemberScope memberScope = packageView.getMemberScope();
    Collection<SimpleFunctionDescriptor> functions = memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST);
    assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + packageView.getName();
    return functions.iterator().next();
}
Also used : MemberScope(org.jetbrains.kotlin.resolve.scopes.MemberScope) FqName(org.jetbrains.kotlin.name.FqName) Name(org.jetbrains.kotlin.name.Name) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with MemberScope

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

the class AbstractAnnotationDescriptorResolveTest method getPropertyDescriptor.

@Nullable
protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name, boolean failOnMissing) {
    Name propertyName = Name.identifier(name);
    MemberScope memberScope = packageView.getMemberScope();
    Collection<PropertyDescriptor> properties = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
    if (properties.isEmpty()) {
        for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(memberScope)) {
            if (descriptor instanceof ClassDescriptor) {
                Collection<PropertyDescriptor> classProperties = ((ClassDescriptor) descriptor).getMemberScope(Collections.<TypeProjection>emptyList()).getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
                if (!classProperties.isEmpty()) {
                    properties = classProperties;
                    break;
                }
            }
        }
    }
    if (failOnMissing) {
        assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + packageView.getName();
    } else if (properties.size() != 1) {
        return null;
    }
    return properties.iterator().next();
}
Also used : TypeProjection(org.jetbrains.kotlin.types.TypeProjection) MemberScope(org.jetbrains.kotlin.resolve.scopes.MemberScope) FqName(org.jetbrains.kotlin.name.FqName) Name(org.jetbrains.kotlin.name.Name) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with MemberScope

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

the class RecursiveDescriptorComparator method getPackageScopeInModule.

@NotNull
private MemberScope getPackageScopeInModule(@NotNull PackageViewDescriptor descriptor, @NotNull ModuleDescriptor module) {
    // See LazyPackageViewDescriptorImpl#memberScope
    List<MemberScope> scopes = new ArrayList<MemberScope>();
    for (PackageFragmentDescriptor fragment : descriptor.getFragments()) {
        if (isFromModule(fragment, module)) {
            scopes.add(fragment.getMemberScope());
        }
    }
    scopes.add(new SubpackagesScope(module, descriptor.getFqName()));
    return ChainedMemberScope.Companion.create("test", scopes);
}
Also used : ArrayList(java.util.ArrayList) MemberScope(org.jetbrains.kotlin.resolve.scopes.MemberScope) ChainedMemberScope(org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope) SubpackagesScope(org.jetbrains.kotlin.descriptors.impl.SubpackagesScope) 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