public static int findFieldAssignmentAnchor(PsiStatement @NotNull [] statements,
                                              @Nullable Ref<? super PsiField> outAnchor,
                                              @Nullable AtomicBoolean outBefore,
                                              @NotNull PsiClass targetClass,
                                              @NotNull PsiParameter myParameter) {
    if (statements.length == 0) return 0;
    PsiElement parent = statements[0].getParent().getParent();
    assert parent instanceof PsiMethod;
    PsiMethod method = (PsiMethod)parent;
    PsiMethodCallExpression constructorCall = JavaPsiConstructorUtil.findThisOrSuperCallInConstructor(method);
    int i = 0;
    for (; i < statements.length; i++) {
      PsiStatement psiStatement = statements[i];
      if (constructorCall != null && psiStatement.getTextOffset() <= constructorCall.getTextOffset()) {
        continue;
      }

      if (psiStatement instanceof PsiExpressionStatement expressionStatement) {
        PsiExpression expression = expressionStatement.getExpression();

        if (expression instanceof PsiAssignmentExpression assignmentExpression) {
          PsiExpression lExpression = assignmentExpression.getLExpression();

          if (!(lExpression instanceof PsiReferenceExpression)) break;

          PsiElement lElement = ((PsiReferenceExpression)lExpression).resolve();
          if (!(lElement instanceof PsiField) || ((PsiField)lElement).getContainingClass() != targetClass) break;

          Set<PsiParameter> parameters = new HashSet<>();
          SyntaxTraverser.psiTraverser().withRoot(assignmentExpression.getRExpression())
            .filter(PsiReferenceExpression.class)
            .forEach(expr -> {
              PsiElement resolve = expr.resolve();
              if (resolve instanceof PsiParameter && ((PsiParameter)resolve).getDeclarationScope() == myParameter.getDeclarationScope()) {
                parameters.add((PsiParameter)resolve);
              }
            });

          if (parameters.size() != 1) break;

          PsiElement rElement = parameters.iterator().next();

          if (myParameter.getTextRange().getStartOffset() < rElement.getTextRange().getStartOffset()) {
            if (outAnchor != null) {
              outAnchor.set((PsiField)lElement);
            }
            if (outBefore != null) {
              outBefore.set(true);
            }
            break;
          }

          if (outAnchor != null) {
            outAnchor.set((PsiField)lElement);
          }
          if (outBefore != null) {
            outBefore.set(false);
          }
          continue;
        }
      }

      break;
    }
    return i;
  }
public static int findFieldAssignmentAnchor(PsiStatement @NotNull [] statements,
                                              @Nullable Ref<? super PsiField> outAnchor,
                                              @Nullable AtomicBoolean outBefore,
                                              @NotNull PsiClass targetClass,
                                              @NotNull PsiParameter myParameter)