ReparseResult (@NotNull PsiFileImpl fileImpl, @NotNull FileASTNode oldFileNode, @NotNull CharSequence newFileText, @NotNull ProgressIndicator indicator, @NotNull CharSequence lastCommittedText) { if (fileImpl instanceof PsiCodeFragment) { FileElement parent = fileImpl.getTreeElement(); PsiElement context = fileImpl.getContext(); DummyHolder dummyHolder = new DummyHolder(fileImpl.getManager(), context != null && context.isValid() ? context : null); FileElement holderElement = dummyHolder.getTreeElement(); holderElement.rawAddChildren(fileImpl.createContentLeafElement(holderElement.getCharTable().intern(newFileText, 0, newFileText.length()))); DiffLog diffLog = new DiffLog(); diffLog.appendReplaceFileElement(parent, (FileElement)holderElement.getFirstChildNode()); return new ReparseResult(diffLog, oldFileNode, holderElement); } FileViewProvider viewProvider = fileImpl.getViewProvider(); viewProvider.getLanguages(); VirtualFile virtualFile = viewProvider.getVirtualFile(); FileType fileType = virtualFile.getFileType(); String fileName = fileImpl.getName(); LightVirtualFile lightFile = new LightVirtualFile(fileName, fileType, newFileText, virtualFile.getCharset(), viewProvider.getModificationStamp()); lightFile.setOriginalFile(virtualFile); FileViewProvider providerCopy = viewProvider.createCopy(lightFile); if (providerCopy.isEventSystemEnabled()) { throw new AssertionError("Copied view provider must be non-physical for reparse to deliver correct events: " + viewProvider); } providerCopy.getLanguages(); SingleRootFileViewProvider.doNotCheckFileSizeLimit(lightFile); // optimization: do not convert file contents to bytes to determine if we should codeinsight it PsiFileImpl newFile = getFileCopy(fileImpl, providerCopy); newFile.setOriginalFile(fileImpl); ASTNode newFileElement = newFile.getNode(); if (lastCommittedText.length() != oldFileNode.getTextLength()) { throw new IncorrectOperationException(viewProvider.toString()); } DiffLog diffLog = mergeTrees(fileImpl, oldFileNode, newFileElement, indicator, lastCommittedText); return new ReparseResult(diffLog, oldFileNode, newFileElement); }