List<PsiReferenceExpression> (@NotNull PsiVariable variable, @Nullable PsiElement context) { if (context == null) return Collections.emptyList(); List<PsiReferenceExpression> result = new ArrayList<>(); PsiTreeUtil.processElements(context, e -> { if (e instanceof PsiReferenceExpression && ((PsiReferenceExpression)e).isReferenceTo(variable)) { result.add((PsiReferenceExpression)e); } return true; }); return result; }