com.intellij.psi.impl.PsiManagerEx Java Examples
The following examples show how to use
com.intellij.psi.impl.PsiManagerEx.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreeViewUtil.java From consulo with Apache License 2.0 | 6 votes |
private static boolean shouldAbbreviateName(PsiPackage aPackage) { final Project project = aPackage.getProject(); ConcurrentMap<PsiPackage, Boolean> map = project.getUserData(SHOULD_ABBREV_PACK_KEY); if (map == null) { final ConcurrentMap<PsiPackage, Boolean> newMap = ContainerUtil.createConcurrentWeakMap(); map = ((UserDataHolderEx)project).putUserDataIfAbsent(SHOULD_ABBREV_PACK_KEY, newMap); if (map == newMap) { ((PsiManagerEx)PsiManager.getInstance(project)).registerRunnableToRunOnChange(new Runnable() { @Override public void run() { newMap.clear(); } }); } } Boolean ret = map.get(aPackage); if (ret != null) return ret; ret = scanPackages(aPackage, 1); map.put(aPackage, ret); return ret; }
Example #2
Source File: InjectedLanguageUtil.java From consulo with Apache License 2.0 | 6 votes |
static void clearCaches(@Nonnull PsiFile injected, @Nonnull DocumentWindowImpl documentWindow) { VirtualFileWindowImpl virtualFile = (VirtualFileWindowImpl)injected.getVirtualFile(); PsiManagerEx psiManagerEx = (PsiManagerEx)injected.getManager(); if (psiManagerEx.getProject().isDisposed()) return; DebugUtil.performPsiModification("injected clearCaches", () -> psiManagerEx.getFileManager().setViewProvider(virtualFile, null)); VirtualFile delegate = virtualFile.getDelegate(); if (!delegate.isValid()) return; FileViewProvider viewProvider = psiManagerEx.getFileManager().findCachedViewProvider(delegate); if (viewProvider == null) return; for (PsiFile hostFile : ((AbstractFileViewProvider)viewProvider).getCachedPsiFiles()) { // modification of cachedInjectedDocuments must be under InjectedLanguageManagerImpl.ourInjectionPsiLock synchronized (InjectedLanguageManagerImpl.ourInjectionPsiLock) { List<DocumentWindow> cachedInjectedDocuments = getCachedInjectedDocuments(hostFile); for (int i = cachedInjectedDocuments.size() - 1; i >= 0; i--) { DocumentWindow cachedInjectedDocument = cachedInjectedDocuments.get(i); if (cachedInjectedDocument == documentWindow) { cachedInjectedDocuments.remove(i); } } } } }
Example #3
Source File: PlatformTestCase.java From consulo with Apache License 2.0 | 6 votes |
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(); ((PsiManagerEx)PsiManager.getInstance(project)).getFileManager().cleanupForNextTest(); } LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl)LocalFileSystem.getInstance(); if (localFileSystem != null) { localFileSystem.cleanupForNextTest(); } LocalHistory.getInstance().cleanupForNextTest(); }
Example #4
Source File: DocumentWindowImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean isValid() { Place shreds; synchronized (myLock) { shreds = myShreds; // assumption: myShreds list is immutable } // can grab PsiLock in SmartPsiPointer.restore() // will check the 0th element manually (to avoid getting .getHost() twice) for (int i = 1; i < shreds.size(); i++) { PsiLanguageInjectionHost.Shred shred = shreds.get(i); if (!shred.isValid()) return false; } PsiLanguageInjectionHost.Shred firstShred = shreds.get(0); PsiLanguageInjectionHost host = firstShred.getHost(); if (host == null || firstShred.getHostRangeMarker() == null) return false; VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(this); return virtualFile != null && ((PsiManagerEx)host.getManager()).getFileManager().findCachedViewProvider(virtualFile) != null; }
Example #5
Source File: StubTreeLoaderImpl.java From consulo with Apache License 2.0 | 6 votes |
private void diagnoseLengthMismatch(VirtualFile vFile, boolean wasIndexedAlready, @Nullable Document document, boolean saved, @Nullable PsiFile cachedPsi) { String message = "Outdated stub in index: " + vFile + " " + getIndexingStampInfo(vFile) + ", doc=" + document + ", docSaved=" + saved + ", wasIndexedAlready=" + wasIndexedAlready + ", queried at " + vFile.getTimeStamp(); message += "\ndoc length=" + (document == null ? -1 : document.getTextLength()) + "\nfile length=" + vFile.getLength(); if (cachedPsi != null) { message += "\ncached PSI " + cachedPsi.getClass(); if (cachedPsi instanceof PsiFileImpl && ((PsiFileImpl)cachedPsi).isContentsLoaded()) { message += "\nPSI length=" + cachedPsi.getTextLength(); } List<Project> projects = ContainerUtil.findAll(ProjectManager.getInstance().getOpenProjects(), p -> PsiManagerEx.getInstanceEx(p).getFileManager().findCachedViewProvider(vFile) != null); message += "\nprojects with file: " + (LOG.isDebugEnabled() ? projects.toString() : projects.size()); } processError(vFile, message, new Exception()); }
Example #6
Source File: ASTDelegatePsiElement.java From consulo with Apache License 2.0 | 6 votes |
@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(); }
Example #7
Source File: TreeElement.java From consulo with Apache License 2.0 | 6 votes |
public PsiManagerEx getManager() { Project project = ProjectCoreUtil.theOnlyOpenProject(); if (project != null) { return PsiManagerEx.getInstanceEx(project); } TreeElement element; CompositeElement parent; for (element = this; (parent = element.getTreeParent()) != null; element = parent) { } if (element instanceof FileElement) { //TODO!! return element.getManager(); } parent = getTreeParent(); if (parent != null) { return parent.getManager(); } return null; }
Example #8
Source File: GlobFindUsagesTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testInMemoryFileHandledGracefully() { createBuildFile(new WorkspacePath("java/com/google/BUILD"), "glob(['**/*.java'])"); LightVirtualFile inMemoryFile = new LightVirtualFile("mockProjectViewFile", ProjectViewLanguage.INSTANCE, ""); FileManager fileManager = ((PsiManagerEx) PsiManager.getInstance(getProject())).getFileManager(); fileManager.setViewProvider( inMemoryFile, fileManager.createFileViewProvider(inMemoryFile, true)); PsiFile psiFile = fileManager.findFile(inMemoryFile); FindUsages.findAllReferences(psiFile); }
Example #9
Source File: FileElement.java From consulo with Apache License 2.0 | 5 votes |
@Override public PsiManagerEx getManager() { CompositeElement treeParent = getTreeParent(); if (treeParent != null) return treeParent.getManager(); PsiElement psi = getPsi(); if (psi == null) throw PsiInvalidElementAccessException.createByNode(this, null); return (PsiManagerEx)psi.getManager(); }
Example #10
Source File: SemServiceImpl.java From consulo with Apache License 2.0 | 5 votes |
@Inject public SemServiceImpl(Project project, PsiManager psiManager) { myProject = project; final MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe(PsiModificationTracker.TOPIC, new PsiModificationTracker.Listener() { @Override public void modificationCountChanged() { if (!isInsideAtomicChange()) { clearCache(); } } }); ((PsiManagerEx)psiManager).registerRunnableToRunOnChange(() -> { if (!isInsideAtomicChange()) { clearCache(); } }); LowMemoryWatcher.register(() -> { if (myCreatingSem.get() == 0) { clearCache(); } //System.out.println("SemService cache flushed"); }, project); }
Example #11
Source File: InjectedFileViewProvider.java From consulo with Apache License 2.0 | 5 votes |
static InjectedFileViewProvider create(@Nonnull PsiManagerEx manager, @Nonnull VirtualFileWindowImpl file, @Nonnull DocumentWindowImpl window, @Nonnull Language language) { AbstractFileViewProvider original = (AbstractFileViewProvider)manager.getFileManager().createFileViewProvider(file, false); return original instanceof TemplateLanguageFileViewProvider ? new MultipleRootsInjectedFileViewProvider.Template(manager, file, window, language, original) : original instanceof MultiplePsiFilesPerDocumentFileViewProvider ? new MultipleRootsInjectedFileViewProvider(manager, file, window, language, original) : new SingleRootInjectedFileViewProvider(manager, file, window, language); }
Example #12
Source File: ConcatenationInjectorManager.java From consulo with Apache License 2.0 | 5 votes |
@Inject public ConcatenationInjectorManager(@Nonnull Project project) { List<ConcatenationAwareInjector> extensionList = ConcatenationAwareInjector.EP_NAME.getExtensionList(project); for (ConcatenationAwareInjector concatenationAwareInjector : extensionList) { registerConcatenationInjector(concatenationAwareInjector); } // clear caches even on non-physical changes PsiManagerEx.getInstanceEx(project).registerRunnableToRunOnAnyChange(this::incModificationCount); }
Example #13
Source File: StubTreeLoaderImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override protected boolean hasPsiInManyProjects(@Nonnull final VirtualFile virtualFile) { int count = 0; for (Project project : ProjectManager.getInstance().getOpenProjects()) { if (PsiManagerEx.getInstanceEx(project).getFileManager().findCachedViewProvider(virtualFile) != null) { count++; } } return count > 1; }
Example #14
Source File: StubTreeLoaderImpl.java From consulo with Apache License 2.0 | 5 votes |
private boolean checkLengthMatch(Project project, VirtualFile vFile, boolean wasIndexedAlready, Document document, boolean saved) { PsiFile cachedPsi = PsiManagerEx.getInstanceEx(project).getFileManager().getCachedPsiFile(vFile); IndexingStampInfo indexingStampInfo = getIndexingStampInfo(vFile); if (indexingStampInfo != null && !indexingStampInfo.contentLengthMatches(vFile.getLength(), getCurrentTextContentLength(project, vFile, document, cachedPsi))) { diagnoseLengthMismatch(vFile, wasIndexedAlready, document, saved, cachedPsi); return false; } return true; }
Example #15
Source File: PushedFilePropertiesUpdaterImpl.java From consulo with Apache License 2.0 | 5 votes |
private static void reloadPsi(final VirtualFile file, final Project project) { final FileManagerImpl fileManager = (FileManagerImpl)PsiManagerEx.getInstanceEx(project).getFileManager(); if (fileManager.findCachedViewProvider(file) != null) { Runnable runnable = () -> WriteAction.run(() -> fileManager.forceReload(file)); if (ApplicationManager.getApplication().isDispatchThread()) { runnable.run(); } else { TransactionGuard.submitTransaction(project, runnable); } } }
Example #16
Source File: StubBasedPsiElementBase.java From consulo with Apache License 2.0 | 5 votes |
@Override public PsiManagerEx getManager() { Project project = ProjectCoreUtil.theOnlyOpenProject(); if (project != null) { return PsiManagerEx.getInstanceEx(project); } return (PsiManagerEx)getContainingFile().getManager(); }
Example #17
Source File: PsiErrorElementUtil.java From consulo with Apache License 2.0 | 5 votes |
public static boolean hasErrors(@Nonnull final Project project, @Nonnull final VirtualFile virtualFile) { return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { if (project.isDisposed() || !virtualFile.isValid()) { return false; } PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(project); PsiFile psiFile = psiManager.getFileManager().findFile(virtualFile); return psiFile != null && hasErrors(psiFile); } }); }
Example #18
Source File: FileTypeChooser.java From consulo with Apache License 2.0 | 5 votes |
/** * If fileName is already associated any known file type returns it. * Otherwise asks user to select file type and associates it with fileName extension if any selected. * * @return Known file type or null. Never returns {@link UnknownFileType#INSTANCE}. */ @Nullable @RequiredUIAccess public static FileType getKnownFileTypeOrAssociate(@Nonnull VirtualFile file, @Nullable Project project) { if (project != null && !(file instanceof FakeVirtualFile)) { PsiManagerEx.getInstanceEx(project).getFileManager().findFile(file); // autodetect text file if needed } FileType type = file.getFileType(); if (type == UnknownFileType.INSTANCE) { type = getKnownFileTypeOrAssociate(file.getName()); } return type; }
Example #19
Source File: FileTypeManagerTest.java From consulo with Apache License 2.0 | 5 votes |
public void testAutoDetectTextFileFromContents() throws IOException { VirtualFile vFile = myFixture.getTempDirFixture().createFile("test.xxxxxxxx"); VfsUtil.saveText(vFile, "text"); FileType type = vFile.getFileType(); assertEquals(UnknownFileType.INSTANCE, type); PsiFile psiFile = ((PsiManagerEx)PsiManager.getInstance(myFixture.getProject())).getFileManager().findFile(vFile); // autodetect text file if needed assertNotNull(psiFile); assertEquals(PlainTextFileType.INSTANCE, vFile.getFileType()); }
Example #20
Source File: PsiExtraFileReference.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Nullable @Override public PsiElement resolve() { final VirtualFile theFile = this.getElement().findTargetFile(); if (theFile == null) { return null; } else { return PsiManagerEx.getInstance(this.getElement().getProject()).findFile(theFile); } }
Example #21
Source File: SkylarkExpressionCodeFragment.java From intellij with Apache License 2.0 | 5 votes |
SkylarkExpressionCodeFragment(Project project, String fileName, String text, boolean isPhysical) { super( PsiManagerEx.getInstanceEx(project) .getFileManager() .createFileViewProvider( new LightVirtualFile(fileName, BuildFileType.INSTANCE, text), isPhysical)); this.isPhysical = isPhysical; ((SingleRootFileViewProvider) getViewProvider()).forceCachedPsi(this); }
Example #22
Source File: MockFileManager.java From consulo with Apache License 2.0 | 4 votes |
public MockFileManager(final PsiManagerEx manager) { myManager = manager; myViewProviders = FactoryMap.create(key -> new SingleRootFileViewProvider(manager, key)); }
Example #23
Source File: SmartPsiElementPointerImpl.java From consulo with Apache License 2.0 | 4 votes |
void cacheElement(@Nullable E element) { myElement = element == null ? null : PsiManagerEx.getInstanceEx(getProject()).isBatchFilesProcessingMode() ? new WeakReference<>(element) : new SoftReference<>(element); }
Example #24
Source File: MultipleRootsInjectedFileViewProvider.java From consulo with Apache License 2.0 | 4 votes |
Template(@Nonnull PsiManagerEx psiManager, @Nonnull VirtualFileWindow virtualFile, @Nonnull DocumentWindowImpl documentWindow, @Nonnull Language language, AbstractFileViewProvider original) { super(psiManager, virtualFile, documentWindow, language, original); assert myOriginalProvider instanceof TemplateLanguageFileViewProvider; }
Example #25
Source File: PsiSearchHelperImpl.java From consulo with Apache License 2.0 | 4 votes |
@Inject public PsiSearchHelperImpl(@Nonnull PsiManager manager) { myManager = (PsiManagerEx)manager; myDumbService = DumbService.getInstance(myManager.getProject()); }
Example #26
Source File: HaxePsiReferenceList.java From intellij-haxe with Apache License 2.0 | 4 votes |
@Override public PsiManagerEx getManager() { return (PsiManagerEx) mContainingClass.getManager(); }