boolean (@NotNull final AnnotatedElementsSearch.Parameters p, @NotNull final Processor<? super PsiModifierListOwner> consumer) { final PsiClass annClass = p.getAnnotationClass(); if (!annClass.isAnnotationType()) throw new IllegalArgumentException("Annotation type should be passed to annotated members search but got: "+annClass); String annotationFQN = ReadAction.compute(() -> annClass.getQualifiedName()); if (annotationFQN == null) throw new IllegalArgumentException("FQN is null for "+annClass); final PsiManager psiManager = ReadAction.compute(() -> annClass.getManager()); final SearchScope useScope = p.getScope(); final Class<? extends PsiModifierListOwner>[] types = p.getTypes(); for (final PsiAnnotation ann : getAnnotationCandidates(annClass, useScope, psiManager.getProject())) { final PsiModifierListOwner candidate = ReadAction.compute(() -> { PsiElement parent = ann.getContext(); if (!(parent instanceof PsiModifierList)) { return null; // Can be a PsiNameValuePair, if annotation is used to annotate annotation parameters } final PsiElement owner = parent.getParent(); if (!isInstanceof(owner, types)) { return null; } if (p.isApproximate()) { return (PsiModifierListOwner)owner; } final PsiJavaCodeReferenceElement ref = ann.getNameReferenceElement(); if (ref == null || !psiManager.areElementsEquivalent(ref.resolve(), annClass)) { return null; } return (PsiModifierListOwner)owner; }); if (candidate != null && !consumer.process(candidate)) { return false; } } return true; }