use of org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor 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);
}
use of org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor in project kotlin by JetBrains.
the class AnnotationsUtils method isFromNonModuleFile.
public static boolean isFromNonModuleFile(@NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor declaration) {
for (AnnotationDescriptor annotation : getContainingFileAnnotations(bindingContext, declaration)) {
DeclarationDescriptor annotationType = annotation.getType().getConstructor().getDeclarationDescriptor();
if (annotationType == null)
continue;
DeclarationDescriptor annotationTypeDescriptor = annotation.getType().getConstructor().getDeclarationDescriptor();
assert annotationTypeDescriptor != null : "Annotation type should have descriptor: " + annotation.getType();
FqNameUnsafe fqName = DescriptorUtils.getFqName(annotationTypeDescriptor);
if (fqName.equals(JS_NON_MODULE_ANNOTATION.toUnsafe())) {
return true;
}
}
return false;
}
use of org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor in project kotlin by JetBrains.
the class AnnotationsUtils method getAnnotationStringParameter.
@Nullable
private static String getAnnotationStringParameter(@NotNull DeclarationDescriptor declarationDescriptor, @NotNull PredefinedAnnotation annotation) {
AnnotationDescriptor annotationDescriptor = getAnnotationByName(declarationDescriptor, annotation);
assert annotationDescriptor != null;
//TODO: this is a quick fix for unsupported default args problem
if (annotationDescriptor.getAllValueArguments().isEmpty()) {
return null;
}
ConstantValue<?> constant = annotationDescriptor.getAllValueArguments().values().iterator().next();
//TODO: this is a quick fix for unsupported default args problem
if (constant == null) {
return null;
}
Object value = constant.getValue();
assert value instanceof String : "Native function annotation should have one String parameter";
return (String) value;
}
use of org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor in project kotlin by JetBrains.
the class AnnotationsUtils method getSingleStringAnnotationArgument.
@Nullable
private static String getSingleStringAnnotationArgument(@NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor declaration, @NotNull FqName annotationFqName) {
for (AnnotationDescriptor annotation : getContainingFileAnnotations(bindingContext, declaration)) {
DeclarationDescriptor annotationType = annotation.getType().getConstructor().getDeclarationDescriptor();
if (annotationType == null)
continue;
FqNameUnsafe fqName = DescriptorUtils.getFqName(annotation.getType().getConstructor().getDeclarationDescriptor());
if (fqName.equals(annotationFqName.toUnsafe())) {
return extractSingleStringArgument(annotation);
}
}
return null;
}
Aggregations