GrInplaceVariableIntroducer (@NotNull GrIntroduceContext context, @NotNull OccurrencesChooser.ReplaceChoice choice) { final Ref<GrIntroduceContext> contextRef = Ref.create(context); if (context.getStringPart() != null) { extractStringPart(contextRef); } context = contextRef.get(); final GrStatement anchor = findAnchor(context, choice == OccurrencesChooser.ReplaceChoice.ALL); if (anchor.getParent() instanceof GrControlStatement) { addBraces(anchor, contextRef); } return new GrInplaceVariableIntroducer(getRefactoringName(), choice, contextRef.get()) { @Override protected GrVariable runRefactoring(GrIntroduceContext context, GroovyIntroduceVariableSettings settings, boolean processUsages) { return refactorInWriteAction(() -> processUsages ? processExpression(context, settings) : addVariable(context, settings)); } @Override protected void performPostIntroduceTasks() { super.performPostIntroduceTasks(); moveOffsetToPositionMarker(contextRef.get().getEditor()); } }; }