void (@NotNull PsiExpression subExpression) { CommentTracker ct = new CommentTracker(); if (SideEffectChecker.mayHaveSideEffects(subExpression) && canExtractSideEffect(subExpression)) { PsiExpression orig = subExpression; subExpression = ensureCodeBlock(subExpression.getProject(), subExpression); if (subExpression == null) { LOG.error("ensureCodeBlock returned null", new Attachment("subExpression.txt", orig.getText())); return; } PsiStatement anchor = ObjectUtils.tryCast(CommonJavaRefactoringUtil.getParentStatement(subExpression, false), PsiStatement.class); if (anchor == null) { LOG.error("anchor is null", new Attachment("subExpression.txt", subExpression.getText())); return; } PsiExpression finalSubExpression = subExpression; List<PsiExpression> sideEffects = SideEffectChecker.extractSideEffectExpressions( subExpression, e -> shouldIgnore(e, finalSubExpression)); sideEffects.forEach(ct::markUnchanged); PsiStatement[] statements = StatementExtractor.generateStatements(sideEffects, subExpression); if (statements.length > 0) { BlockUtils.addBefore(anchor, statements); } if (!subExpression.isValid()) { LOG.error("subExpression became invalid", new Attachment("subExpression.txt", subExpression.getText())); return; } } PsiExpression expression = (PsiExpression)ct.replaceAndRestoreComments(subExpression, Boolean.toString(mySubExpressionValue)); while (expression.getParent() instanceof PsiExpression) { expression = (PsiExpression)expression.getParent(); } simplifyExpression(expression); }