use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class IpnbPyFragment method clone.
protected IpnbPyFragment clone() {
final IpnbPyFragment clone = (IpnbPyFragment) cloneImpl((FileElement) calcTreeElement().clone());
clone.myPhysical = false;
clone.myOriginalFile = this;
FileManager fileManager = ((PsiManagerEx) getManager()).getFileManager();
SingleRootFileViewProvider cloneViewProvider = (SingleRootFileViewProvider) fileManager.createFileViewProvider(new LightVirtualFile(getName(), getLanguage(), getText()), false);
cloneViewProvider.forceCachedPsi(clone);
clone.myViewProvider = cloneViewProvider;
return clone;
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class PsiElementFactoryImpl method createDummyHolder.
@NotNull
@Override
public PsiElement createDummyHolder(@NotNull final String text, @NotNull final IElementType type, @Nullable final PsiElement context) {
final DummyHolder result = DummyHolderFactory.createHolder(myManager, context);
final FileElement holder = result.getTreeElement();
final Language language = type.getLanguage();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
assert parserDefinition != null : "No parser definition for language " + language;
final Project project = myManager.getProject();
final Lexer lexer = parserDefinition.createLexer(project);
final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, holder, lexer, language, text);
final ASTNode node = parserDefinition.createParser(project).parse(type, builder);
holder.rawAddChildren((TreeElement) node);
final PsiElement psi = node.getPsi();
assert psi != null : text;
return psi;
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class DocumentCommitThread method doCommit.
// public for Upsource
@Nullable("returns runnable to execute under write action in AWT to finish the commit")
public Processor<Document> doCommit(@NotNull final CommitTask task, @NotNull final PsiFile file, @NotNull final FileASTNode oldFileNode) {
Document document = task.getDocument();
final CharSequence newDocumentText = document.getImmutableCharSequence();
final TextRange changedPsiRange = getChangedPsiRange(file, task.myLastCommittedText, newDocumentText);
if (changedPsiRange == null) {
return null;
}
final Boolean data = document.getUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY);
if (data != null) {
document.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, null);
file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, data);
}
BlockSupport blockSupport = BlockSupport.getInstance(file.getProject());
final DiffLog diffLog = blockSupport.reparseRange(file, oldFileNode, changedPsiRange, newDocumentText, task.indicator, task.myLastCommittedText);
return document1 -> {
FileViewProvider viewProvider = file.getViewProvider();
if (!task.isStillValid() || ((PsiDocumentManagerBase) PsiDocumentManager.getInstance(file.getProject())).getCachedViewProvider(document1) != viewProvider) {
return false;
}
if (file.isPhysical() && !ApplicationManager.getApplication().isWriteAccessAllowed()) {
VirtualFile vFile = viewProvider.getVirtualFile();
LOG.error("Write action expected" + "; document=" + document1 + "; file=" + file + " of " + file.getClass() + "; file.valid=" + file.isValid() + "; file.eventSystemEnabled=" + viewProvider.isEventSystemEnabled() + "; viewProvider=" + viewProvider + " of " + viewProvider.getClass() + "; language=" + file.getLanguage() + "; vFile=" + vFile + " of " + vFile.getClass() + "; free-threaded=" + SingleRootFileViewProvider.isFreeThreaded(viewProvider));
}
doActualPsiChange(file, diffLog);
assertAfterCommit(document1, file, (FileElement) oldFileNode);
return true;
};
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class PomModelImpl method reparseParallelTrees.
private void reparseParallelTrees(PsiFile changedFile, PsiToDocumentSynchronizer synchronizer) {
List<PsiFile> allFiles = changedFile.getViewProvider().getAllFiles();
if (allFiles.size() <= 1) {
return;
}
CharSequence newText = changedFile.getNode().getChars();
for (final PsiFile file : allFiles) {
FileElement fileElement = file == changedFile ? null : ((PsiFileImpl) file).getTreeElement();
Runnable changeAction = fileElement == null ? null : reparseFile(file, fileElement, newText);
if (changeAction == null)
continue;
synchronizer.setIgnorePsiEvents(true);
try {
CodeStyleManager.getInstance(file.getProject()).performActionWithFormatterDisabled(changeAction);
} finally {
synchronizer.setIgnorePsiEvents(false);
}
}
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class PsiParserFacadeImpl method createWhiteSpaceFromText.
@Override
@NotNull
public PsiElement createWhiteSpaceFromText(@NotNull @NonNls String text) throws IncorrectOperationException {
final FileElement holderElement = DummyHolderFactory.createHolder(myManager, null).getTreeElement();
final LeafElement newElement = ASTFactory.leaf(TokenType.WHITE_SPACE, holderElement.getCharTable().intern(text));
holderElement.rawAddChildren(newElement);
GeneratedMarkerVisitor.markGenerated(newElement.getPsi());
return newElement.getPsi();
}
Aggregations