List<PsiVariable> (PsiElement scope) { final List<PsiVariable> result = new ArrayList<>(); scope.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { final PsiElement element = expression.resolve(); if (element instanceof PsiVariable) { result.add((PsiVariable)element); } final PsiExpression qualifier = expression.getQualifierExpression(); if (qualifier != null) { qualifier.accept(this); } } }); return result; }