PsiVariable (final @NotNull Project project, final @NotNull PsiExpression expr, final @Nullable Editor editor, final @NotNull PsiElement anchorStatement, final PsiExpression @NotNull [] occurrences, final @NotNull IntroduceVariableSettings settings) { Computable<SmartPsiElementPointer<PsiVariable>> computation = new VariableExtractor(project, expr, editor, anchorStatement, occurrences, settings)::extractVariable; PsiFile file = expr.getContainingFile(); SmartPsiElementPointer<PsiVariable> pointer = ApplicationManager.getApplication().runWriteAction(computation); if (pointer != null) { PsiVariable var = pointer.getElement(); if (var == null) { throw new RuntimeExceptionWithAttachments("Refactoring is interrupted due to syntax errors in the file", new Attachment("expression.txt", expr.getText()), new Attachment("source.java", file.getText())); } return var; } return null; }