void (ProblemReporter reporter, DataFlowInstructionVisitor visitor) { visitor.sameValueAssignments().forEach(expr -> { expr = PsiUtil.skipParenthesizedExprDown(expr); if (expr == null) return; PsiAssignmentExpression assignment = PsiTreeUtil.getParentOfType(expr, PsiAssignmentExpression.class); PsiElement context = PsiTreeUtil.getParentOfType(expr, PsiForStatement.class, PsiClassInitializer.class); if (context instanceof PsiForStatement && PsiTreeUtil.isAncestor(((PsiForStatement)context).getInitialization(), expr, true)) { return; } if (expr instanceof PsiReferenceExpression ref && ref.resolve() instanceof PsiField field) { // Final field assignment: even if redundant according to DFA model (e.g. this.field = null), // it's necessary due to language semantics if (field.hasModifierProperty(PsiModifier.FINAL)) return; if (context instanceof PsiClassInitializer) { if (assignment != null) { Object constValue = ExpressionUtils.computeConstantExpression(assignment.getRExpression()); if (constValue == PsiTypesUtil.getDefaultValue(expr.getType())) { if ((field.hasModifierProperty(PsiModifier.STATIC) || ExpressionUtil.isEffectivelyUnqualified(ref)) && field.getContainingClass() == ((PsiClassInitializer)context).getContainingClass()) { return; } } } } } DfType value = CommonDataflow.getDfType(expr, IGNORE_ASSERT_STATEMENTS); // reported by ConstantValueInspection if (value == DfTypes.TRUE || value == DfTypes.FALSE) return; String message = assignment != null && !assignment.getOperationTokenType().equals(JavaTokenType.EQ) ? JavaAnalysisBundle.message("dataflow.message.redundant.update") : JavaAnalysisBundle.message("dataflow.message.redundant.assignment"); reporter.registerProblem(expr, message, LocalQuickFix.notNullElements(createRemoveAssignmentFix(assignment))); }); }