PsiElement (PsiMethodCallExpression methodCall) { String from = methodCall.getMethodExpression().getReferenceName(); if (from == null) return null; boolean removeParentNegation; boolean removeLambdaNegation; switch (from) { case ALL_MATCH_METHOD -> { removeLambdaNegation = true; removeParentNegation = myTo.equals(ANY_MATCH_METHOD); } case ANY_MATCH_METHOD -> { removeParentNegation = true; removeLambdaNegation = myTo.equals(ALL_MATCH_METHOD); } case NONE_MATCH_METHOD -> { removeParentNegation = myTo.equals(ANY_MATCH_METHOD); removeLambdaNegation = myTo.equals(ALL_MATCH_METHOD); } default -> { return null; } } if (removeParentNegation && !isParentNegated(methodCall)) return null; if (removeLambdaNegation && !isArgumentLambdaNegated(methodCall)) return null; ExpressionUtils.bindCallTo(methodCall, myTo); if (removeLambdaNegation) { // Casts and array bounds already checked in isArgumentLambdaNegated PsiExpression body = (PsiExpression)((PsiLambdaExpression)methodCall.getArgumentList().getExpressions()[0]).getBody(); PsiExpression negated = BoolUtils.getNegated(body); LOG.assertTrue(negated != null); body.replace(negated); } if (removeParentNegation) { return PsiUtil.skipParenthesizedExprUp(methodCall.getParent()).replace(methodCall); } return methodCall; }