void (@NotNull PsiTypeCastExpression typeCastExpression) { final PsiMethod method = PsiTreeUtil.getParentOfType(typeCastExpression, PsiMethod.class); if (method == null) { return; } final PsiExpression operand = PsiUtil.skipParenthesizedExprDown(typeCastExpression.getOperand()); if (!(operand instanceof PsiReferenceExpression operandReference)) { return; } final PsiElement resolved = operandReference.resolve(); if (!(resolved instanceof PsiParameter) && !(resolved instanceof PsiLocalVariable)) { return; } final PsiVariable replacement = findReplacement(method, (PsiVariable)resolved, typeCastExpression); if (replacement == null) { return; } final String variableName = replacement.getName(); final String castExpressionText = typeCastExpression.getText(); final LocalQuickFix fix = new ReplaceCastWithVariableFix(castExpressionText, replacement); holder.registerProblem(typeCastExpression, InspectionGadgetsBundle.message("inspection.cast.can.be.replaced.with.variable.message", variableName, castExpressionText), fix); }