Пример #1
0
  @NotNull
  private static Collection<CallableMemberDescriptor> extractMembersOverridableInBothWays(
      @NotNull CallableMemberDescriptor overrider,
      @NotNull Queue<CallableMemberDescriptor> extractFrom,
      @NotNull DescriptorSink sink) {
    Collection<CallableMemberDescriptor> overridable = new ArrayList<CallableMemberDescriptor>();
    overridable.add(overrider);
    for (Iterator<CallableMemberDescriptor> iterator = extractFrom.iterator();
        iterator.hasNext(); ) {
      CallableMemberDescriptor candidate = iterator.next();
      if (overrider == candidate) {
        iterator.remove();
        continue;
      }

      OverrideCompatibilityInfo.Result result1 =
          DEFAULT.isOverridableBy(candidate, overrider).getResult();
      OverrideCompatibilityInfo.Result result2 =
          DEFAULT.isOverridableBy(overrider, candidate).getResult();
      if (result1 == OVERRIDABLE && result2 == OVERRIDABLE) {
        overridable.add(candidate);
        iterator.remove();
      } else if (result1 == CONFLICT || result2 == CONFLICT) {
        sink.conflict(overrider, candidate);
        iterator.remove();
      }
    }
    return overridable;
  }
Пример #2
0
  private static Collection<CallableMemberDescriptor> extractAndBindOverridesForMember(
      @NotNull CallableMemberDescriptor fromCurrent,
      @NotNull Collection<? extends CallableMemberDescriptor> descriptorsFromSuper,
      @NotNull ClassDescriptor current,
      @NotNull DescriptorSink sink) {
    Collection<CallableMemberDescriptor> bound =
        new ArrayList<CallableMemberDescriptor>(descriptorsFromSuper.size());
    for (CallableMemberDescriptor fromSupertype : descriptorsFromSuper) {
      OverrideCompatibilityInfo.Result result =
          DEFAULT.isOverridableBy(fromSupertype, fromCurrent).getResult();

      boolean isVisible =
          Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, fromSupertype, current);
      switch (result) {
        case OVERRIDABLE:
          if (isVisible) {
            fromCurrent.addOverriddenDescriptor(fromSupertype);
          }
          bound.add(fromSupertype);
          break;
        case CONFLICT:
          if (isVisible) {
            sink.conflict(fromSupertype, fromCurrent);
          }
          bound.add(fromSupertype);
          break;
        case INCOMPATIBLE:
          break;
      }
    }
    return bound;
  }
Пример #3
0
  private static void createAndBindFakeOverride(
      @NotNull Collection<CallableMemberDescriptor> overridables,
      @NotNull ClassDescriptor current,
      @NotNull DescriptorSink sink) {
    Collection<CallableMemberDescriptor> visibleOverridables =
        filterVisibleFakeOverrides(current, overridables);
    boolean allInvisible = visibleOverridables.isEmpty();
    Collection<CallableMemberDescriptor> effectiveOverridden =
        allInvisible ? overridables : visibleOverridables;

    Modality modality = getMinimalModality(effectiveOverridden);
    Visibility visibility = allInvisible ? Visibilities.INVISIBLE_FAKE : Visibilities.INHERITED;
    CallableMemberDescriptor mostSpecific = selectMostSpecificMemberFromSuper(effectiveOverridden);
    CallableMemberDescriptor fakeOverride =
        mostSpecific.copy(
            current, modality, visibility, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
    for (CallableMemberDescriptor descriptor : effectiveOverridden) {
      fakeOverride.addOverriddenDescriptor(descriptor);
    }
    sink.addFakeOverride(fakeOverride);
  }