Exemplo n.º 1
0
  @NotNull
  public static String[] getThrownExceptions(
      @NotNull FunctionDescriptor function, @NotNull final JetTypeMapper mapper) {
    AnnotationDescriptor annotation =
        function.getAnnotations().findAnnotation(new FqName("kotlin.throws"));
    if (annotation == null) {
      annotation = function.getAnnotations().findAnnotation(new FqName("kotlin.jvm.Throws"));
    }

    if (annotation == null) return ArrayUtil.EMPTY_STRING_ARRAY;

    Collection<ConstantValue<?>> values = annotation.getAllValueArguments().values();
    if (values.isEmpty()) return ArrayUtil.EMPTY_STRING_ARRAY;

    Object value = values.iterator().next();
    if (!(value instanceof ArrayValue)) return ArrayUtil.EMPTY_STRING_ARRAY;
    ArrayValue arrayValue = (ArrayValue) value;

    List<String> strings =
        ContainerUtil.mapNotNull(
            arrayValue.getValue(),
            new Function<ConstantValue<?>, String>() {
              @Override
              public String fun(ConstantValue<?> constant) {
                if (constant instanceof KClassValue) {
                  KClassValue classValue = (KClassValue) constant;
                  ClassDescriptor classDescriptor =
                      DescriptorUtils.getClassDescriptorForType(classValue.getValue());
                  return mapper.mapClass(classDescriptor).getInternalName();
                }
                return null;
              }
            });
    return ArrayUtil.toStringArray(strings);
  }
Exemplo n.º 2
0
  @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);
  }