Search in sources :

Example 6 with PsiManagerEx

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

the class ASTDelegatePsiElement method getManager.

@Override
public PsiManagerEx getManager() {
    Project project = ProjectCoreUtil.theOnlyOpenProject();
    if (project != null) {
        return PsiManagerEx.getInstanceEx(project);
    }
    PsiElement parent = this;
    while (parent instanceof ASTDelegatePsiElement) {
        parent = parent.getParent();
    }
    if (parent == null) {
        throw new PsiInvalidElementAccessException(this);
    }
    return (PsiManagerEx) parent.getManager();
}
Also used : PsiInvalidElementAccessException(com.intellij.psi.PsiInvalidElementAccessException) Project(com.intellij.openapi.project.Project) PsiElement(com.intellij.psi.PsiElement) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 7 with PsiManagerEx

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

the class PsiCodeFragmentImpl method clone.

@Override
protected PsiCodeFragmentImpl clone() {
    final PsiCodeFragmentImpl clone = (PsiCodeFragmentImpl) cloneImpl((FileElement) calcTreeElement().clone());
    clone.myPhysical = false;
    clone.myOriginalFile = this;
    clone.myPseudoImports = new LinkedHashMap<>(myPseudoImports);
    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 8 with PsiManagerEx

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

the class PsiModificationTrackerTest method testClassShouldNotDisappearWithoutEvents.

public void testClassShouldNotDisappearWithoutEvents() throws Exception {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    long count0 = tracker.getJavaStructureModificationCount();
    final VirtualFile file = addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
    final Document document = FileDocumentManager.getInstance().getDocument(file);
    assertNotNull(document);
    assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
    long count1 = tracker.getJavaStructureModificationCount();
    assertFalse(count1 == count0);
    WriteCommandAction.runWriteCommandAction(getProject(), () -> document.deleteString(0, document.getTextLength()));
    DocumentCommitThread.getInstance().waitForAllCommits();
    // gc softly-referenced file and AST
    PlatformTestUtil.tryGcSoftlyReachableObjects();
    final PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(getProject());
    assertNull(psiManager.getFileManager().getCachedPsiFile(file));
    assertFalse(count1 == tracker.getJavaStructureModificationCount());
    assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) Document(com.intellij.openapi.editor.Document) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 9 with PsiManagerEx

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

the class PsiModificationTrackerTest method testClassShouldNotDisappearWithoutEvents_ParentVirtualDirectoryDeleted.

public void testClassShouldNotDisappearWithoutEvents_ParentVirtualDirectoryDeleted() throws Exception {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    final PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(getProject());
    final VirtualFile file = addFileToProject("foo/Foo.java", "package foo; class Foo {}").getVirtualFile();
    assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject())));
    long count1 = tracker.getJavaStructureModificationCount();
    // gc softly-referenced file and document
    PlatformTestUtil.tryGcSoftlyReachableObjects();
    assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
    assertNull(psiManager.getFileManager().getCachedPsiFile(file));
    delete(file.getParent());
    assertNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject())));
    assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 10 with PsiManagerEx

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

the class PsiErrorElementUtil method hasErrors.

public static boolean hasErrors(@NotNull Project project, @NotNull VirtualFile virtualFile) {
    return ReadAction.compute(() -> {
        if (project.isDisposed() || !virtualFile.isValid())
            return false;
        PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(project);
        PsiFile psiFile = psiManager.getFileManager().findFile(virtualFile);
        return psiFile != null && hasErrors(psiFile);
    });
}
Also used : PsiFile(com.intellij.psi.PsiFile) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Aggregations

PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)25 PsiModificationTracker (com.intellij.psi.util.PsiModificationTracker)7 FileManager (com.intellij.psi.impl.file.impl.FileManager)6 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 FileElement (com.intellij.psi.impl.source.tree.FileElement)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 Document (com.intellij.openapi.editor.Document)2 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)2 XmlFile (com.intellij.psi.xml.XmlFile)2 File (java.io.File)2 ASTNode (com.intellij.lang.ASTNode)1 Disposable (com.intellij.openapi.Disposable)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1 VirtualFileFilter (com.intellij.openapi.vfs.VirtualFileFilter)1 PsiClass (com.intellij.psi.PsiClass)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiElement (com.intellij.psi.PsiElement)1 PsiElementFactory (com.intellij.psi.PsiElementFactory)1