@NotNull
  public static PropertyDescriptor createEnumValuesProperty(@NotNull ClassDescriptor enumClass) {
    PropertyDescriptorImpl values =
        PropertyDescriptorImpl.create(
            enumClass,
            Annotations.Companion.getEMPTY(),
            Modality.FINAL,
            Visibilities.PUBLIC, /* isVar */
            false,
            DescriptorUtils.ENUM_VALUES,
            CallableMemberDescriptor.Kind.SYNTHESIZED,
            enumClass.getSource(),
            /* lateInit = */ false,
            /* isConst = */ false);

    KotlinType type =
        getBuiltIns(enumClass).getArrayType(Variance.INVARIANT, enumClass.getDefaultType());

    PropertyGetterDescriptorImpl getter =
        createDefaultGetter(values, Annotations.Companion.getEMPTY());

    values.initialize(getter, null);
    getter.initialize(type);
    values.setType(type, Collections.<TypeParameterDescriptor>emptyList(), null, (KotlinType) null);

    return values;
  }
Esempio n. 2
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);
    }
  }