void (@NotNull PsiComment insertedComment, @NotNull String annotation, @NotNull List<TextRange> typeRanges) { final int initialCaretOffset = insertedComment.getTextRange().getStartOffset(); final VirtualFile updatedVirtualFile = insertedComment.getContainingFile().getVirtualFile(); final Project project = insertedComment.getProject(); final TemplateBuilder templateBuilder = TemplateBuilderFactory.getInstance().createTemplateBuilder(insertedComment); final boolean testMode = ApplicationManager.getApplication().isUnitTestMode(); for (TextRange range : typeRanges) { final String individualType = range.substring(annotation); final String replacementText = testMode ? "[" + individualType + "]" : individualType; templateBuilder.replaceRange(range.shiftRight(TYPE_COMMENT_PREFIX.length()), replacementText); } final Editor editor = PythonUiService.getInstance().openTextEditor(project, updatedVirtualFile, initialCaretOffset); if (editor != null) { editor.getCaretModel().moveToOffset(initialCaretOffset); templateBuilder.run(editor, true); } else { templateBuilder.runNonInteractively(true); } }