@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);
 }
  @Override
  protected void generateBody() {
    FunctionDescriptor erasedInterfaceFunction;
    if (samType == null) {
      erasedInterfaceFunction = getErasedInvokeFunction(funDescriptor);
    } else {
      erasedInterfaceFunction = samType.getAbstractMethod().getOriginal();
    }

    generateBridge(
        typeMapper.mapSignature(erasedInterfaceFunction).getAsmMethod(),
        typeMapper.mapSignature(funDescriptor).getAsmMethod());

    functionCodegen.generateMethod(OtherOrigin(element, funDescriptor), funDescriptor, strategy);

    // TODO: rewrite cause ugly hack
    if (samType != null) {
      SimpleFunctionDescriptorImpl descriptorForBridges =
          SimpleFunctionDescriptorImpl.create(
              funDescriptor.getContainingDeclaration(),
              funDescriptor.getAnnotations(),
              erasedInterfaceFunction.getName(),
              CallableMemberDescriptor.Kind.DECLARATION,
              funDescriptor.getSource());

      descriptorForBridges.initialize(
          null,
          erasedInterfaceFunction.getDispatchReceiverParameter(),
          erasedInterfaceFunction.getTypeParameters(),
          erasedInterfaceFunction.getValueParameters(),
          erasedInterfaceFunction.getReturnType(),
          Modality.OPEN,
          erasedInterfaceFunction.getVisibility());

      descriptorForBridges.addOverriddenDescriptor(erasedInterfaceFunction);
      functionCodegen.generateBridges(descriptorForBridges);
    }

    this.constructor = generateConstructor(superClassAsmType);

    if (isConst(closure)) {
      generateConstInstance();
    }

    genClosureFields(closure, v, typeMapper);

    functionCodegen.generateDefaultIfNeeded(
        context.intoFunction(funDescriptor),
        funDescriptor,
        context.getContextKind(),
        DefaultParameterValueLoader.DEFAULT,
        null);
  }
Beispiel #3
0
 @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);
 }
  @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);
  }