boolean (final PsiField field, final PsiAssignmentExpression assignment, final Collection<? super PsiAssignmentExpression> initializingAssignments) { final PsiExpression expression = assignment.getRExpression(); if (expression == null) return false; PsiClass containingClass = field.getContainingClass(); if (containingClass == null) return false; final Ref<Boolean> result = new Ref<>(Boolean.TRUE); final List<PsiAssignmentExpression> totalUsages = new ArrayList<>(); containingClass.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression reference) { if (!result.get().booleanValue()) return; super.visitReferenceExpression(reference); if (!PsiUtil.isOnAssignmentLeftHand(reference)) return; PsiElement resolved = reference.resolve(); if (resolved != field) return; PsiAssignmentExpression assignmentExpression = PsiTreeUtil.getParentOfType(reference, PsiAssignmentExpression.class); if (assignmentExpression == null) return; PsiExpression rValue = assignmentExpression.getRExpression(); PsiMember member = PsiTreeUtil.getParentOfType(assignmentExpression, PsiMember.class); if ((member instanceof PsiClassInitializer || member instanceof PsiMethod && ((PsiMethod)member).isConstructor()) && ExpressionUtils.isVoidContext(assignmentExpression) && assignmentExpression.getOperationTokenType().equals(JavaTokenType.EQ)) { // ignore usages other than initializing if (rValue == null || !EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(rValue, expression)) { result.set(Boolean.FALSE); } initializingAssignments.add(assignmentExpression); } totalUsages.add(assignment); } }); // the only assignment is OK if (totalUsages.size() == 1 && initializingAssignments.isEmpty()) { initializingAssignments.addAll(totalUsages); return true; } return result.get().booleanValue(); }