com.intellij.psi.util.PsiModificationTracker Java Examples
The following examples show how to use
com.intellij.psi.util.PsiModificationTracker.
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: ResourcePathIndex.java From idea-php-typo3-plugin with MIT License | 6 votes |
@NotNull private synchronized static Collection<String> getAllResourceKeys(@NotNull Project project) { CachedValue<Collection<String>> userData = project.getUserData(RESOURCE_KEYS); if (userData != null && userData.hasUpToDateValue()) { return RESOURCE_KEYS_LOCAL_CACHE.getOrDefault(project, new ArrayList<>()); } CachedValue<Collection<String>> cachedValue = CachedValuesManager.getManager(project).createCachedValue(() -> { Collection<String> allKeys = FileBasedIndex.getInstance().getAllKeys(ResourcePathIndex.KEY, project); if (RESOURCE_KEYS_LOCAL_CACHE.containsKey(project)) { RESOURCE_KEYS_LOCAL_CACHE.replace(project, allKeys); } else { RESOURCE_KEYS_LOCAL_CACHE.put(project, allKeys); } return CachedValueProvider.Result.create(new ArrayList<>(), PsiModificationTracker.MODIFICATION_COUNT); }, false); project.putUserData(RESOURCE_KEYS, cachedValue); return RESOURCE_KEYS_LOCAL_CACHE.getOrDefault(project, cachedValue.getValue()); }
Example #2
Source File: BinaryContextRunConfigurationProducer.java From intellij with Apache License 2.0 | 6 votes |
@Nullable private BinaryRunContext findRunContext(ConfigurationContext context) { if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) { // not a binary run context return null; } ContextWrapper wrapper = new ContextWrapper(context); PsiElement psi = context.getPsiLocation(); return psi == null ? null : CachedValuesManager.getCachedValue( psi, () -> CachedValueProvider.Result.create( doFindRunContext(wrapper.context), PsiModificationTracker.MODIFICATION_COUNT, BlazeSyncModificationTracker.getInstance(wrapper.context.getProject()))); }
Example #3
Source File: ProducerUtils.java From intellij with Apache License 2.0 | 6 votes |
/** * Based on {@link JUnitUtil#isTestClass}. We don't use that directly because it returns true for * all inner classes of a test class, regardless of whether they're also test classes. */ public static boolean isTestClass(PsiClass psiClass) { if (psiClass.getQualifiedName() == null) { return false; } if (JUnitUtil.isJUnit5(psiClass) && JUnitUtil.isJUnit5TestClass(psiClass, true)) { return true; } if (!PsiClassUtil.isRunnableClass(psiClass, true, true)) { return false; } if (isJUnit4Class(psiClass)) { return true; } if (isTestCaseInheritor(psiClass)) { return true; } return CachedValuesManager.getCachedValue( psiClass, () -> CachedValueProvider.Result.create( hasTestOrSuiteMethods(psiClass), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT)); }
Example #4
Source File: TestContextRunConfigurationProducer.java From intellij with Apache License 2.0 | 6 votes |
@Nullable private RunConfigurationContext findTestContext(ConfigurationContext context) { if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) { // handled by a different producer return null; } ContextWrapper wrapper = new ContextWrapper(context); PsiElement psi = context.getPsiLocation(); return psi == null ? null : CachedValuesManager.getCachedValue( psi, cacheKey, () -> CachedValueProvider.Result.create( doFindTestContext(wrapper.context), PsiModificationTracker.MODIFICATION_COUNT, BlazeSyncModificationTracker.getInstance(wrapper.context.getProject()))); }
Example #5
Source File: VirtualFileTestContextProvider.java From intellij with Apache License 2.0 | 6 votes |
@Nullable @Override public RunConfigurationContext getTestContext(ConfigurationContext context) { PsiElement psi = context.getPsiLocation(); if (!(psi instanceof PsiFileSystemItem) || !(psi instanceof FakePsiElement)) { return null; } VirtualFile vf = ((PsiFileSystemItem) psi).getVirtualFile(); if (vf == null) { return null; } WorkspacePath path = getWorkspacePath(context.getProject(), vf); if (path == null) { return null; } return CachedValuesManager.getCachedValue( psi, () -> CachedValueProvider.Result.create( doFindTestContext(context, vf, psi, path), PsiModificationTracker.MODIFICATION_COUNT, BlazeSyncModificationTracker.getInstance(context.getProject()))); }
Example #6
Source File: CtrlMouseHandler.java From consulo with Apache License 2.0 | 6 votes |
private void updateOnPsiChanges(@Nonnull LightweightHint hint, @Nonnull Info info, @Nonnull Consumer<? super String> textConsumer, @Nonnull String oldText, @Nonnull Editor editor) { if (!hint.isVisible()) return; Disposable hintDisposable = Disposable.newDisposable("CtrlMouseHandler.TooltipProvider.updateOnPsiChanges"); hint.addHintListener(__ -> Disposer.dispose(hintDisposable)); myProject.getMessageBus().connect(hintDisposable).subscribe(PsiModificationTracker.TOPIC, () -> ReadAction.nonBlocking(() -> { try { DocInfo newDocInfo = info.getInfo(); return (Runnable)() -> { if (newDocInfo.text != null && !oldText.equals(newDocInfo.text)) { updateText(newDocInfo.text, textConsumer, hint, editor); } }; } catch (IndexNotReadyException e) { showDumbModeNotification(myProject); return createDisposalContinuation(); } }).finishOnUiThread(ModalityState.defaultModalityState(), Runnable::run).withDocumentsCommitted(myProject).expireWith(hintDisposable).expireWhen(() -> !info.isValid(editor.getDocument())) .coalesceBy(hint).submit(AppExecutorUtil.getAppExecutorService())); }
Example #7
Source File: SubscriberIndexUtil.java From idea-php-shopware-plugin with MIT License | 6 votes |
@NotNull public static Collection<ServiceResource> getIndexedBootstrapResources(@NotNull Project project) { // cache CachedValue<Collection<ServiceResource>> cache = project.getUserData(SERVICE_RESOURCE); if (cache == null) { cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create( getIndexedBootstrapResources(project, BootstrapResource.INIT_RESOURCE, BootstrapResource.AFTER_INIT_RESOURCE, BootstrapResource.AFTER_REGISTER_RESOURCE), PsiModificationTracker.MODIFICATION_COUNT ), false); project.putUserData(SERVICE_RESOURCE, cache); } return cache.getValue(); }
Example #8
Source File: Unity3dManifest.java From consulo-unity3d with Apache License 2.0 | 6 votes |
@Nonnull public static Unity3dManifest parse(@Nonnull Project project) { return CachedValuesManager.getManager(project).getCachedValue(project, () -> { Path projectPath = Paths.get(project.getBasePath()); Path manifestJson = projectPath.resolve(Paths.get("Packages", "manifest.json")); if(Files.exists(manifestJson)) { Gson gson = new Gson(); try (Reader reader = Files.newBufferedReader(manifestJson)) { return CachedValueProvider.Result.create(gson.fromJson(reader, Unity3dManifest.class), PsiModificationTracker.MODIFICATION_COUNT); } catch(Exception e) { LOG.error(e); } } return CachedValueProvider.Result.create(EMPTY, PsiModificationTracker.MODIFICATION_COUNT); }); }
Example #9
Source File: PsiCachedValue.java From consulo with Apache License 2.0 | 6 votes |
@Override protected long getTimeStamp(@Nonnull Object dependency) { if (dependency instanceof PsiDirectory) { return myManager.getModificationTracker().getOutOfCodeBlockModificationCount(); } if (dependency instanceof PsiElement) { PsiElement element = (PsiElement)dependency; if (!element.isValid()) return -1; PsiFile containingFile = element.getContainingFile(); if (containingFile != null) return containingFile.getModificationStamp(); } if (dependency == PsiModificationTracker.MODIFICATION_COUNT || dependency == PSI_MOD_COUNT_OPTIMIZATION) { return myManager.getModificationTracker().getModificationCount(); } if (dependency == PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT) { return myManager.getModificationTracker().getOutOfCodeBlockModificationCount(); } if (dependency == PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT) { return myManager.getModificationTracker().getJavaStructureModificationCount(); } return super.getTimeStamp(dependency); }
Example #10
Source File: GlobalNamespaceLoader.java From idea-php-drupal-symfony2-bridge with MIT License | 6 votes |
@Override @NotNull public Collection<String> getGlobalNamespaces(@NotNull AnnotationGlobalNamespacesLoaderParameter parameter) { Project project = parameter.getProject(); CachedValue<Collection<String>> cache = project.getUserData(CACHE); if(cache == null) { cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(getGlobalNamespacesInner(project), PsiModificationTracker.MODIFICATION_COUNT), false ); project.putUserData(CACHE, cache); } return cache.getValue(); }
Example #11
Source File: TextEditorHighlightingPass.java From consulo with Apache License 2.0 | 6 votes |
protected boolean isValid() { if (isDumbMode() && !DumbService.isDumbAware(this)) { return false; } if (PsiModificationTracker.SERVICE.getInstance(myProject).getModificationCount() != myInitialPsiStamp) { return false; } if (myDocument != null) { if (myDocument.getModificationStamp() != myInitialDocStamp) return false; PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); return file != null && file.isValid(); } return true; }
Example #12
Source File: SymfonyUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private static boolean compare(@NotNull Project project, @NotNull String version, @NotNull Comparator comparator) { Set<String> cache = CachedValuesManager.getManager(project).getCachedValue( project, CACHE, () -> CachedValueProvider.Result.create(getVersions(project), PsiModificationTracker.MODIFICATION_COUNT), false ); for (String s : cache) { if(comparator.accepts(s)) { return true; } } return false; }
Example #13
Source File: CSharpModifierListImplUtil.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nonnull @RequiredReadAction public static EnumSet<CSharpModifier> getModifiersCached(@Nonnull CSharpModifierList modifierList) { if(!modifierList.isValid()) { return emptySet; } return CachedValuesManager.getCachedValue(modifierList, () -> { Set<CSharpModifier> modifiers = new THashSet<>(); for(CSharpModifier modifier : CSharpModifier.values()) { if(hasModifier(modifierList, modifier)) { modifiers.add(modifier); } } return CachedValueProvider.Result.create(modifiers.isEmpty() ? emptySet : EnumSet.copyOf(modifiers), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); }); }
Example #14
Source File: CSharpTypeDeclarationImpl.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Nonnull @Override public DotNetTypeRef[] getExtendTypeRefs() { return CachedValuesManager.getCachedValue(this, new CachedValueProvider<DotNetTypeRef[]>() { @Nullable @Override @RequiredReadAction public Result<DotNetTypeRef[]> compute() { DotNetTypeRef[] extendTypeRefs = CSharpTypeDeclarationImplUtil.getExtendTypeRefs(CSharpTypeDeclarationImpl.this); return Result.create(extendTypeRefs, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); } }); }
Example #15
Source File: ConfigAddPathTwigNamespaces.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull @Override public Collection<TwigPath> getNamespaces(@NotNull TwigNamespaceExtensionParameter parameter) { Project project = parameter.getProject(); Collection<Pair<String, String>> cachedValue = CachedValuesManager.getManager(project).getCachedValue( project, CACHE, () -> CachedValueProvider.Result.create(getTwigPaths(project), PsiModificationTracker.MODIFICATION_COUNT), false ); // TwigPath is not cache able as it right now; we need to build it here return cachedValue.stream() .map(p -> new TwigPath(p.getFirst(), p.getSecond(), TwigUtil.NamespaceType.ADD_PATH, true)) .collect(Collectors.toList()); }
Example #16
Source File: CSharpBlockStatementImpl.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nonnull private Collection<CSharpElementGroup<CSharpMethodDeclaration>> getLocalMethods() { return CachedValuesManager.getCachedValue(this, () -> { MultiMap<String, CSharpMethodDeclaration> multiMap = new MultiMap<>(); for(DotNetStatement statement : getStatements()) { if(statement instanceof CSharpLocalMethodDeclarationStatementImpl) { CSharpMethodDeclaration method = ((CSharpLocalMethodDeclarationStatementImpl) statement).getMethod(); multiMap.putValue(method.getName(), method); } } List<CSharpElementGroup<CSharpMethodDeclaration>> list = multiMap .entrySet() .stream() .map(e -> new CSharpElementGroupImpl<>(getProject(), e.getKey(), e.getValue())) .collect(Collectors.toList()); return CachedValueProvider.Result.create(list, PsiModificationTracker.MODIFICATION_COUNT); }); }
Example #17
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 #18
Source File: MockPsiManager.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public PsiModificationTracker getModificationTracker() { if (myPsiModificationTracker == null) { myPsiModificationTracker = new PsiModificationTrackerImpl(Application.get(), myProject); } return myPsiModificationTracker; }
Example #19
Source File: PsiCachedValue.java From consulo with Apache License 2.0 | 5 votes |
private boolean anyChangeImpliesPsiCounterChange(@Nonnull Object dependency) { return dependency instanceof PsiElement && isVeryPhysical((PsiElement)dependency) || dependency instanceof ProjectRootModificationTracker || dependency instanceof PsiModificationTracker || dependency == PsiModificationTracker.MODIFICATION_COUNT || dependency == PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT || dependency == PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT; }
Example #20
Source File: DaemonCodeAnalyzerImpl.java From consulo with Apache License 2.0 | 5 votes |
@TestOnly private boolean waitInOtherThread(int millis, boolean canChangeDocument) throws Throwable { Disposable disposable = Disposable.newDisposable(); // last hope protection against PsiModificationTrackerImpl.incCounter() craziness (yes, Kotlin) myProject.getMessageBus().connect(disposable).subscribe(PsiModificationTracker.TOPIC, () -> { throw new IllegalStateException("You must not perform PSI modifications from inside highlighting"); }); if (!canChangeDocument) { myProject.getMessageBus().connect(disposable).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonListener() { @Override public void daemonCancelEventOccurred(@Nonnull String reason) { throw new IllegalStateException("You must not cancel daemon inside highlighting test: " + reason); } }); } try { Future<Boolean> future = ApplicationManager.getApplication().executeOnPooledThread(() -> { try { return myPassExecutorService.waitFor(millis); } catch (Throwable e) { throw new RuntimeException(e); } }); return future.get(); } finally { Disposer.dispose(disposable); } }
Example #21
Source File: GlobalTwigConfigVariableCollector.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@NotNull private Map<String, PsiVariable> getGlobals(@NotNull Project project) { return CachedValuesManager.getManager(project).getCachedValue( project, CACHE, () -> CachedValueProvider.Result.create(getGlobalsInner(project), PsiModificationTracker.MODIFICATION_COUNT), false ); }
Example #22
Source File: TranslationIndex.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@NotNull private Collection<File> getTranslationRoot() { return CachedValuesManager.getManager(project) .getCachedValue( project, SYMFONY_TRANSLATION_COMPILED, () -> CachedValueProvider.Result.create(getTranslationRootInnerTime(), PsiModificationTracker.MODIFICATION_COUNT), false ); }
Example #23
Source File: ServiceIndexUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * Get all services that extends a given "parent" id */ @NotNull public static Map<String, Collection<ContainerService>> getParentServices(@NotNull Project project) { return CachedValuesManager.getManager(project).getCachedValue( project, SERVICE_PARENT, () -> CachedValueProvider.Result.create(getParentServicesInner(project), PsiModificationTracker.MODIFICATION_COUNT), false ); }
Example #24
Source File: ServiceIndexUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@NotNull public static Map<String, Collection<ContainerService>> getDecoratedServices(@NotNull Project project) { return CachedValuesManager.getManager(project).getCachedValue( project, SERVICE_DECORATION_CACHE, () -> CachedValueProvider.Result.create(getDecoratedServicesInner(project), PsiModificationTracker.MODIFICATION_COUNT), false ); }
Example #25
Source File: AbstractRefactoringPanel.java From IntelliJDeodorant with MIT License | 5 votes |
/** * Adds a listener that invalidates found refactoring opportunities if the structure of PSI is changed. */ private void registerPsiModificationListener() { if (!isPreviewUsage) { MessageBus projectMessageBus = scope.getProject().getMessageBus(); projectMessageBus.connect().subscribe(PsiModificationTracker.TOPIC, () -> ApplicationManager.getApplication().invokeLater(this::showRefreshingProposal)); } }
Example #26
Source File: JsonFileIndexTwigNamespaces.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@NotNull @Override public Collection<TwigPath> getNamespaces(final @NotNull TwigNamespaceExtensionParameter parameter) { Project project = parameter.getProject(); return CachedValuesManager.getManager(project).getCachedValue( project, CACHE, () -> CachedValueProvider.Result.create(getNamespacesInner(project), PsiModificationTracker.MODIFICATION_COUNT), false ); }
Example #27
Source File: DesktopIconDeferrerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Inject public DesktopIconDeferrerImpl(Application application) { final MessageBusConnection connection = application.getMessageBus().connect(); connection.subscribe(PsiModificationTracker.TOPIC, this::clear); connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() { @Override public void projectClosed(@Nonnull Project project, @Nonnull UIAccess uiAccess) { clear(); } }); LowMemoryWatcher.register(this::clear, this); }
Example #28
Source File: CSharpCompositeTypeDeclaration.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Nullable public static CSharpCompositeTypeDeclaration findCompositeType(@Nonnull CSharpTypeDeclaration parent) { Object cachedValue = CachedValuesManager.getCachedValue(parent, () -> CachedValueProvider.Result.create(findCompositeTypeImpl(parent), PsiModificationTracker .OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)); return cachedValue == ObjectUtil.NULL ? null : (CSharpCompositeTypeDeclaration) cachedValue; }
Example #29
Source File: CSharpGenericParameterImpl.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Nonnull @Override public DotNetTypeRef[] getExtendTypeRefs() { return CachedValuesManager.getCachedValue(this, () -> CachedValueProvider.Result.create(CSharpGenericConstraintUtil.getExtendTypes(CSharpGenericParameterImpl.this), PsiModificationTracker .OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)); }
Example #30
Source File: LightProjectBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Override public void registerServices(@Nonnull InjectingContainerBuilder builder) { builder.bind(PsiFileFactory.class).to(PsiFileFactoryImpl.class); builder.bind(PsiManager.class).to(PsiManagerImpl.class); builder.bind(FileIndexFacade.class).to(LightFileIndexFacade.class); builder.bind(PsiModificationTracker.class).to(PsiModificationTrackerImpl.class); }