コード例 #1
0
 @NotNull
 public static SimpleFunctionDescriptor createEnumValueOfMethod(
     @NotNull ClassDescriptor enumClass) {
   SimpleFunctionDescriptorImpl valueOf =
       SimpleFunctionDescriptorImpl.create(
           enumClass,
           Annotations.Companion.getEMPTY(),
           DescriptorUtils.ENUM_VALUE_OF,
           CallableMemberDescriptor.Kind.SYNTHESIZED,
           enumClass.getSource());
   ValueParameterDescriptor parameterDescriptor =
       new ValueParameterDescriptorImpl(
           valueOf,
           null,
           0,
           Annotations.Companion.getEMPTY(),
           Name.identifier("value"),
           getBuiltIns(enumClass).getStringType(),
           /* declaresDefaultValue = */ false,
           /* isCrossinline = */ false,
           /* isNoinline = */ false,
           null,
           enumClass.getSource());
   return valueOf.initialize(
       null,
       null,
       Collections.<TypeParameterDescriptor>emptyList(),
       Collections.singletonList(parameterDescriptor),
       enumClass.getDefaultType(),
       Modality.FINAL,
       Visibilities.PUBLIC);
 }
コード例 #2
0
  @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;
  }
コード例 #3
0
ファイル: DescriptorFactory.java プロジェクト: rlugojr/kotlin
 @NotNull
 public static SimpleFunctionDescriptor createEnumValuesMethod(
     @NotNull ClassDescriptor enumClass) {
   SimpleFunctionDescriptorImpl values =
       SimpleFunctionDescriptorImpl.create(
           enumClass,
           Annotations.Companion.getEMPTY(),
           DescriptorUtils.ENUM_VALUES,
           CallableMemberDescriptor.Kind.SYNTHESIZED,
           enumClass.getSource());
   return values.initialize(
       null,
       null,
       Collections.<TypeParameterDescriptor>emptyList(),
       Collections.<ValueParameterDescriptor>emptyList(),
       getBuiltIns(enumClass).getArrayType(Variance.INVARIANT, enumClass.getDefaultType()),
       Modality.FINAL,
       Visibilities.PUBLIC);
 }
コード例 #4
0
  @NotNull
  public static SimpleFunctionDescriptor createEnumValuesMethod(
      @NotNull ClassDescriptor enumClass) {
    AnnotationsImpl annotations =
        AnnotationsImpl.createWithNoTarget(
            AnnotationUtilKt.createDeprecatedAnnotation(
                getBuiltIns(enumClass), "Use 'values' property instead", "this.values"));

    SimpleFunctionDescriptorImpl values =
        SimpleFunctionDescriptorImpl.create(
            enumClass,
            annotations,
            DescriptorUtils.ENUM_VALUES,
            CallableMemberDescriptor.Kind.SYNTHESIZED,
            enumClass.getSource());
    return values.initialize(
        null,
        null,
        Collections.<TypeParameterDescriptor>emptyList(),
        Collections.<ValueParameterDescriptor>emptyList(),
        getBuiltIns(enumClass).getArrayType(Variance.INVARIANT, enumClass.getDefaultType()),
        Modality.FINAL,
        Visibilities.PUBLIC);
  }