void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiTypeCastExpression cast = PsiTreeUtil.getParentOfType(element, PsiTypeCastExpression.class); if (cast == null) return; PsiReferenceExpression ref = tryCast(PsiUtil.skipParenthesizedExprDown(cast.getOperand()), PsiReferenceExpression.class); if (ref == null) return; PsiVariable var = tryCast(ref.resolve(), PsiVariable.class); if (var == null) return; PsiTypeElement castType = cast.getCastType(); if (castType == null) return; var.normalizeDeclaration(); PsiTypeElement typeElement = var.getTypeElement(); if (typeElement == null) return; PsiElement newTypeElement = JavaCodeStyleManager.getInstance(project).shortenClassReferences(typeElement.replace(castType)); for (PsiReference reference : ReferencesSearch.search(var).findAll()) { if (reference instanceof PsiReferenceExpression) { PsiTypeCastExpression castOccurrence = tryCast(PsiUtil.skipParenthesizedExprUp(((PsiReferenceExpression)reference).getParent()), PsiTypeCastExpression.class); if (castOccurrence != null && RedundantCastUtil.isCastRedundant(castOccurrence)) { RemoveRedundantCastUtil.removeCast(castOccurrence); } } } if (myOnTheFly) { updater.highlight(newTypeElement, EditorColors.SEARCH_RESULT_ATTRIBUTES); } }