示例#1
0
 @NotNull
 private static Modality getMinimalModality(
     @NotNull Collection<CallableMemberDescriptor> descriptors) {
   Modality modality = Modality.ABSTRACT;
   for (CallableMemberDescriptor descriptor : descriptors) {
     if (descriptor.getModality().compareTo(modality) < 0) {
       modality = descriptor.getModality();
     }
   }
   return modality;
 }
示例#2
0
  @NotNull
  private static Modality determineModality(
      @NotNull Collection<CallableMemberDescriptor> descriptors) {
    // Optimization: avoid creating hash sets in frequent cases when modality can be computed
    // trivially
    boolean hasOpen = false;
    boolean hasAbstract = false;
    for (CallableMemberDescriptor descriptor : descriptors) {
      switch (descriptor.getModality()) {
        case FINAL:
          return Modality.FINAL;
        case SEALED:
          throw new IllegalStateException("Member cannot have SEALED modality: " + descriptor);
        case OPEN:
          hasOpen = true;
          break;
        case ABSTRACT:
          hasAbstract = true;
          break;
      }
    }

    if (hasOpen && !hasAbstract) return Modality.OPEN;
    if (!hasOpen && hasAbstract) return Modality.ABSTRACT;

    Set<CallableMemberDescriptor> allOverriddenDeclarations =
        new HashSet<CallableMemberDescriptor>();
    for (CallableMemberDescriptor descriptor : descriptors) {
      allOverriddenDeclarations.addAll(getOverriddenDeclarations(descriptor));
    }
    return getMinimalModality(filterOutOverridden(allOverriddenDeclarations));
  }
示例#3
0
 @Nullable
 private static Visibility computeVisibilityToInherit(
     @NotNull CallableMemberDescriptor memberDescriptor) {
   Collection<? extends CallableMemberDescriptor> overriddenDescriptors =
       memberDescriptor.getOverriddenDescriptors();
   Visibility maxVisibility = findMaxVisibility(overriddenDescriptors);
   if (maxVisibility == null) {
     return null;
   }
   if (memberDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
     for (CallableMemberDescriptor overridden : overriddenDescriptors) {
       // An implementation (a non-abstract overridden member) of a fake override should have the
       // maximum possible visibility
       if (overridden.getModality() != Modality.ABSTRACT
           && !overridden.getVisibility().equals(maxVisibility)) {
         return null;
       }
     }
     return maxVisibility;
   }
   return maxVisibility.normalize();
 }