Search in sources :

Example 11 with PsiManagerEx

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

the class GrThrowsClauseImpl method getReferenceElements.

@Override
@NotNull
public PsiJavaCodeReferenceElement[] getReferenceElements() {
    PsiClassType[] types = getReferencedTypes();
    if (types.length == 0)
        return PsiJavaCodeReferenceElement.EMPTY_ARRAY;
    PsiManagerEx manager = getManager();
    List<PsiJavaCodeReferenceElement> result = ContainerUtil.newArrayList();
    for (PsiClassType type : types) {
        PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
        PsiClass resolved = resolveResult.getElement();
        if (resolved != null) {
            result.add(new LightClassReference(manager, type.getCanonicalText(), resolved, resolveResult.getSubstitutor()));
        }
    }
    return result.toArray(new PsiJavaCodeReferenceElement[result.size()]);
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) LightClassReference(com.intellij.psi.impl.light.LightClassReference) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiClass(com.intellij.psi.PsiClass) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) NotNull(org.jetbrains.annotations.NotNull)

Example 12 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 13 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 14 with PsiManagerEx

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

the class DartExpressionCodeFragmentImpl method clone.

protected DartExpressionCodeFragmentImpl clone() {
    final DartExpressionCodeFragmentImpl clone = (DartExpressionCodeFragmentImpl) cloneImpl((FileElement) calcTreeElement().clone());
    clone.myPhysical = false;
    clone.myOriginalFile = this;
    final FileManager fileManager = ((PsiManagerEx) getManager()).getFileManager();
    final SingleRootFileViewProvider cloneViewProvider = (SingleRootFileViewProvider) fileManager.createFileViewProvider(new LightVirtualFile(getName(), getLanguage(), getText()), false);
    clone.myViewProvider = cloneViewProvider;
    cloneViewProvider.forceCachedPsi(clone);
    clone.init(getContentElementType(), getContentElementType());
    return clone;
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) FileElement(com.intellij.psi.impl.source.tree.FileElement) SingleRootFileViewProvider(com.intellij.psi.SingleRootFileViewProvider) FileManager(com.intellij.psi.impl.file.impl.FileManager) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 15 with PsiManagerEx

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

the class ModuleResourceRepositoryTest method testPsiListenerWithVirtualFiles.

/**
   * This tests that even if we initialize ResourceFolderRepository with VirtualFiles and the test code is careful to only work with
   * VirtualFiles, we still get the PsiListener events.
   *
   * Namely, {@link com.intellij.psi.impl.file.impl.PsiVFSListener} skips notifying other listeners if the parent directory has never
   * been initialized as PSI.
   */
public void testPsiListenerWithVirtualFiles() throws Exception {
    final VirtualFile res1 = myFixture.copyFileToProject(LAYOUT, "res/layout/layout.xml").getParent().getParent();
    // Stash the resource directory somewhere deep. Sometimes the test framework + VFS listener does automatically create
    // a PsiDirectory for the top level. We only want a VirtualFile representation, and not the PsiDirectory representation.
    final VirtualFile layout2 = myFixture.copyFileToProject(LAYOUT_OVERLAY, "foo/baz/bar/res/layout/foo_activity.xml");
    final VirtualFile res2 = layout2.getParent().getParent();
    assertNotSame(res1, res2);
    // Check that we indeed don't have the PsiDirectory already cached, by poking at the implementation classes.
    PsiManagerEx psiManager = (PsiManagerEx) PsiManager.getInstance(getProject());
    FileManagerImpl fileManager = (FileManagerImpl) psiManager.getFileManager();
    assertNull(fileManager.getCachedDirectory(res2));
    assertNull(fileManager.getCachedPsiFile(layout2));
    ModuleResourceRepository resources = ModuleResourceRepository.createForTest(myFacet, Arrays.asList(res1, res2));
    assertNotNull(fileManager.getCachedDirectory(res2));
    long generation = resources.getModificationCount();
    assertTrue(resources.hasResourceItem(ResourceType.LAYOUT, "foo_activity"));
    assertFalse(resources.hasResourceItem(ResourceType.LAYOUT, "bar_activity"));
    WriteCommandAction.runWriteCommandAction(null, new Runnable() {

        @Override
        public void run() {
            try {
                layout2.rename(this, "bar_activity.xml");
            } catch (IOException e) {
                fail(e.toString());
            }
        }
    });
    assertTrue(resources.hasResourceItem(ResourceType.LAYOUT, "bar_activity"));
    assertFalse(resources.hasResourceItem(ResourceType.LAYOUT, "foo_activity"));
    assertTrue(resources.getModificationCount() > generation);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) FileManagerImpl(com.intellij.psi.impl.file.impl.FileManagerImpl) 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