PsiExpression[] (final PsiElement[] scopeElements, final PsiVariable variable) { final ArrayList<PsiExpression> result = new ArrayList<>(); for (final PsiElement element : scopeElements) { element.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(final @NotNull PsiReferenceExpression expression) { super.visitReferenceExpression(expression); if (!expression.isQualified() && expression.isReferenceTo(variable)) { result.add(expression); } } }); } return result.toArray(PsiExpression.EMPTY_ARRAY); }