private static boolean collectAssignedFields(PsiElement element, PsiParameter parameter,
                                                 @Nullable Set<? super PsiMethod> methods, List<? super PsiField> assignedFields) {
      if (element instanceof PsiAssignmentExpression) {
        final PsiExpression lhs = PsiUtil.skipParenthesizedExprDown(((PsiAssignmentExpression)element).getLExpression());
        final PsiVariable variable = resolveVariable(lhs, null);
        if (variable instanceof PsiField) {
          assignedFields.add((PsiField)variable);
        }
      }
      else if (JavaPsiConstructorUtil.isChainedConstructorCall(element)) {
        final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)element;
        for (PsiExpression argument : methodCallExpression.getArgumentList().getExpressions()) {
          argument = PsiUtil.skipParenthesizedExprDown(argument);
          final PsiVariable variable = resolveVariable(argument, parameter);
          if (variable == parameter) {
            // instance to copy is passed to another constructor
            return false;
          }
        }
        if (methods != null) {
          final PsiMethod constructor = methodCallExpression.resolveMethod();
          if (constructor != null) {
            methods.add(constructor);
          }
        }
      }
      else if (element instanceof PsiMethodCallExpression methodCallExpression) {
        final PsiExpression qualifier =
          PsiUtil.skipParenthesizedExprDown(methodCallExpression.getMethodExpression().getQualifierExpression());
        if (qualifier == null || qualifier instanceof PsiThisExpression) {
          final PsiMethod method = methodCallExpression.resolveMethod();
          final PsiField field = PropertyUtil.getFieldOfSetter(method);
          if (field != null) {
            // field assigned using setter
            assignedFields.add(field);
          }
          else if (methods != null && method != null) {
            methods.add(method);
          }
        }
        else if (qualifier instanceof PsiReferenceExpression referenceExpression) {
          // consider field assigned if method is called on it.
          final PsiElement target = referenceExpression.resolve();
          if (target instanceof PsiField) {
            assignedFields.add((PsiField)target);
          }
        }
      }
      return true;
    }
private static boolean collectAssignedFields(PsiElement element, PsiParameter parameter,
                                                 @Nullable Set<? super PsiMethod> methods, List<? super PsiField> assignedFields)