示例#1
0
 @Nullable
 public static Visibility findMaxVisibility(
     @NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
   if (descriptors.isEmpty()) {
     return Visibilities.DEFAULT_VISIBILITY;
   }
   Visibility maxVisibility = null;
   for (CallableMemberDescriptor descriptor : descriptors) {
     Visibility visibility = descriptor.getVisibility();
     assert visibility != Visibilities.INHERITED
         : "Visibility should have been computed for " + descriptor;
     if (maxVisibility == null) {
       maxVisibility = visibility;
       continue;
     }
     Integer compareResult = Visibilities.compare(visibility, maxVisibility);
     if (compareResult == null) {
       maxVisibility = null;
     } else if (compareResult > 0) {
       maxVisibility = visibility;
     }
   }
   if (maxVisibility == null) {
     return null;
   }
   for (CallableMemberDescriptor descriptor : descriptors) {
     Integer compareResult = Visibilities.compare(maxVisibility, descriptor.getVisibility());
     if (compareResult == null || compareResult < 0) {
       return null;
     }
   }
   return maxVisibility;
 }
示例#2
0
 @Nullable
 private static Visibility findMaxVisibility(
     @NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
   if (descriptors.isEmpty()) {
     return Visibilities.INTERNAL;
   }
   Visibility maxVisibility = null;
   for (CallableMemberDescriptor descriptor : descriptors) {
     Visibility visibility = descriptor.getVisibility();
     assert visibility != Visibilities.INHERITED
         : "Visibility should have been computed for " + descriptor;
     if (maxVisibility == null) {
       maxVisibility = visibility;
       continue;
     }
     Integer compareResult = Visibilities.compare(visibility, maxVisibility);
     if (compareResult == null) {
       maxVisibility = null;
     } else if (compareResult > 0) {
       maxVisibility = visibility;
     }
   }
   // TODO: IDEA seems to issue an incorrect warning here
   //noinspection ConstantConditions
   if (maxVisibility == null) {
     return null;
   }
   for (CallableMemberDescriptor descriptor : descriptors) {
     Integer compareResult = Visibilities.compare(maxVisibility, descriptor.getVisibility());
     if (compareResult == null || compareResult < 0) {
       return null;
     }
   }
   return maxVisibility;
 }
示例#3
0
  public static void resolveUnknownVisibilityForMember(
      @NotNull CallableMemberDescriptor memberDescriptor,
      @Nullable Function1<CallableMemberDescriptor, Unit> cannotInferVisibility) {
    for (CallableMemberDescriptor descriptor : memberDescriptor.getOverriddenDescriptors()) {
      if (descriptor.getVisibility() == Visibilities.INHERITED) {
        resolveUnknownVisibilityForMember(descriptor, cannotInferVisibility);
      }
    }

    if (memberDescriptor.getVisibility() != Visibilities.INHERITED) {
      return;
    }

    Visibility maxVisibility = computeVisibilityToInherit(memberDescriptor);
    Visibility visibilityToInherit;
    if (maxVisibility == null) {
      if (cannotInferVisibility != null) {
        cannotInferVisibility.invoke(memberDescriptor);
      }
      visibilityToInherit = Visibilities.PUBLIC;
    } else {
      visibilityToInherit = maxVisibility;
    }

    if (memberDescriptor instanceof PropertyDescriptorImpl) {
      ((PropertyDescriptorImpl) memberDescriptor).setVisibility(visibilityToInherit);
      for (PropertyAccessorDescriptor accessor :
          ((PropertyDescriptor) memberDescriptor).getAccessors()) {
        // If we couldn't infer visibility for property, the diagnostic is already reported, no need
        // to report it again on accessors
        resolveUnknownVisibilityForMember(
            accessor, maxVisibility == null ? null : cannotInferVisibility);
      }
    } else if (memberDescriptor instanceof FunctionDescriptorImpl) {
      ((FunctionDescriptorImpl) memberDescriptor).setVisibility(visibilityToInherit);
    } else {
      assert memberDescriptor instanceof PropertyAccessorDescriptorImpl;
      ((PropertyAccessorDescriptorImpl) memberDescriptor).setVisibility(visibilityToInherit);
    }
  }
示例#4
0
 private void checkDeclaredTypeInPublicMember(
     JetNamedDeclaration member, CallableMemberDescriptor memberDescriptor) {
   boolean hasDeferredType;
   if (member instanceof JetProperty) {
     hasDeferredType =
         ((JetProperty) member).getTypeReference() == null
             && DescriptorResolver.hasBody((JetProperty) member);
   } else {
     assert member instanceof JetFunction;
     JetFunction function = (JetFunction) member;
     hasDeferredType =
         function.getTypeReference() == null && function.hasBody() && !function.hasBlockBody();
   }
   if ((memberDescriptor.getVisibility().isPublicAPI())
       && memberDescriptor.getOverriddenDescriptors().size() == 0
       && hasDeferredType) {
     trace.report(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE.on(member));
   }
 }
示例#5
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();
 }