Search in sources :

Example 1 with BlockSupport

use of com.intellij.psi.text.BlockSupport in project intellij-elixir by KronicDeth.

the class RemoveSpaceInFrontOfNoParenthesesStrict method invoke.

@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
    assert startElement == endElement;
    com.intellij.lang.ASTNode parentNode = startElement.getNode();
    com.intellij.lang.ASTNode whiteSpace = parentNode.findChildByType(TokenType.WHITE_SPACE);
    BlockSupport blockSupport = BlockSupport.getInstance(project);
    final int startOffset = whiteSpace.getStartOffset();
    final int endOffset = startOffset + whiteSpace.getTextLength();
    blockSupport.reparseRange(file, startOffset, endOffset, "");
}
Also used : BlockSupport(com.intellij.psi.text.BlockSupport)

Example 2 with BlockSupport

use of com.intellij.psi.text.BlockSupport in project intellij-community by JetBrains.

the class SrcRepositoryUseTest method testModification3.

public void testModification3() throws Exception {
    PsiClass aClass = myJavaFacade.findClass("pack.MyInterface1", GlobalSearchScope.allScope(myProject));
    TextRange classRange = aClass.getTextRange();
    String text = aClass.getText();
    BlockSupport blockSupport = ServiceManager.getService(myProject, BlockSupport.class);
    final PsiFile psiFile = aClass.getContainingFile();
    ApplicationManager.getApplication().runWriteAction(() -> blockSupport.reparseRange(psiFile, classRange.getStartOffset(), classRange.getEndOffset(), ""));
    LOG.assertTrue(!aClass.isValid());
    ApplicationManager.getApplication().runWriteAction(() -> blockSupport.reparseRange(psiFile, classRange.getStartOffset(), classRange.getStartOffset(), text));
    aClass = myJavaFacade.findClass("pack.MyInterface1", GlobalSearchScope.allScope(myProject));
    PsiElement[] children = aClass.getChildren();
    for (PsiElement child : children) {
        if (child instanceof PsiModifierList) {
            PsiElement parent = child.getParent();
            assertEquals(aClass, parent);
            PsiModifierList modifierList = aClass.getModifierList();
            assertEquals(modifierList, child);
        }
    }
    PsiJavaFile file = (PsiJavaFile) aClass.getContainingFile();
    PsiImportList importList = file.getImportList();
    children = importList.getChildren();
    int index = 0;
    for (PsiElement child : children) {
        if (child instanceof PsiImportStatement) {
            PsiElement parent = child.getParent();
            assertEquals(importList, parent);
            PsiImportStatement statement = importList.getImportStatements()[index++];
            assertEquals(statement, child);
        }
    }
}
Also used : TextRange(com.intellij.openapi.util.TextRange) BlockSupport(com.intellij.psi.text.BlockSupport)

Example 3 with BlockSupport

use of com.intellij.psi.text.BlockSupport 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 4 with BlockSupport

use of com.intellij.psi.text.BlockSupport in project intellij-elixir by KronicDeth.

the class ConvertKeywordPairToTypeOperation method invoke.

@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
    assert startElement == endElement;
    BlockSupport blockSupport = BlockSupport.getInstance(project);
    TextRange textRange = startElement.getTextRange();
    int startOffset = textRange.getStartOffset();
    int endOffset = textRange.getEndOffset();
    blockSupport.reparseRange(file, startOffset, endOffset, " ::");
}
Also used : TextRange(com.intellij.openapi.util.TextRange) BlockSupport(com.intellij.psi.text.BlockSupport)

Example 5 with BlockSupport

use of com.intellij.psi.text.BlockSupport in project intellij-elixir by KronicDeth.

the class ConvertMatchToTypeOperation method applyFix.

/*
     * Instance Methods
     */
/**
     * Called to apply the fix.
     *
     * @param project    {@link Project}
     * @param descriptor problem reported by the tool which provided this quick fix action
     */
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    BlockSupport blockSupport = BlockSupport.getInstance(project);
    TextRange textRange = matchOperatorASTNode.getTextRange();
    blockSupport.reparseRange(matchOperatorASTNode.getPsi().getContainingFile(), textRange.getStartOffset(), textRange.getEndOffset(), "::");
}
Also used : TextRange(com.intellij.openapi.util.TextRange) BlockSupport(com.intellij.psi.text.BlockSupport)

Aggregations

BlockSupport (com.intellij.psi.text.BlockSupport)7 TextRange (com.intellij.openapi.util.TextRange)3 Project (com.intellij.openapi.project.Project)2 DiffLog (com.intellij.psi.impl.source.text.DiffLog)2 ASTNode (com.intellij.lang.ASTNode)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 Document (com.intellij.openapi.editor.Document)1 DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 StandardProgressIndicatorBase (com.intellij.openapi.progress.util.StandardProgressIndicatorBase)1 com.intellij.openapi.util (com.intellij.openapi.util)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1