private static Pair<PsiField, PsiType> isAssignedToField(@NotNull PsiReference ref, PsiClass containingClass) {
    PsiElement refElement = ref.getElement();
    PsiElement parent = skipParensAndCastsUp(refElement);
    if (!(parent instanceof PsiAssignmentExpression) || ((PsiAssignmentExpression)parent).getOperationTokenType() != JavaTokenType.EQ) return null;
    PsiExpression r = ((PsiAssignmentExpression)parent).getRExpression();
    if (!PsiTreeUtil.isAncestor(r, refElement, false)) return null;
    PsiExpression l = skipParensAndCastsDown(((PsiAssignmentExpression)parent).getLExpression());
    if (!(l instanceof PsiReferenceExpression lExpression)) return null;
    PsiExpression lQualifier = skipParensAndCastsDown(lExpression.getQualifierExpression());
    if (lQualifier != null && !(lQualifier instanceof PsiThisExpression)) return null;
    PsiElement resolved = lExpression.resolve();
    if (!(resolved instanceof PsiField field)) return null;
    // too expensive to search for usages of public field otherwise
    if (!field.hasModifierProperty(PsiModifier.PRIVATE) &&
        !field.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) return null;
    PsiType type = r.getType();
    if (type == null) return null;
    if (field.getContainingClass() != containingClass) return null;
    return Pair.createNonNull(field, type);
  }
private static Pair<PsiField, PsiType> isAssignedToField(@NotNull PsiReference ref, PsiClass containingClass)