void (@NotNull ActionContext context, @NotNull PsiTypeElement castTypeElement, @NotNull ModPsiUpdater updater) { PsiTypeElement[] conjuncts = PsiTreeUtil.getChildrenOfType(castTypeElement, PsiTypeElement.class); if (conjuncts == null) return; PsiTypeElement conjunct = updater.getWritable(myConjunct); final String intersectionTypeText = StreamEx.of(conjuncts).without(conjunct).prepend(conjunct).map(PsiElement::getText).joining(" & "); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(context.project()); final PsiTypeCastExpression fixedCast = (PsiTypeCastExpression)elementFactory.createExpressionFromText("(" + intersectionTypeText + ") a", castTypeElement); final PsiTypeElement fixedCastCastType = fixedCast.getCastType(); LOG.assertTrue(fixedCastCastType != null); final PsiElement flippedTypeElement = castTypeElement.replace(fixedCastCastType); CodeStyleManager.getInstance(context.project()).reformat(flippedTypeElement); }