Esempio 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);
  }
Esempio n. 2
0
  @Nullable
  public static String getJvmName(@NotNull Annotated annotated) {
    AnnotationDescriptor jvmNameAnnotation =
        getAnnotationByFqName(annotated.getAnnotations(), JVM_NAME);
    if (jvmNameAnnotation == null) return null;

    Map<ValueParameterDescriptor, ConstantValue<?>> arguments =
        jvmNameAnnotation.getAllValueArguments();
    if (arguments.isEmpty()) return null;

    ConstantValue<?> name = arguments.values().iterator().next();
    if (!(name instanceof StringValue)) return null;

    return ((StringValue) name).getValue();
  }