PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitAssignmentExpression(@NotNull PsiAssignmentExpression expression) { checkSillyAssignment(expression, holder); } @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { visitElement(expression); } @Override public void visitVariable(final @NotNull PsiVariable variable) { final PsiExpression initializer = PsiUtil.deparenthesizeExpression(variable.getInitializer()); if (initializer instanceof PsiAssignmentExpression) { final PsiExpression lExpr = PsiUtil.deparenthesizeExpression(((PsiAssignmentExpression)initializer).getLExpression()); checkExpression(variable, lExpr); } else { checkExpression(variable, initializer); } } private void checkExpression(PsiVariable variable, PsiExpression expression) { if (!(expression instanceof PsiReferenceExpression refExpr)) { return; } final PsiExpression qualifier = refExpr.getQualifierExpression(); if ((qualifier == null || qualifier instanceof PsiQualifiedExpression || variable.hasModifierProperty(PsiModifier.STATIC)) && refExpr.isReferenceTo(variable)) { holder.registerProblem(refExpr, JavaBundle.message("assignment.to.declared.variable.problem.descriptor", variable.getName()), LocalQuickFix.notNullElements(createRemoveAssignmentFix(refExpr))); } } }; }