PsiElement () { LOG.assertTrue(myChainExpression != null); if (myFinisher == null || myChainExpression instanceof PsiStatement) { PsiElement toDelete = myChainExpression; if (toDelete instanceof PsiExpression && toDelete.getParent() instanceof PsiExpressionStatement) { toDelete = toDelete.getParent(); while (toDelete instanceof PsiExpressionStatement && toDelete.getParent() instanceof PsiLabeledStatement) { toDelete = toDelete.getParent(); } } myCommentTracker.delete(toDelete); return null; } else { PsiExpression expression = createExpression(myFinisher); PsiElement parent = myChainExpression.getParent(); if (parent instanceof PsiExpression && ParenthesesUtils.areParenthesesNeeded(expression, (PsiExpression)parent, false)) { expression = createExpression("(" + myFinisher + ")"); } return myCommentTracker.replace(myChainExpression, expression); } }