Search in sources :

Example 1 with DiffLog

use of com.intellij.psi.impl.source.text.DiffLog in project kotlin by JetBrains.

the class KtParsingTestCase method ensureCorrectReparse.

public static void ensureCorrectReparse(@NotNull PsiFile file) {
    String psiToStringDefault = DebugUtil.psiToString(file, false, false);
    String fileText = file.getText();
    DiffLog diffLog = (new BlockSupportImpl(file.getProject())).reparseRange(file, file.getNode(), TextRange.allOf(fileText), fileText, new EmptyProgressIndicator(), fileText);
    diffLog.performActualPsiChange(file);
    TestCase.assertEquals(psiToStringDefault, DebugUtil.psiToString(file, false, false));
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) BlockSupportImpl(com.intellij.psi.impl.source.text.BlockSupportImpl) DiffLog(com.intellij.psi.impl.source.text.DiffLog)

Example 2 with DiffLog

use of com.intellij.psi.impl.source.text.DiffLog in project intellij-community by JetBrains.

the class MultiHostRegistrarImpl method registerDocument.

// under com.intellij.psi.PsiLock.LOCK
private static PsiFile registerDocument(final DocumentWindowImpl documentWindow, final PsiFile injectedPsi, final Place shreds, final PsiFile hostPsiFile, final PsiDocumentManager documentManager) {
    List<DocumentWindow> injected = InjectedLanguageUtil.getCachedInjectedDocuments(hostPsiFile);
    for (int i = injected.size() - 1; i >= 0; i--) {
        DocumentWindowImpl oldDocument = (DocumentWindowImpl) injected.get(i);
        final PsiFileImpl oldFile = (PsiFileImpl) documentManager.getCachedPsiFile(oldDocument);
        FileViewProvider viewProvider;
        if (oldFile == null || !oldFile.isValid() || !((viewProvider = oldFile.getViewProvider()) instanceof InjectedFileViewProvider) || ((InjectedFileViewProvider) viewProvider).isDisposed()) {
            injected.remove(i);
            Disposer.dispose(oldDocument);
            continue;
        }
        InjectedFileViewProvider oldViewProvider = (InjectedFileViewProvider) viewProvider;
        final ASTNode injectedNode = injectedPsi.getNode();
        final ASTNode oldFileNode = oldFile.getNode();
        assert injectedNode != null : "New node is null";
        if (oldDocument.areRangesEqual(documentWindow)) {
            if (oldFile.getFileType() != injectedPsi.getFileType() || oldFile.getLanguage() != injectedPsi.getLanguage()) {
                injected.remove(i);
                Disposer.dispose(oldDocument);
                continue;
            }
            oldFile.putUserData(FileContextUtil.INJECTED_IN_ELEMENT, injectedPsi.getUserData(FileContextUtil.INJECTED_IN_ELEMENT));
            assert shreds.isValid();
            if (!oldFile.textMatches(injectedPsi)) {
                oldViewProvider.performNonPhysically(() -> {
                    DebugUtil.startPsiModification("injected tree diff");
                    try {
                        final DiffLog diffLog = BlockSupportImpl.mergeTrees(oldFile, oldFileNode, injectedNode, new DaemonProgressIndicator(), oldFileNode.getText());
                        DocumentCommitThread.doActualPsiChange(oldFile, diffLog);
                    } finally {
                        DebugUtil.finishPsiModification();
                    }
                });
            }
            assert shreds.isValid();
            return oldFile;
        }
    }
    injected.add(documentWindow);
    return injectedPsi;
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) DocumentWindowImpl(com.intellij.injected.editor.DocumentWindowImpl) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) ASTNode(com.intellij.lang.ASTNode) DiffLog(com.intellij.psi.impl.source.text.DiffLog)

Example 3 with DiffLog

use of com.intellij.psi.impl.source.text.DiffLog in project intellij-community by JetBrains.

the class PsiBuilderImpl method buildTree.

@NotNull
private ASTNode buildTree() {
    final StartMarker rootMarker = prepareLightTree();
    final boolean isTooDeep = myFile != null && BlockSupport.isTooDeep(myFile.getOriginalFile());
    if (myOriginalTree != null && !isTooDeep) {
        DiffLog diffLog = merge(myOriginalTree, rootMarker, myLastCommittedText);
        throw new BlockSupport.ReparsedSuccessfullyException(diffLog);
    }
    final TreeElement rootNode = createRootAST(rootMarker);
    bind(rootMarker, (CompositeElement) rootNode);
    if (isTooDeep && !(rootNode instanceof FileElement)) {
        final ASTNode childNode = rootNode.getFirstChildNode();
        childNode.putUserData(BlockSupport.TREE_DEPTH_LIMIT_EXCEEDED, Boolean.TRUE);
    }
    assert rootNode.getTextLength() == myText.length() : rootNode.getElementType();
    return rootNode;
}
Also used : DiffLog(com.intellij.psi.impl.source.text.DiffLog) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with DiffLog

use of com.intellij.psi.impl.source.text.DiffLog 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 5 with DiffLog

use of com.intellij.psi.impl.source.text.DiffLog in project intellij-community by JetBrains.

the class PsiBuilderImpl method merge.

@NotNull
private DiffLog merge(@NotNull final ASTNode oldRoot, @NotNull StartMarker newRoot, @NotNull CharSequence lastCommittedText) {
    DiffLog diffLog = new DiffLog();
    DiffTreeChangeBuilder<ASTNode, LighterASTNode> builder = new ConvertFromTokensToASTBuilder(newRoot, diffLog);
    MyTreeStructure treeStructure = new MyTreeStructure(newRoot, null);
    ShallowNodeComparator<ASTNode, LighterASTNode> comparator = new MyComparator(getUserDataUnprotected(CUSTOM_COMPARATOR), treeStructure);
    ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
    BlockSupportImpl.diffTrees(oldRoot, builder, comparator, treeStructure, indicator == null ? new EmptyProgressIndicator() : indicator, lastCommittedText);
    return diffLog;
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DiffLog(com.intellij.psi.impl.source.text.DiffLog) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiffLog (com.intellij.psi.impl.source.text.DiffLog)8 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)4 NotNull (org.jetbrains.annotations.NotNull)3 ASTNode (com.intellij.lang.ASTNode)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 PomModelEvent (com.intellij.pom.event.PomModelEvent)2 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)2 TreeAspectEvent (com.intellij.pom.tree.TreeAspectEvent)2 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)2 BlockSupportImpl (com.intellij.psi.impl.source.text.BlockSupportImpl)2 BlockSupport (com.intellij.psi.text.BlockSupport)2 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)1 FileASTNode (com.intellij.lang.FileASTNode)1 Disposable (com.intellij.openapi.Disposable)1 com.intellij.openapi.application (com.intellij.openapi.application)1 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1