PsiAnnotation (final PsiFile file) { if (!(file instanceof GroovyFile)) return null; return CachedValuesManager.getCachedValue(file, () -> { PsiClass grab = JavaPsiFacade.getInstance(file.getProject()).findClass(GrabAnnos.GRAB_ANNO, file.getResolveScope()); final Ref<PsiAnnotation> result = Ref.create(); if (grab != null) { ReferencesSearch.search(grab, new LocalSearchScope(file)).forEach(reference -> { if (reference instanceof GrCodeReferenceElement) { PsiElement parent = ((GrCodeReferenceElement)reference).getParent(); if (parent instanceof PsiAnnotation) { result.set((PsiAnnotation)parent); return false; } } return true; }); } return CachedValueProvider.Result.create(result.get(), file); }); }