void (@NotNull ActionContext context, @NotNull PsiPrefixExpression myPrefixExpression, @NotNull ModPsiUpdater updater) { PsiExpression operand = Objects.requireNonNull(myPrefixExpression.getOperand()); PsiElement unnegated = myPrefixExpression.replace(operand); PsiElement parent = unnegated.getParent(); PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.project()); PsiPrefixExpression negated = (PsiPrefixExpression)factory.createExpressionFromText("!(xxx)", parent); PsiParenthesizedExpression parentheses = (PsiParenthesizedExpression)Objects.requireNonNull(negated.getOperand()); Objects.requireNonNull(parentheses.getExpression()).replace(parent.copy()); parent.replace(negated); }