Java Intellij插件设置当前文档的文本

Java Intellij插件设置当前文档的文本,java,intellij-idea,intellij-plugin,Java,Intellij Idea,Intellij Plugin,有没有办法从字符串更改文件中的整个代码? 我的意思是有一种方法可以阅读文档中的所有内容,但我也可以替换整个文本吗 阅读文档中代码的方式: SourceCodeString=e.getData(LangDataKeys.EDITOR).getDocument().getText() 所以我基本上是想做相反的事情。查看相关文档: 是否需要指定开始和结束,或者您也可以替换整个内容? // Replace the selection with a fixed string. // Must do thi

有没有办法从字符串更改文件中的整个代码? 我的意思是有一种方法可以阅读文档中的所有内容,但我也可以替换整个文本吗

阅读文档中代码的方式:

SourceCodeString=e.getData(LangDataKeys.EDITOR).getDocument().getText()


所以我基本上是想做相反的事情。

查看相关文档:


是否需要指定开始和结束,或者您也可以替换整个内容?
// Replace the selection with a fixed string.
// Must do this document change in a write action context.
WriteCommandAction.runWriteCommandAction(project, () ->
    document.replaceString(start, end, "editor_basics")
);