@Nullable public static ReceiverParameterDescriptor getDispatchReceiverParameterIfNeeded( @NotNull DeclarationDescriptor containingDeclaration) { if (containingDeclaration instanceof ClassDescriptor) { ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration; return classDescriptor.getThisAsReceiverParameter(); } return null; }
public static boolean isDirectSubclass( @NotNull ClassDescriptor subClass, @NotNull ClassDescriptor superClass) { for (KotlinType superType : subClass.getTypeConstructor().getSupertypes()) { if (isSameClass(superType, superClass.getOriginal())) { return true; } } return false; }
@Nullable public static ClassDescriptor getSuperClassDescriptor(@NotNull ClassDescriptor classDescriptor) { Collection<KotlinType> superclassTypes = classDescriptor.getTypeConstructor().getSupertypes(); for (KotlinType type : superclassTypes) { ClassDescriptor superClassDescriptor = getClassDescriptorForType(type); if (superClassDescriptor.getKind() != ClassKind.INTERFACE) { return superClassDescriptor; } } return null; }
@NotNull public static KotlinType getSuperClassType(@NotNull ClassDescriptor classDescriptor) { Collection<KotlinType> superclassTypes = classDescriptor.getTypeConstructor().getSupertypes(); for (KotlinType type : superclassTypes) { ClassDescriptor superClassDescriptor = getClassDescriptorForType(type); if (superClassDescriptor.getKind() != ClassKind.INTERFACE) { return type; } } return getBuiltIns(classDescriptor).getAnyType(); }
@NotNull public static List<ClassDescriptor> getSuperclassDescriptors( @NotNull ClassDescriptor classDescriptor) { Collection<KotlinType> superclassTypes = classDescriptor.getTypeConstructor().getSupertypes(); List<ClassDescriptor> superClassDescriptors = new ArrayList<ClassDescriptor>(); for (KotlinType type : superclassTypes) { ClassDescriptor result = getClassDescriptorForType(type); if (!isAny(result)) { superClassDescriptors.add(result); } } return superClassDescriptors; }
@NotNull public static Visibility getDefaultConstructorVisibility( @NotNull ClassDescriptor classDescriptor) { ClassKind classKind = classDescriptor.getKind(); if (classKind == ClassKind.ENUM_CLASS || classKind.isSingleton() || isSealedClass(classDescriptor)) { return Visibilities.PRIVATE; } if (isAnonymousObject(classDescriptor)) { return Visibilities.DEFAULT_VISIBILITY; } assert classKind == ClassKind.CLASS || classKind == ClassKind.INTERFACE || classKind == ClassKind.ANNOTATION_CLASS; return Visibilities.PUBLIC; }
// TODO: should be internal @Nullable public static ClassDescriptor getInnerClassByName( @NotNull ClassDescriptor classDescriptor, @NotNull String innerClassName, @NotNull LookupLocation location) { ClassifierDescriptor classifier = classDescriptor .getDefaultType() .getMemberScope() .getContributedClassifier(Name.identifier(innerClassName), location); assert classifier instanceof ClassDescriptor : "Inner class " + innerClassName + " in " + classDescriptor + " should be instance of ClassDescriptor, but was: " + (classifier == null ? "null" : classifier.getClass()); return (ClassDescriptor) classifier; }
public static boolean isSingletonOrAnonymousObject(@NotNull ClassDescriptor classDescriptor) { return classDescriptor.getKind().isSingleton() || isAnonymousObject(classDescriptor); }
public static boolean classCanHaveOpenMembers(@NotNull ClassDescriptor classDescriptor) { return classDescriptor.getModality() != Modality.FINAL || classDescriptor.getKind() == ClassKind.ENUM_CLASS; }
public static boolean classCanHaveAbstractMembers(@NotNull ClassDescriptor classDescriptor) { return classDescriptor.getModality() == Modality.ABSTRACT || isSealedClass(classDescriptor) || classDescriptor.getKind() == ClassKind.ENUM_CLASS; }
/** @return true iff {@code descriptor}'s first non-class container is a package */ public static boolean isTopLevelOrInnerClass(@NotNull ClassDescriptor descriptor) { DeclarationDescriptor containing = descriptor.getContainingDeclaration(); return isTopLevelDeclaration(descriptor) || containing instanceof ClassDescriptor && isTopLevelOrInnerClass((ClassDescriptor) containing); }
public static boolean isSubclass( @NotNull ClassDescriptor subClass, @NotNull ClassDescriptor superClass) { return isSubtypeOfClass(subClass.getDefaultType(), superClass.getOriginal()); }