Search in sources :

Example 1 with ArrayValue

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);
}
Also used : AnnotationDescriptor(org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor) JavaClassDescriptor(org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor) FqName(org.jetbrains.kotlin.name.FqName) KClassValue(org.jetbrains.kotlin.resolve.constants.KClassValue) ConstantValue(org.jetbrains.kotlin.resolve.constants.ConstantValue) ArrayValue(org.jetbrains.kotlin.resolve.constants.ArrayValue) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 AnnotationDescriptor (org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor)1 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)1 FqName (org.jetbrains.kotlin.name.FqName)1 ArrayValue (org.jetbrains.kotlin.resolve.constants.ArrayValue)1 ConstantValue (org.jetbrains.kotlin.resolve.constants.ConstantValue)1 KClassValue (org.jetbrains.kotlin.resolve.constants.KClassValue)1