PsiLocalVariable (@NotNull PsiAssignmentExpression assignmentExpression) { PsiExpression lExpression = PsiUtil.skipParenthesizedExprDown(assignmentExpression.getLExpression()); if (lExpression instanceof PsiReferenceExpression reference && !reference.isQualified() && // optimization: locals aren't qualified reference.resolve() instanceof PsiLocalVariable variable) { PsiDeclarationStatement declarationStatement = ObjectUtils.tryCast(variable.getParent(), PsiDeclarationStatement.class); PsiExpressionStatement expressionStatement = ObjectUtils.tryCast(assignmentExpression.getParent(), PsiExpressionStatement.class); if (declarationStatement != null && declarationStatement.getParent() instanceof PsiCodeBlock && expressionStatement != null && expressionStatement.getParent() == declarationStatement.getParent()) { return findOccurrence(expressionStatement, variable, PsiTreeUtil::skipWhitespacesAndCommentsBackward, (candidate, unused) -> candidate == declarationStatement ? variable : null); } } return null; }