void (String annotationFqn, Project project, BiConsumer<? super PsiModifierListOwner, ? super PsiAnnotation> consumer) { Collection<PsiAnnotation> annotations = ReadAction.compute( () -> JavaAnnotationIndex.getInstance().getAnnotations(StringUtil.getShortName(annotationFqn), project, GlobalSearchScope.allScope(project))); annotations.forEach(annotation -> ReadAction.run(() -> { if (!annotation.isValid()) return; PsiElement parent = annotation.getContext(); if (parent instanceof PsiModifierList) { PsiElement owner = parent.getParent(); if (owner instanceof PsiModifierListOwner && annotationFqn.equals(annotation.getQualifiedName())) { consumer.accept((PsiModifierListOwner)owner, annotation); } } })); }