boolean (@NotNull PsiVariable variable, @NotNull PsiElement element) { if (element instanceof PsiAssignmentExpression assignmentExpression) { PsiExpression lExpression = assignmentExpression.getLExpression(); if (lExpression instanceof PsiReferenceExpression ref && ref.resolve() == variable) return true; } else if (PsiUtil.isIncrementDecrementOperation(element)) { PsiElement operand = ((PsiUnaryExpression) element).getOperand(); if (operand instanceof PsiReferenceExpression ref && ref.resolve() == variable) return true; } PsiElement[] children = element.getChildren(); for (PsiElement child : children) { if (writtenInside(variable, child)) return true; } return false; }