Java Code Examples for com.intellij.psi.PsiFile#getText()
The following examples show how to use
com.intellij.psi.PsiFile#getText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 7 votes |
public void testGoToSymbolFunction_QualifiedImport() { PsiFile[] psiFiles = myFixture.configureByFiles( "QualifiedImport/Usage.hs", "QualifiedImport/Definition.hs" ); PsiFile usage = psiFiles[0]; PsiFile definition = psiFiles[1]; String textOfFile = definition.getText(); int expectedStartOffset = textOfFile.indexOf("seven ::"); PsiElement psiElement = usage .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellVarid varId = (HaskellVarid) psiElement; PsiReference reference = varId.getReference(); HaskellVarid referencedElement = (HaskellVarid) reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 2
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 6 votes |
public void testGoToSymbolFunction_QualifiedImportNoAs() { PsiFile[] psiFiles = myFixture.configureByFiles( "QualifiedImportNoAs/Usage.hs", "QualifiedImportNoAs/Definition.hs" ); PsiFile usage = psiFiles[0]; PsiFile definition = psiFiles[1]; String textOfFile = definition.getText(); int expectedStartOffset = textOfFile.indexOf("seven ::"); PsiElement psiElement = usage .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellVarid varId = (HaskellVarid) psiElement; PsiReference reference = varId.getReference(); HaskellVarid referencedElement = (HaskellVarid) reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 3
Source File: CreateFromTemplateActionBase.java From consulo with Apache License 2.0 | 6 votes |
public static void startLiveTemplate(@Nonnull PsiFile file, @Nonnull Map<String, String> defaultValues) { Editor editor = EditorHelper.openInEditor(file); if (editor == null) return; TemplateImpl template = new TemplateImpl("", file.getText(), ""); template.setInline(true); int count = template.getSegmentsCount(); if (count == 0) return; Set<String> variables = new HashSet<>(); for (int i = 0; i < count; i++) { variables.add(template.getSegmentName(i)); } variables.removeAll(TemplateImpl.INTERNAL_VARS_SET); for (String variable : variables) { String defaultValue = defaultValues.getOrDefault(variable, variable); template.addVariable(variable, null, '"' + defaultValue + '"', true); } Project project = file.getProject(); WriteCommandAction.runWriteCommandAction(project, () -> editor.getDocument().setText(template.getTemplateText())); editor.getCaretModel().moveToOffset(0); // ensures caret at the start of the template TemplateManager.getInstance(project).startTemplate(editor, template); }
Example 4
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 6 votes |
public void testGoToSymbolFunction_QualifiedImportMultipleLevels() { PsiFile[] psiFiles = myFixture.configureByFiles( "QualifiedImportMultipleLevels/Usage/Usage.hs", "QualifiedImportMultipleLevels/Definition/Definition.hs" ); PsiFile usage = psiFiles[0]; PsiFile definition = psiFiles[1]; String textOfFile = definition.getText(); int expectedStartOffset = textOfFile.indexOf("seven ::"); PsiElement psiElement = usage .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellVarid varId = (HaskellVarid) psiElement; PsiReference reference = varId.getReference(); HaskellVarid referencedElement = (HaskellVarid) reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 5
Source File: PsiFileUtil.java From NutzCodeInsight with Apache License 2.0 | 6 votes |
public static List<String> findProperties(Project project, Collection<VirtualFile> virtualFiles, String key) { List<String> result = new ArrayList<>(); for (VirtualFile virtualFile : virtualFiles) { PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); Properties properties = new Properties(); try (StringReader reader = new StringReader(psiFile.getText())) { properties.load(reader); } catch (IOException e) { } properties.forEach((name, val) -> { if (name.equals(key)) { result.add(String.valueOf(val)); } }); } return result; }
Example 6
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 6 votes |
public void testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons2_NoAs() { PsiFile[] psiFiles = myFixture.configureByFiles( "QualifiedImport_QualifierResolvesMultipleCons_Cons2_NoAs/Usage.hs", "QualifiedImport_QualifierResolvesMultipleCons_Cons2_NoAs/Definition.hs" ); PsiFile usage = psiFiles[0]; String textOfFile = usage.getText(); int expectedStartOffset = textOfFile.indexOf("qualified Definition.Definition") + 21; PsiElement psiElement = usage .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellConid conId = (HaskellConid) psiElement; PsiReference reference = conId.getReference(); HaskellConid referencedElement = (HaskellConid) reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 7
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 6 votes |
public void testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons1_NoAs() { PsiFile[] psiFiles = myFixture.configureByFiles( "QualifiedImport_QualifierResolvesMultipleCons_Cons1_NoAs/Usage.hs", "QualifiedImport_QualifierResolvesMultipleCons_Cons1_NoAs/Definition.hs" ); PsiFile usage = psiFiles[0]; String textOfFile = usage.getText(); int expectedStartOffset = textOfFile.indexOf("qualified Definition.Definition") + 10; PsiElement psiElement = usage .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellConid conId = (HaskellConid) psiElement; PsiReference reference = conId.getReference(); HaskellConid referencedElement = (HaskellConid) reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 8
Source File: DebuggerCompletionContributor.java From intellij with Apache License 2.0 | 6 votes |
@Override protected void addCompletions( CompletionParameters parameters, ProcessingContext context, CompletionResultSet result) { PsiFile file = parameters.getOriginalFile(); SkylarkSourcePosition debugContext = getDebugContext(file); if (debugContext == null) { return; } String text = file.getText(); List<Value> suggestions = SkylarkDebugCompletionSuggestions.create(debugContext).getCompletionValues(text); if (suggestions.isEmpty()) { return; } suggestions.forEach( value -> result.addElement( LookupElementBuilder.create(value.getLabel()) .withIcon(SkylarkDebugValue.getIcon(value)))); }
Example 9
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 6 votes |
public void testGoToSymbolFunction_ImportResolvesToModule_MultipleCons_OnModule() { PsiFile[] psiFiles = myFixture.configureByFiles( "ImportResolvesToModule_MultipleCons_OnModule/Usage.hs", "ImportResolvesToModule_MultipleCons_OnModule/Definition.hs" ); PsiFile usage = psiFiles[0]; PsiFile definition = psiFiles[1]; String textOfFile = definition.getText(); int expectedStartOffset = textOfFile.indexOf("module Definition.Definition") + 18; PsiElement psiElement = usage .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellConid conId = (HaskellConid) psiElement; PsiReference reference = conId.getReference(); HaskellConid referencedElement = (HaskellConid) reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 10
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 6 votes |
public void testGoToSymbolFunction_QualifiedImportMultipleLevels_AsPartConsistsOfMultipleCons() { PsiFile[] psiFiles = myFixture.configureByFiles( "QualifiedImportMultipleLevels_AsPartConsistsOfMultipleCons/Usage/Usage.hs", "QualifiedImportMultipleLevels_AsPartConsistsOfMultipleCons/Definition/Definition.hs" ); PsiFile usage = psiFiles[0]; PsiFile definition = psiFiles[1]; String textOfFile = definition.getText(); int expectedStartOffset = textOfFile.indexOf("seven ::"); PsiElement psiElement = usage .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellVarid varId = (HaskellVarid) psiElement; PsiReference reference = varId.getReference(); HaskellVarid referencedElement = (HaskellVarid) reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 11
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 6 votes |
public void testGoToSymbolFunction_QualifiedImport_MultipleImportSameQualifiedName1() { PsiFile[] psiFiles = myFixture.configureByFiles( "QualifiedImport_MultipleImportSameQualifiedName1/Usage/Usage.hs", "QualifiedImport_MultipleImportSameQualifiedName1/Definition/Definition.hs", "QualifiedImport_MultipleImportSameQualifiedName1/Other/Definition.hs" ); PsiFile usage = psiFiles[0]; String textOfFile = usage.getText(); int expectedStartOffset = textOfFile.indexOf("qualified Definition.Definition as Definition") + 35; PsiElement psiElement = usage .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellConid conId = (HaskellConid) psiElement; PsiReference reference = conId.getReference(); HaskellConid referencedElement = (HaskellConid) reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 12
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 6 votes |
public void testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons1() { PsiFile[] psiFiles = myFixture.configureByFiles( "QualifiedImport_QualifierResolvesMultipleCons_Cons1/Usage.hs", "QualifiedImport_QualifierResolvesMultipleCons_Cons1/Definition.hs" ); PsiFile usage = psiFiles[0]; String textOfFile = usage.getText(); int expectedStartOffset = textOfFile.indexOf("as Def.Lef") + 3; PsiElement psiElement = usage .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellConid conId = (HaskellConid) psiElement; PsiReference reference = conId.getReference(); HaskellConid referencedElement = (HaskellConid) reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 13
Source File: HLint.java From intellij-haskforce with Apache License 2.0 | 5 votes |
@Override public void createAnnotations(@NotNull PsiFile file, @NotNull HaskellAnnotationHolder holder) { final String text = file.getText(); final int start = getOffsetStart(text); final int end = getOffsetEnd(start, text); if (start == -1 || end == -1) { return; } if (useJson && hint.equals("Use camelCase")) { createUseCamelCaseAnnotations(text, start, end, holder); } else { createDefaultAnnotations(start, end, holder); } }
Example 14
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 5 votes |
public void testGoToSymbolFunction_GADT(){ myFixture.configureByFile(getTestName(false)+".hs"); PsiFile file = myFixture.getFile(); String textOfFile = file.getText(); int expectedStartOffset= textOfFile.indexOf("f (B _ end)") +7; PsiElement psiElement = file .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellVarid varId = (HaskellVarid) psiElement; PsiReference reference = varId.getReference(); HaskellVarid referencedElement = (HaskellVarid)reference.resolve(); assertEquals(varId.getName(), referencedElement.getName()); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset()); }
Example 15
Source File: TranslationInsertUtilTest.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public void testInsertTranslationForXlf20() { PsiFile xmlFile = PsiFileFactory.getInstance(getProject()).createFileFromText("foo.xml", XmlFileType.INSTANCE, "" + "<?xml version=\"1.0\"?>\n" + "<xliff xmlns=\"urn:oasis:names:tc:xliff:document:2.0\"\n" + " version=\"2.0\" srcLang=\"en-US\" trgLang=\"ja-JP\">\n" + " <file id=\"f1\" original=\"Graphic Example.psd\">\n" + " <skeleton href=\"Graphic Example.psd.skl\"/>\n" + " <group id=\"1\">\n" + " <unit id=\"1\">\n" + " <segment>\n" + " <source>foo</source>\n" + " </segment>\n" + " </unit>\n" + " <unit id=\"foobar\">\n" + " <segment>\n" + " <source>foo</source>\n" + " </segment>\n" + " </unit>\n" + " </group>\n" + " </file>\n" + "</xliff>" ); CommandProcessor.getInstance().executeCommand(getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> { TranslationInsertUtil.invokeTranslation((XmlFile) xmlFile, "foobar", "value"); }), null, null); String text = xmlFile.getText(); assertTrue(text.contains("<unit id=\"2\">")); assertTrue(text.contains("<source>foobar</source>")); assertTrue(text.contains("<target>value</target>")); }
Example 16
Source File: HaskellGoToSymbolTest.java From intellij-haskforce with Apache License 2.0 | 5 votes |
public void testGoToSymbolFunction_RecordsConstructor(){ myFixture.configureByFile(getTestName(false)+".hs"); PsiFile file = myFixture.getFile(); String textOfFile = file.getText(); int expectedStartOffset= textOfFile.indexOf("Pool (Maybe a)"); PsiElement psiElement = file .findElementAt(myFixture.getCaretOffset()).getParent(); HaskellConid conId = (HaskellConid) psiElement; PsiReference reference = conId.getReference(); HaskellConid referencedElement = (HaskellConid)reference.resolve(); assertNotSame(psiElement, referencedElement); assertEquals(expectedStartOffset,referencedElement.getTextRange().getStartOffset()); }
Example 17
Source File: CompletionAssertions.java From consulo with Apache License 2.0 | 4 votes |
static void assertCommitSuccessful(Editor editor, PsiFile psiFile) { Document document = editor.getDocument(); int docLength = document.getTextLength(); int psiLength = psiFile.getTextLength(); PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject()); boolean committed = !manager.isUncommited(document); if (docLength == psiLength && committed) { return; } FileViewProvider viewProvider = psiFile.getViewProvider(); String message = "unsuccessful commit:"; message += "\nmatching=" + (psiFile == manager.getPsiFile(document)); message += "\ninjectedEditor=" + (editor instanceof EditorWindow); message += "\ninjectedFile=" + InjectedLanguageManager.getInstance(psiFile.getProject()).isInjectedFragment(psiFile); message += "\ncommitted=" + committed; message += "\nfile=" + psiFile.getName(); message += "\nfile class=" + psiFile.getClass(); message += "\nfile.valid=" + psiFile.isValid(); message += "\nfile.physical=" + psiFile.isPhysical(); message += "\nfile.eventSystemEnabled=" + viewProvider.isEventSystemEnabled(); message += "\nlanguage=" + psiFile.getLanguage(); message += "\ndoc.length=" + docLength; message += "\npsiFile.length=" + psiLength; String fileText = psiFile.getText(); if (fileText != null) { message += "\npsiFile.text.length=" + fileText.length(); } FileASTNode node = psiFile.getNode(); if (node != null) { message += "\nnode.length=" + node.getTextLength(); String nodeText = node.getText(); message += "\nnode.text.length=" + nodeText.length(); } VirtualFile virtualFile = viewProvider.getVirtualFile(); message += "\nvirtualFile=" + virtualFile; message += "\nvirtualFile.class=" + virtualFile.getClass(); message += "\n" + DebugUtil.currentStackTrace(); throw new RuntimeExceptionWithAttachments("Commit unsuccessful", message, new Attachment(virtualFile.getPath() + "_file.txt", StringUtil.notNullize(fileText)), createAstAttachment(psiFile, psiFile), new Attachment("docText.txt", document.getText())); }
Example 18
Source File: CompletionAssertions.java From consulo with Apache License 2.0 | 4 votes |
private static Attachment createFileTextAttachment(PsiFile fileCopy, final PsiFile originalFile) { return new Attachment(originalFile.getViewProvider().getVirtualFile().getPath(), fileCopy.getText()); }
Example 19
Source File: GenerateLexerRulesForLiteralsAction.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void actionPerformed(AnActionEvent e) { LOG.info("actionPerformed GenerateLexerRulesForLiteralsAction"); final Project project = e.getProject(); final PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE); if (psiFile == null) { return; } String inputText = psiFile.getText(); ParsingResult results = ParsingUtils.parseANTLRGrammar(inputText); final Parser parser = results.parser; final ParseTree tree = results.tree; Collection<ParseTree> literalNodes = XPath.findAll(tree, "//ruleBlock//STRING_LITERAL", parser); LinkedHashMap<String, String> lexerRules = new LinkedHashMap<String, String>(); for (ParseTree node : literalNodes) { String literal = node.getText(); String ruleText = String.format("%s : %s ;", RefactorUtils.getLexerRuleNameFromLiteral(literal), literal); lexerRules.put(literal, ruleText); } // remove those already defined String lexerRulesXPath = "//lexerRule"; String treePattern = "<TOKEN_REF> : <STRING_LITERAL>;"; ParseTreePattern p = parser.compileParseTreePattern(treePattern, ANTLRv4Parser.RULE_lexerRule); List<ParseTreeMatch> matches = p.findAll(tree, lexerRulesXPath); for (ParseTreeMatch match : matches) { ParseTree lit = match.get("STRING_LITERAL"); if (lexerRules.containsKey(lit.getText())) { // we have rule for this literal already lexerRules.remove(lit.getText()); } } final LiteralChooser chooser = new LiteralChooser(project, new ArrayList<String>(lexerRules.values())); chooser.show(); List<String> selectedElements = chooser.getSelectedElements(); // chooser disposed automatically. final Editor editor = e.getData(PlatformDataKeys.EDITOR); final Document doc = editor.getDocument(); final CommonTokenStream tokens = (CommonTokenStream) parser.getTokenStream(); // System.out.println(selectedElements); if (selectedElements != null) { String text = doc.getText(); int cursorOffset = editor.getCaretModel().getOffset(); // make sure it's not in middle of rule; put between. // System.out.println("offset "+cursorOffset); Collection<ParseTree> allRuleNodes = XPath.findAll(tree, "//ruleSpec", parser); for (ParseTree r : allRuleNodes) { Interval extent = r.getSourceInterval(); // token indexes int start = tokens.get(extent.a).getStartIndex(); int stop = tokens.get(extent.b).getStopIndex(); // System.out.println("rule "+r.getChild(0).getText()+": "+start+".."+stop); if (cursorOffset < start) { // before this rule, so must be between previous and this one cursorOffset = start; // put right before this rule break; } else if (cursorOffset >= start && cursorOffset <= stop) { // cursor in this rule cursorOffset = stop + 2; // put right before this rule (after newline) if (cursorOffset >= text.length()) { cursorOffset = text.length(); } break; } } String allRules = Utils.join(selectedElements.iterator(), "\n"); text = text.substring(0, cursorOffset) + "\n" + allRules + "\n" + text.substring(cursorOffset, text.length()); MyPsiUtils.replacePsiFileFromText(project, psiFile, text); } }
Example 20
Source File: FileUtils.java From EasyCode with MIT License | 4 votes |
/** * 写入文件 * * @param saveFile 需要保存的文件对象 */ public void write(SaveFile saveFile) { // 校验目录是否存在 PsiManager psiManager = PsiManager.getInstance(saveFile.getProject()); PsiDirectory psiDirectory; VirtualFile directory = LocalFileSystem.getInstance().findFileByPath(saveFile.getPath()); if (directory == null) { // 尝试创建目录 if (saveFile.isOperateTitle() && !MessageDialogBuilder.yesNo(MsgValue.TITLE_INFO, "Directory " + saveFile.getPath() + " Not Found, Confirm Create?").isYes()) { return; } psiDirectory = WriteCommandAction.runWriteCommandAction(saveFile.getProject(), (Computable<PsiDirectory>) () -> { try { VirtualFile dir = VfsUtil.createDirectoryIfMissing(saveFile.getPath()); LOG.assertTrue(dir != null); // 重载文件,防止发生IndexNotReadyException异常 FileDocumentManager.getInstance().reloadFiles(dir); return psiManager.findDirectory(dir); } catch (IOException e) { LOG.error("path " + saveFile.getPath() + " error"); ExceptionUtil.rethrow(e); return null; } }); } else { psiDirectory = psiManager.findDirectory(directory); } if (psiDirectory == null) { return; } // 保存或替换文件 PsiFile oldFile = psiDirectory.findFile(saveFile.getFile().getName()); PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(saveFile.getProject()); FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); if (saveFile.isOperateTitle() && oldFile != null) { MessageDialogBuilder.YesNoCancel yesNoCancel = MessageDialogBuilder.yesNoCancel(MsgValue.TITLE_INFO, "File " + saveFile.getFile().getName() + " Exists, Select Operate Mode?"); yesNoCancel.yesText("Cover"); yesNoCancel.noText("Compare"); yesNoCancel.cancelText("Cancel"); int result = yesNoCancel.show(); switch (result) { case Messages.YES: break; case Messages.NO: // 对比代码时也格式化代码 if (saveFile.isReformat()) { // 保留旧文件内容,用新文件覆盖旧文件执行格式化,然后再还原旧文件内容 String oldText = oldFile.getText(); WriteCommandAction.runWriteCommandAction(saveFile.getProject(), () -> psiDocumentManager.getDocument(oldFile).setText(saveFile.getFile().getText())); // 提交所有改动,并非VCS中的提交文件 PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments(); reformatFile(saveFile.getProject(), Collections.singletonList(oldFile)); // 提交所有改动,并非VCS中的提交文件 PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments(); String newText = oldFile.getText(); WriteCommandAction.runWriteCommandAction(saveFile.getProject(), () -> psiDocumentManager.getDocument(oldFile).setText(oldText)); // 提交所有改动,并非VCS中的提交文件 PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments(); saveFile.setVirtualFile(new LightVirtualFile(saveFile.getFile().getName(), saveFile.getFile().getFileType(), newText)); } CompareFileUtils.showCompareWindow(saveFile.getProject(), fileDocumentManager.getFile(psiDocumentManager.getDocument(oldFile)), saveFile.getVirtualFile()); return; case Messages.CANCEL: default: return; } } PsiDirectory finalPsiDirectory = psiDirectory; PsiFile finalFile = WriteCommandAction.runWriteCommandAction(saveFile.getProject(), (Computable<PsiFile>) () -> { if (oldFile == null) { // 提交所有改动,并非VCS中的提交文件 PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments(); return (PsiFile) finalPsiDirectory.add(saveFile.getFile()); } else { // 对旧文件进行替换操作 Document document = psiDocumentManager.getDocument(oldFile); LOG.assertTrue(document != null); document.setText(saveFile.getFile().getText()); return oldFile; } }); // 判断是否需要进行代码格式化操作 if (saveFile.isReformat()) { reformatFile(saveFile.getProject(), Collections.singletonList(finalFile)); } // 提交所有改动,并非VCS中的提交文件 PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments(); }