예제 #1
0
 @Nullable
 public static ReceiverParameterDescriptor getDispatchReceiverParameterIfNeeded(
     @NotNull DeclarationDescriptor containingDeclaration) {
   if (containingDeclaration instanceof ClassDescriptor) {
     ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
     return classDescriptor.getThisAsReceiverParameter();
   }
   return null;
 }
예제 #2
0
 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;
 }
예제 #3
0
 @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;
 }
예제 #4
0
 @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();
 }
예제 #5
0
 @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;
 }
예제 #6
0
 @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;
 }
예제 #7
0
 // 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;
 }
예제 #8
0
 public static boolean isSingletonOrAnonymousObject(@NotNull ClassDescriptor classDescriptor) {
   return classDescriptor.getKind().isSingleton() || isAnonymousObject(classDescriptor);
 }
예제 #9
0
 public static boolean classCanHaveOpenMembers(@NotNull ClassDescriptor classDescriptor) {
   return classDescriptor.getModality() != Modality.FINAL
       || classDescriptor.getKind() == ClassKind.ENUM_CLASS;
 }
예제 #10
0
 public static boolean classCanHaveAbstractMembers(@NotNull ClassDescriptor classDescriptor) {
   return classDescriptor.getModality() == Modality.ABSTRACT
       || isSealedClass(classDescriptor)
       || classDescriptor.getKind() == ClassKind.ENUM_CLASS;
 }
예제 #11
0
 /** @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);
 }
예제 #12
0
 public static boolean isSubclass(
     @NotNull ClassDescriptor subClass, @NotNull ClassDescriptor superClass) {
   return isSubtypeOfClass(subClass.getDefaultType(), superClass.getOriginal());
 }