use of org.jetbrains.kotlin.resolve.constants.ArrayValue in project kotlin by JetBrains.
the class FunctionCodegen method getThrownExceptions.
@NotNull
public static String[] getThrownExceptions(@NotNull FunctionDescriptor function, @NotNull final KotlinTypeMapper 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);
}
Aggregations