use of org.jetbrains.kotlin.resolve.scopes.MemberScope in project kotlin by JetBrains.
the class ClosureCodegen method getErasedInvokeFunction.
@NotNull
public static FunctionDescriptor getErasedInvokeFunction(@NotNull FunctionDescriptor function) {
ClassDescriptor functionClass = DescriptorUtilsKt.getBuiltIns(function).getFunction(function.getValueParameters().size() + (function.getExtensionReceiverParameter() != null ? 1 : 0));
MemberScope scope = functionClass.getDefaultType().getMemberScope();
return scope.getContributedFunctions(OperatorNameConventions.INVOKE, NoLookupLocation.FROM_BACKEND).iterator().next();
}
use of org.jetbrains.kotlin.resolve.scopes.MemberScope in project kotlin by JetBrains.
the class AbstractAnnotationDescriptorResolveTest method getPropertyDescriptor.
@NotNull
private static PropertyDescriptor getPropertyDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name propertyName = Name.identifier(name);
MemberScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
Collection<PropertyDescriptor> properties = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + classDescriptor.getName();
return properties.iterator().next();
}
use of org.jetbrains.kotlin.resolve.scopes.MemberScope in project kotlin by JetBrains.
the class RecursiveDescriptorComparator method appendDeclarationRecursively.
private void appendDeclarationRecursively(@NotNull DeclarationDescriptor descriptor, @NotNull ModuleDescriptor module, @NotNull Printer printer, boolean topLevel) {
if (!isFromModule(descriptor, module))
return;
boolean isEnumEntry = isEnumEntry(descriptor);
boolean isClassOrPackage = (descriptor instanceof ClassOrPackageFragmentDescriptor || descriptor instanceof PackageViewDescriptor) && !isEnumEntry;
if (isClassOrPackage && !topLevel) {
printer.println();
}
boolean isPrimaryConstructor = descriptor instanceof ConstructorDescriptor && ((ConstructorDescriptor) descriptor).isPrimary();
printer.print(isPrimaryConstructor && conf.checkPrimaryConstructors ? "/*primary*/ " : "", conf.renderer.render(descriptor));
if (isClassOrPackage) {
if (!topLevel) {
printer.printlnWithNoIndent(" {").pushIndent();
} else {
printer.println();
printer.println();
}
if (descriptor instanceof ClassDescriptor) {
ClassDescriptor klass = (ClassDescriptor) descriptor;
appendSubDescriptors(descriptor, module, klass.getDefaultType().getMemberScope(), klass.getConstructors(), printer);
MemberScope staticScope = klass.getStaticScope();
if (!DescriptorUtils.getAllDescriptors(staticScope).isEmpty()) {
printer.println();
printer.println("// Static members");
appendSubDescriptors(descriptor, module, staticScope, Collections.<DeclarationDescriptor>emptyList(), printer);
}
} else if (descriptor instanceof PackageFragmentDescriptor) {
appendSubDescriptors(descriptor, module, ((PackageFragmentDescriptor) descriptor).getMemberScope(), Collections.<DeclarationDescriptor>emptyList(), printer);
} else if (descriptor instanceof PackageViewDescriptor) {
appendSubDescriptors(descriptor, module, getPackageScopeInModule((PackageViewDescriptor) descriptor, module), Collections.<DeclarationDescriptor>emptyList(), printer);
}
if (!topLevel) {
printer.popIndent().println("}");
}
} else if (conf.checkPropertyAccessors && descriptor instanceof PropertyDescriptor) {
printer.printlnWithNoIndent();
printer.pushIndent();
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
if (getter != null) {
printer.println(conf.renderer.render(getter));
}
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
if (setter != null) {
printer.println(conf.renderer.render(setter));
}
printer.popIndent();
} else {
printer.printlnWithNoIndent();
}
if (isEnumEntry) {
printer.println();
}
}
use of org.jetbrains.kotlin.resolve.scopes.MemberScope in project kotlin by JetBrains.
the class LazyDeclarationResolver method findClassDescriptor.
@NotNull
private ClassDescriptor findClassDescriptor(@NotNull KtNamedDeclaration classObjectOrScript, @NotNull LookupLocation location) {
MemberScope scope = getMemberScopeDeclaredIn(classObjectOrScript, location);
// Why not use the result here. Because it may be that there is a redeclaration:
// class A {} class A { fun foo(): A<completion here>}
// and if we find the class by name only, we may b-not get the right one.
// This call is only needed to make sure the classes are written to trace
ClassifierDescriptor scopeDescriptor = scope.getContributedClassifier(classObjectOrScript.getNameAsSafeName(), location);
DeclarationDescriptor descriptor = getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, classObjectOrScript);
if (descriptor == null) {
throw new IllegalArgumentException(String.format("Could not find a classifier for %s.\n" + "Found descriptor: %s (%s).\n", PsiUtilsKt.getElementTextWithContext(classObjectOrScript), scopeDescriptor != null ? DescriptorRenderer.DEBUG_TEXT.render(scopeDescriptor) : "null", scopeDescriptor != null ? (scopeDescriptor.getContainingDeclaration().getClass()) : null));
}
return (ClassDescriptor) descriptor;
}
use of org.jetbrains.kotlin.resolve.scopes.MemberScope in project kotlin by JetBrains.
the class CommonSupertypes method computeSupertypeProjections.
// constructor - type constructor of a supertype to be instantiated
// types - instantiations of constructor occurring as supertypes of classes we are trying to intersect
@NotNull
private static SimpleType computeSupertypeProjections(@NotNull TypeConstructor constructor, @NotNull Set<SimpleType> types, int recursionDepth, int maxDepth) {
assert !types.isEmpty();
if (types.size() == 1) {
return types.iterator().next();
}
List<TypeParameterDescriptor> parameters = constructor.getParameters();
List<TypeProjection> newProjections = new ArrayList<TypeProjection>(parameters.size());
for (TypeParameterDescriptor parameterDescriptor : parameters) {
Set<TypeProjection> typeProjections = new HashSet<TypeProjection>();
for (KotlinType type : types) {
typeProjections.add(type.getArguments().get(parameterDescriptor.getIndex()));
}
newProjections.add(computeSupertypeProjection(parameterDescriptor, typeProjections, recursionDepth, maxDepth));
}
boolean nullable = false;
for (KotlinType type : types) {
nullable |= type.isMarkedNullable();
}
ClassifierDescriptor classifier = constructor.getDeclarationDescriptor();
MemberScope newScope;
if (classifier instanceof ClassDescriptor) {
newScope = ((ClassDescriptor) classifier).getMemberScope(newProjections);
} else if (classifier instanceof TypeParameterDescriptor) {
newScope = classifier.getDefaultType().getMemberScope();
} else {
newScope = ErrorUtils.createErrorScope("A scope for common supertype which is not a normal classifier", true);
}
return KotlinTypeFactory.simpleType(Annotations.Companion.getEMPTY(), constructor, newProjections, nullable, newScope);
}
Aggregations