void (final Map<PsiVariable, VariableInfo> variableInfoMap, PsiElement scope) { scope.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { if (expression.getQualifierExpression() == null) { PsiElement refElement = expression.resolve(); if (refElement instanceof PsiVariable var && !(refElement instanceof PsiField)) { final PsiClass containingClass = PsiTreeUtil.getParentOfType(var, PsiClass.class); if (PsiTreeUtil.isAncestor(containingClass, myAnonOrLocalClass, true)) { saveVariable(variableInfoMap, var, expression); } } } super.visitReferenceExpression(expression); } }); }