@Nullable private PsiVariable findPreviousVariable() { PsiElement scope = myVariable.getParent(); while (scope != null) { if (scope instanceof PsiFile || scope instanceof PsiMethod || scope instanceof PsiClassInitializer) break; scope = scope.getParent(); } if (scope == null) return null; PsiIdentifier nameIdentifier = myVariable.getNameIdentifier(); if (nameIdentifier == null) { return null; } final VariablesNotProcessor processor = new VariablesNotProcessor(myVariable, false); PsiScopesUtil.treeWalkUp(processor, nameIdentifier, scope); return processor.size() > 0 ? processor.getResult(0) : null; }