Search in sources :

Example 1 with KotlinJavascriptPackageFragment

use of org.jetbrains.kotlin.serialization.js.KotlinJavascriptPackageFragment in project kotlin by JetBrains.

the class AnnotationsUtils method getContainingFileAnnotations.

@NotNull
public static List<AnnotationDescriptor> getContainingFileAnnotations(@NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor descriptor) {
    PackageFragmentDescriptor containingPackage = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor.class, false);
    if (containingPackage instanceof KotlinJavascriptPackageFragment) {
        return ((KotlinJavascriptPackageFragment) containingPackage).getContainingFileAnnotations(descriptor);
    }
    KtFile kotlinFile = getFile(descriptor);
    if (kotlinFile != null) {
        List<AnnotationDescriptor> annotations = new ArrayList<AnnotationDescriptor>();
        for (KtAnnotationEntry psiAnnotation : kotlinFile.getAnnotationEntries()) {
            AnnotationDescriptor annotation = bindingContext.get(BindingContext.ANNOTATION, psiAnnotation);
            if (annotation != null) {
                annotations.add(annotation);
            }
        }
        return annotations;
    }
    return Collections.emptyList();
}
Also used : AnnotationDescriptor(org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor) KtAnnotationEntry(org.jetbrains.kotlin.psi.KtAnnotationEntry) KotlinJavascriptPackageFragment(org.jetbrains.kotlin.serialization.js.KotlinJavascriptPackageFragment) ArrayList(java.util.ArrayList) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 AnnotationDescriptor (org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor)1 KtAnnotationEntry (org.jetbrains.kotlin.psi.KtAnnotationEntry)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 KotlinJavascriptPackageFragment (org.jetbrains.kotlin.serialization.js.KotlinJavascriptPackageFragment)1