InlineTransformer (PsiStatement earlyStatement, PsiStatement finalStatement) { return (methodCopy, callSite, returnType) -> { PsiCodeBlock block = Objects.requireNonNull(methodCopy.getBody()); PsiReturnStatement[] returns = PsiUtil.findReturnStatements(methodCopy); for (PsiReturnStatement returnStatement : returns) { PsiExpression returnValue = Objects.requireNonNull(returnStatement.getReturnValue()); // null-checked in "from" method PsiLiteralExpression literal = ExpressionUtils.getLiteral(returnValue); Boolean value = literal == null ? null : ObjectUtils.tryCast(literal.getValue(), Boolean.class); if (value == null) { CommentTracker tracker = new CommentTracker(); String condition = myEarlyReturnValue ? tracker.text(returnValue) : BoolUtils.getNegatedExpressionText(returnValue, tracker); tracker.replaceAndRestoreComments(returnStatement, "if(" + condition + ") {" + earlyStatement.getText() + "}"); } else if (value == myEarlyReturnValue) { new CommentTracker().replaceAndRestoreComments(returnStatement, earlyStatement); } else { new CommentTracker().delete(returnStatement); } } if (finalStatement != null) { block.addBefore(finalStatement, block.getRBrace()); } return null; }; }