Search in sources :

Example 1 with PsiManagerImpl

use of com.intellij.psi.impl.PsiManagerImpl in project intellij-community by JetBrains.

the class DomStubTest method prepareFile.

protected XmlFile prepareFile(String path) {
    VirtualFile virtualFile = myFixture.copyFileToProject(path);
    assertNotNull(virtualFile);
    XmlFile file = (XmlFile) ((PsiManagerEx) getPsiManager()).getFileManager().findFile(virtualFile);
    assertFalse(file.getNode().isParsed());
    ObjectStubTree tree = StubTreeLoader.getInstance().readOrBuild(getProject(), virtualFile, file);
    assertNotNull("Can't build stubs for " + path, tree);
    ((PsiManagerImpl) getPsiManager()).cleanupForNextTest();
    file = (XmlFile) getPsiManager().findFile(virtualFile);
    assertNotNull(file);
    return file;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) ObjectStubTree(com.intellij.psi.stubs.ObjectStubTree)

Example 2 with PsiManagerImpl

use of com.intellij.psi.impl.PsiManagerImpl in project intellij-community by JetBrains.

the class FileBasedIndexImpl method registerIndexableSet.

@Override
public void registerIndexableSet(@NotNull IndexableFileSet set, @Nullable Project project) {
    myIndexableSets.add(set);
    myIndexableSetToProjectMap.put(set, project);
    if (project != null) {
        ((PsiManagerImpl) PsiManager.getInstance(project)).addTreeChangePreprocessor(event -> {
            if (event.isGenericChange() && event.getCode() == PsiTreeChangeEventImpl.PsiEventType.CHILDREN_CHANGED) {
                PsiFile file = event.getFile();
                if (file != null) {
                    waitUntilIndicesAreInitialized();
                    VirtualFile virtualFile = file.getVirtualFile();
                    if (!clearUpToDateStateForPsiIndicesOfUnsavedDocuments(virtualFile)) {
                        if (virtualFile instanceof VirtualFileWithId) {
                            int fileId = ((VirtualFileWithId) virtualFile).getId();
                            boolean wasIndexed = false;
                            List<ID<?, ?>> candidates = getAffectedIndexCandidates(virtualFile);
                            for (ID<?, ?> psiBackedIndex : myPsiDependentIndices) {
                                if (!candidates.contains(psiBackedIndex))
                                    continue;
                                if (getInputFilter(psiBackedIndex).acceptInput(virtualFile)) {
                                    getIndex(psiBackedIndex).resetIndexedStateForFile(fileId);
                                    wasIndexed = true;
                                }
                            }
                            if (wasIndexed) {
                                myChangedFilesCollector.scheduleForUpdate(virtualFile);
                                IndexingStamp.flushCache(fileId);
                            }
                        }
                    }
                }
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) PsiFile(com.intellij.psi.PsiFile) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId)

Example 3 with PsiManagerImpl

use of com.intellij.psi.impl.PsiManagerImpl in project intellij-community by JetBrains.

the class PsiFileImplUtil method doDelete.

public static void doDelete(@NotNull PsiFile file) throws IncorrectOperationException {
    final PsiManagerImpl manager = (PsiManagerImpl) file.getManager();
    final VirtualFile vFile = file.getVirtualFile();
    try {
        vFile.delete(manager);
    } catch (IOException e) {
        throw new IncorrectOperationException(e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IOException(java.io.IOException)

Example 4 with PsiManagerImpl

use of com.intellij.psi.impl.PsiManagerImpl in project intellij-community by JetBrains.

the class PlatformTestCase method cleanupApplicationCaches.

public static void cleanupApplicationCaches(Project project) {
    if (project != null && !project.isDisposed()) {
        UndoManagerImpl globalInstance = (UndoManagerImpl) UndoManager.getGlobalInstance();
        if (globalInstance != null) {
            globalInstance.dropHistoryInTests();
        }
        ((UndoManagerImpl) UndoManager.getInstance(project)).dropHistoryInTests();
        ((DocumentReferenceManagerImpl) DocumentReferenceManager.getInstance()).cleanupForNextTest();
        ((PsiManagerImpl) PsiManager.getInstance(project)).cleanupForNextTest();
    }
    final ProjectManager projectManager = ProjectManager.getInstance();
    assert projectManager != null : "The ProjectManager is not initialized yet";
    ProjectManagerImpl projectManagerImpl = (ProjectManagerImpl) projectManager;
    if (projectManagerImpl.isDefaultProjectInitialized()) {
        Project defaultProject = projectManager.getDefaultProject();
        ((PsiManagerImpl) PsiManager.getInstance(defaultProject)).cleanupForNextTest();
    }
    AsyncHighlighterUpdater.completeAsyncTasks();
    ((FileBasedIndexImpl) FileBasedIndex.getInstance()).cleanupForNextTest();
    LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl) LocalFileSystem.getInstance();
    if (localFileSystem != null) {
        localFileSystem.cleanupForNextTest();
    }
}
Also used : UndoManagerImpl(com.intellij.openapi.command.impl.UndoManagerImpl) Project(com.intellij.openapi.project.Project) DocumentReferenceManagerImpl(com.intellij.openapi.command.impl.DocumentReferenceManagerImpl) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) FileBasedIndexImpl(com.intellij.util.indexing.FileBasedIndexImpl) LocalFileSystemImpl(com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl) ProjectManager(com.intellij.openapi.project.ProjectManager) ProjectManagerImpl(com.intellij.openapi.project.impl.ProjectManagerImpl)

Example 5 with PsiManagerImpl

use of com.intellij.psi.impl.PsiManagerImpl in project intellij-community by JetBrains.

the class PsiEventsTest method testTreeChangePreprocessorThrowsException.

public void testTreeChangePreprocessorThrowsException() throws Exception {
    VirtualFile vFile = createFile("a.xml", "<tag/>").getVirtualFile();
    Document document = FileDocumentManager.getInstance().getDocument(vFile);
    assert document != null;
    PsiTreeChangePreprocessor preprocessor = event -> {
        if (!event.getCode().name().startsWith("BEFORE") && !event.isGenericChange()) {
            throw new NullPointerException();
        }
    };
    ((PsiManagerImpl) getPsiManager()).addTreeChangePreprocessor(preprocessor);
    try {
        WriteCommandAction.runWriteCommandAction(myProject, () -> document.insertString(0, " "));
        PsiDocumentManager.getInstance(myProject).commitAllDocuments();
        fail("NPE expected");
    } catch (NullPointerException ignore) {
    } finally {
        ((PsiManagerImpl) getPsiManager()).removeTreeChangePreprocessor(preprocessor);
    }
    WriteCommandAction.runWriteCommandAction(myProject, () -> document.insertString(0, " "));
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    assertEquals("  <tag/>", getPsiManager().findFile(vFile).getText());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) MemoryDumpHelper(com.intellij.util.MemoryDumpHelper) com.intellij.testFramework(com.intellij.testFramework) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) FileTypeManagerEx(com.intellij.openapi.fileTypes.ex.FileTypeManagerEx) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) WaitFor(com.intellij.util.WaitFor) ModuleRootModificationUtil(com.intellij.openapi.roots.ModuleRootModificationUtil) ReadOnlyAttributeUtil(com.intellij.util.io.ReadOnlyAttributeUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) FileUtil(com.intellij.openapi.util.io.FileUtil) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) PsiTreeChangePreprocessor(com.intellij.psi.impl.PsiTreeChangePreprocessor) PsiTreeChangePreprocessor(com.intellij.psi.impl.PsiTreeChangePreprocessor) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) Document(com.intellij.openapi.editor.Document)

Aggregations

PsiManagerImpl (com.intellij.psi.impl.PsiManagerImpl)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 IOException (java.io.IOException)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 Document (com.intellij.openapi.editor.Document)2 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)2 FileType (com.intellij.openapi.fileTypes.FileType)2 PsiFile (com.intellij.psi.PsiFile)2 PsiTreeChangeEventImpl (com.intellij.psi.impl.PsiTreeChangeEventImpl)2 LocalQuickFixAndIntentionActionOnPsiElement (com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement)1 ASTNode (com.intellij.lang.ASTNode)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 DocumentReferenceManagerImpl (com.intellij.openapi.command.impl.DocumentReferenceManagerImpl)1 UndoManagerImpl (com.intellij.openapi.command.impl.UndoManagerImpl)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 UnknownFileType (com.intellij.openapi.fileTypes.UnknownFileType)1 FileTypeManagerEx (com.intellij.openapi.fileTypes.ex.FileTypeManagerEx)1 Project (com.intellij.openapi.project.Project)1 ProjectManager (com.intellij.openapi.project.ProjectManager)1