private static PsiVariable extractThatVariable(PsiStatement statement, PsiParameter parameter) {
    if (!(statement instanceof PsiDeclarationStatement decl)) return null;
    PsiElement[] elements = decl.getDeclaredElements();
    if (elements.length != 1 || !(elements[0] instanceof PsiLocalVariable var)) return null;
    if (!(PsiUtil.skipParenthesizedExprDown(var.getInitializer()) instanceof PsiTypeCastExpression cast)) return null;
    if (!ExpressionUtils.isReferenceTo(cast.getOperand(), parameter)) return null;
    PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(var.getType());
    if (psiClass == null || !psiClass.isEquivalentTo(PsiTreeUtil.getParentOfType(statement, PsiClass.class))) return null;
    return var;
  }
private static PsiVariable extractThatVariable(PsiStatement statement, PsiParameter parameter)