将字符串插入文档中,不能直接使用document.insertString,会error: Assertion failed: Write access is allowed inside write-action only (see com.intellij.openapi.application.Application.runWriteAction())
需要把这个任务放入一个Runnable中,然后由WriteCommandAction来调度。
参考:Write access is allowed inside write-action only
// 对文档进行操作部分代码,需要放入runnable,不然IDEA会卡住 Runnable runnable = () -> document.insertString(nextLineStartOffset, genGetterAndGetter(fieldList)); // 加入任务,由IDE调度任务 WriteCommandAction.runWriteCommandAction(project, runnable); 效果目前来看效果还不错,关于安装方法、使用方法,见github的README。
github链接:https://github.com/mybichu/PyGetterAndSetter