Search in sources :

Example 6 with FileElement

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;
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) FileElement(com.intellij.psi.impl.source.tree.FileElement) FileManager(com.intellij.psi.impl.file.impl.FileManager) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 7 with FileElement

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;
}
Also used : Project(com.intellij.openapi.project.Project) JavaLexer(com.intellij.lang.java.lexer.JavaLexer) Lexer(com.intellij.lexer.Lexer) FileElement(com.intellij.psi.impl.source.tree.FileElement) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with FileElement

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;
    };
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) PomModelEvent(com.intellij.pom.event.PomModelEvent) UIUtil(com.intellij.util.ui.UIUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Date(java.util.Date) Document(com.intellij.openapi.editor.Document) TimeoutException(java.util.concurrent.TimeoutException) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) com.intellij.openapi.application(com.intellij.openapi.application) SmartList(com.intellij.util.SmartList) FileASTNode(com.intellij.lang.FileASTNode) PomModel(com.intellij.pom.PomModel) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) Logger(com.intellij.openapi.diagnostic.Logger) ProgressManager(com.intellij.openapi.progress.ProgressManager) BlockSupport(com.intellij.psi.text.BlockSupport) Set(java.util.Set) FileElement(com.intellij.psi.impl.source.tree.FileElement) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) TreeAspect(com.intellij.pom.tree.TreeAspect) PooledThreadExecutor(org.jetbrains.ide.PooledThreadExecutor) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) NonNls(org.jetbrains.annotations.NonNls) SimpleDateFormat(java.text.SimpleDateFormat) ForeignLeafPsiElement(com.intellij.psi.impl.source.tree.ForeignLeafPsiElement) ContainerUtil(com.intellij.util.containers.ContainerUtil) PomManager(com.intellij.pom.PomManager) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) TreeAspectEvent(com.intellij.pom.tree.TreeAspectEvent) Project(com.intellij.openapi.project.Project) ExecutorService(java.util.concurrent.ExecutorService) BoundedTaskExecutor(com.intellij.util.concurrency.BoundedTaskExecutor) DiffLog(com.intellij.psi.impl.source.text.DiffLog) HashSetQueue(com.intellij.util.containers.HashSetQueue) ReentrantLock(java.util.concurrent.locks.ReentrantLock) StandardProgressIndicatorBase(com.intellij.openapi.progress.util.StandardProgressIndicatorBase) StringUtil(com.intellij.openapi.util.text.StringUtil) TreeUtil(com.intellij.psi.impl.source.tree.TreeUtil) Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ASTNode(com.intellij.lang.ASTNode) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) Lock(java.util.concurrent.locks.Lock) ExceptionUtil(com.intellij.util.ExceptionUtil) Collections(java.util.Collections) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileElement(com.intellij.psi.impl.source.tree.FileElement) Document(com.intellij.openapi.editor.Document) BlockSupport(com.intellij.psi.text.BlockSupport) DiffLog(com.intellij.psi.impl.source.text.DiffLog) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with FileElement

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);
        }
    }
}
Also used : ThrowableRunnable(com.intellij.util.ThrowableRunnable) FileElement(com.intellij.psi.impl.source.tree.FileElement)

Example 10 with FileElement

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();
}
Also used : FileElement(com.intellij.psi.impl.source.tree.FileElement) LeafElement(com.intellij.psi.impl.source.tree.LeafElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileElement (com.intellij.psi.impl.source.tree.FileElement)33 NotNull (org.jetbrains.annotations.NotNull)10 ASTNode (com.intellij.lang.ASTNode)7 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)6 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)5 FileManager (com.intellij.psi.impl.file.impl.FileManager)5 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)4 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)3 Nullable (org.jetbrains.annotations.Nullable)3 Lexer (com.intellij.lexer.Lexer)2 Disposable (com.intellij.openapi.Disposable)2 Document (com.intellij.openapi.editor.Document)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 PomModel (com.intellij.pom.PomModel)2 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)2 GeneratedMarkerVisitor (com.intellij.psi.impl.GeneratedMarkerVisitor)2 DummyHolder (com.intellij.psi.impl.source.DummyHolder)2 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)2