@SuppressWarnings("deprecation") @Override @NotNull public PsiElement getNavigationElement() { for (ClsCustomNavigationPolicy customNavigationPolicy : Extensions.getExtensions(ClsCustomNavigationPolicy.EP_NAME)) { if (customNavigationPolicy instanceof ClsCustomNavigationPolicyEx) { PsiFile navigationElement = ((ClsCustomNavigationPolicyEx)customNavigationPolicy).getFileNavigationElement(this); if (navigationElement != null) { return navigationElement; } } } return CachedValuesManager.getCachedValue(this, new CachedValueProvider<PsiElement>() { @Nullable @Override public Result<PsiElement> compute() { PsiElement target = JavaPsiImplementationHelper.getInstance(getProject()).getClsFileNavigationElement(ClsFileImpl.this); ModificationTracker tracker = FileIndexFacade.getInstance(getProject()).getRootModificationTracker(); return Result.create(target, ClsFileImpl.this, target.getContainingFile(), tracker); } }); }
public CachedValue<MultiValuesMap<VirtualFile, Artifact>> getFileToArtifactsMap() { if (myFile2Artifacts == null) { myFile2Artifacts = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<MultiValuesMap<VirtualFile, Artifact>>() { public Result<MultiValuesMap<VirtualFile, Artifact>> compute() { MultiValuesMap<VirtualFile, Artifact> result = computeFileToArtifactsMap(); List<ModificationTracker> trackers = new ArrayList<ModificationTracker>(); trackers.add(ArtifactManager.getInstance(myProject).getModificationTracker()); for (ComplexPackagingElementType<?> type : PackagingElementFactory.getInstance().getComplexElementTypes()) { ContainerUtil.addIfNotNull(type.getAllSubstitutionsModificationTracker(myProject), trackers); } return Result.create(result, trackers.toArray(new ModificationTracker[trackers.size()])); } }, false); } return myFile2Artifacts; }
public static void cacheParticularEntity(PsiFile file, XmlEntityDecl decl) { synchronized(PsiLock.LOCK) { final Map<String, CachedValue<XmlEntityDecl>> cachingMap = getCachingMap(file); final String name = decl.getName(); if (cachingMap.containsKey(name)) return; final SmartPsiElementPointer declPointer = SmartPointerManager.getInstance(file.getProject()).createSmartPsiElementPointer(decl); cachingMap.put( name, CachedValuesManager.getManager(file.getProject()).createCachedValue(new CachedValueProvider<XmlEntityDecl>() { @Override public Result<XmlEntityDecl> compute() { PsiElement declElement = declPointer.getElement(); if (declElement instanceof XmlEntityDecl && declElement.isValid() && name.equals(((XmlEntityDecl)declElement).getName())) return new Result<XmlEntityDecl>((XmlEntityDecl)declElement, declElement); cachingMap.put(name,null); return new Result<XmlEntityDecl>(null, ModificationTracker.NEVER_CHANGED); } }, false )); } }
@Override public Result<Map<String, Set<Define>>> compute() { try { myScope.acceptChildren(this); final PsiElement psiElement = myScope.getPsiElement(); if (psiElement == null || !psiElement.isValid()) { return Result.create(null, ModificationTracker.EVER_CHANGED); } final PsiFile file = psiElement.getContainingFile(); if (myVisitedFiles.get() != null) { myVisitedFiles.get().add(file); return Result.create(myDefines.get(), myVisitedFiles.get().toArray()); } else { return Result.create(myDefines.get(), file); } } finally { myVisitedFiles.remove(); myDefines.remove(); } }
@Override public Object[] getDependences() { if (myPattern != null) { if (DumbService.isDumb(myElement.getProject())) { return new Object[] { ModificationTracker.EVER_CHANGED, ExternalResourceManager.getInstance()}; } final Object[] a = { myElement, ExternalResourceManager.getInstance() }; final PsiElementProcessor.CollectElements<XmlFile> processor = new PsiElementProcessor.CollectElements<XmlFile>(); RelaxIncludeIndex.processForwardDependencies(myFile, processor); if (processor.getCollection().size() > 0) { return ArrayUtil.mergeArrays(a, processor.toArray()); } else { return a; } } return new Object[]{ ModificationTracker.EVER_CHANGED }; }
@Nullable @Override public final Result<T> compute() { AndroidFacet[] facets = myComponent.getDataBindingEnabledFacets(); List<V> values = Lists.newArrayList(); List<ModificationTracker> newDependencies = Lists.newArrayList(); newDependencies.add(myComponent); Collections.addAll(newDependencies, myAdditionalTrackers); for (AndroidFacet facet : facets) { CachedValue<V> cachedValue = getCachedValue(facet); // we know this for sure since it is created from createCacheProvider if (cachedValue.getValueProvider() instanceof ModificationTracker) { newDependencies.add((ModificationTracker)cachedValue.getValueProvider()); } V result = cachedValue.getValue(); if (result != null) { values.add(result); } } myDependencyModificationCountOnCompute = calculateModificationCountFrom(newDependencies); myDependencies = newDependencies; return Result.create(merge(values), this); }
@Nullable public static MvcFramework getInstance(@Nullable final Module module) { if (module == null) { return null; } final Project project = module.getProject(); return CachedValuesManager.getManager(project).getCachedValue(module, new CachedValueProvider<MvcFramework>() { @Override public Result<MvcFramework> compute() { final ModificationTracker tracker = MvcModuleStructureSynchronizer.getInstance(project).getFileAndRootsModificationTracker(); for (final MvcFramework framework : EP_NAME.getExtensions()) { if (framework.hasSupport(module)) { return Result.create(framework, tracker); } } return Result.create(null, tracker); } }); }
public Result<Map<String, Set<Define>>> compute() { try { myScope.acceptChildren(this); final PsiElement psiElement = myScope.getPsiElement(); if (psiElement == null || !psiElement.isValid()) { return Result.create(null, ModificationTracker.EVER_CHANGED); } final PsiFile file = psiElement.getContainingFile(); if (myVisitedFiles.get() != null) { myVisitedFiles.get().add(file); return Result.create(myDefines.get(), myVisitedFiles.get().toArray()); } else { return Result.create(myDefines.get(), file); } } finally { myVisitedFiles.remove(); myDefines.remove(); } }
public Object[] getDependences() { if (myPattern != null) { if (DumbService.isDumb(myElement.getProject())) { return new Object[] { ModificationTracker.EVER_CHANGED, ExternalResourceManager.getInstance()}; } final Object[] a = { myElement, ExternalResourceManager.getInstance() }; final PsiElementProcessor.CollectElements<XmlFile> processor = new PsiElementProcessor.CollectElements<XmlFile>(); RelaxIncludeIndex.processForwardDependencies(myFile, processor); if (processor.getCollection().size() > 0) { return ArrayUtil.mergeArrays(a, processor.toArray()); } else { return a; } } return new Object[]{ ModificationTracker.EVER_CHANGED }; }
public static void cacheParticularEntity(PsiFile file, XmlEntityDecl decl) { synchronized(LOCK) { final Map<String, CachedValue<XmlEntityDecl>> cachingMap = getCachingMap(file); final String name = decl.getName(); if(cachingMap.containsKey(name)) { return; } final SmartPsiElementPointer declPointer = SmartPointerManager.getInstance(file.getProject()).createSmartPsiElementPointer(decl); cachingMap.put(name, CachedValuesManager.getManager(file.getProject()).createCachedValue(() -> { PsiElement declElement = declPointer.getElement(); if(declElement instanceof XmlEntityDecl && declElement.isValid() && name.equals(((XmlEntityDecl) declElement).getName())) { return new CachedValueProvider.Result<>((XmlEntityDecl) declElement, declElement); } cachingMap.put(name, null); return new CachedValueProvider.Result<>(null, ModificationTracker.NEVER_CHANGED); }, false)); } }
@Override public Object[] getDependences() { if (myPattern != null) { if (DumbService.isDumb(myElement.getProject())) { return new Object[] { ModificationTracker.EVER_CHANGED, ExternalResourceManager.getInstance()}; } final Object[] a = { myElement, ExternalResourceManager.getInstance() }; final PsiElementProcessor.CollectElements<XmlFile> processor = new PsiElementProcessor.CollectElements<>(); RelaxIncludeIndex.processForwardDependencies(myFile, processor); if (processor.getCollection().size() > 0) { return ArrayUtil.mergeArrays(a, processor.toArray()); } else { return a; } } return new Object[]{ ModificationTracker.EVER_CHANGED }; }
public PsiAnnotation createContractAnnotation(String contractValue) { Map<String, PsiAnnotation> cache = CachedValuesManager.getManager(myProject).getCachedValue(myProject, new CachedValueProvider<Map<String, PsiAnnotation>>() { @Nullable @Override public Result<Map<String, PsiAnnotation>> compute() { Map<String, PsiAnnotation> map = new ConcurrentFactoryMap<String, PsiAnnotation>() { @Nullable @Override protected PsiAnnotation create(String attrs) { return createAnnotationFromText("@org.jetbrains.annotations.Contract(" + attrs + ")"); } }; return CachedValueProvider.Result.create(map, ModificationTracker.NEVER_CHANGED); } }); return cache.get(contractValue); }
public TemplateEngineProvider(Project project, NotNullLazyValue<ModificationTracker> tracker) { super(project); this.tracker = tracker; for (TemplateEngine engine : TemplateEngine.values()) { engines.put("catberry-" + engine, engine); } }
public PsiAnnotation getNotNullAnnotation() { return CachedValuesManager.getManager(myProject).getCachedValue(myProject, new CachedValueProvider<PsiAnnotation>() { @Nullable @Override public Result<PsiAnnotation> compute() { return Result.create(createAnnotationFromText("@" + AnnotationUtil.NOT_NULL), ModificationTracker.NEVER_CHANGED); } }); }
public PsiAnnotation getNullableAnnotation() { return CachedValuesManager.getManager(myProject).getCachedValue(myProject, new CachedValueProvider<PsiAnnotation>() { @Nullable @Override public Result<PsiAnnotation> compute() { return Result.create(createAnnotationFromText("@" + AnnotationUtil.NULLABLE), ModificationTracker.NEVER_CHANGED); } }); }
@NotNull @Override protected final CachedValueProvider<AnAction[]> createChildrenProvider(@NotNull final ActionManager actionManager) { return new CachedValueProvider<AnAction[]>() { @Nullable @Override public Result<AnAction[]> compute() { return Result.create(computeChildren(actionManager), ModificationTracker.NEVER_CHANGED); } }; }
@Override public <F extends Facet> ModificationTracker getAllFacetsOfTypeModificationTracker(FacetTypeId<F> type) { AllFacetsOfTypeModificationTracker tracker = myAllFacetTrackers.get(type); if (tracker == null) { tracker = new AllFacetsOfTypeModificationTracker<F>(myProject, type); Disposer.register(myProject, tracker); myAllFacetTrackers.put(type, tracker); } return tracker; }
private static long calculateModificationCountFrom(List<ModificationTracker> dependencies) { long total = 0; for (ModificationTracker tracker : dependencies) { total += tracker.getModificationCount(); } return total; }
@Nullable @Override public Result<String> compute() { return Result.create(StringUtil.join(myRegisteredRepositoryIds, ","), new ModificationTracker() { @Override public long getModificationCount() { return myRegisteredRepositoryIds.hashCode(); } }); }
@Nonnull @Override protected final CachedValueProvider<AnAction[]> createChildrenProvider(@Nonnull final ActionManager actionManager) { return new CachedValueProvider<AnAction[]>() { @Nullable @Override public Result<AnAction[]> compute() { return Result.create(computeChildren(actionManager), ModificationTracker.NEVER_CHANGED); } }; }
@Nonnull public ModificationTracker forLanguages(@Nonnull Condition<Language> condition) { if (!ourEnableLanguageTracker.asBoolean()) return this; return () -> { long result = 0; for (Language l : myLanguageTrackers.keySet()) { if (condition.value(l)) continue; result += myLanguageTrackers.get(l).getModificationCount(); } return result; }; }
@Override @NotNull @SuppressWarnings("deprecation") public PsiElement getNavigationElement() { for(ClsCustomNavigationPolicy customNavigationPolicy : Extensions.getExtensions(ClsCustomNavigationPolicy.EP_NAME)) { if(customNavigationPolicy instanceof ClsCustomNavigationPolicyEx) { try { PsiFile navigationElement = ((ClsCustomNavigationPolicyEx) customNavigationPolicy).getFileNavigationElement(this); if(navigationElement != null) { return navigationElement; } } catch(IndexNotReadyException ignore) { } } } return CachedValuesManager.getCachedValue(this, () -> { PsiElement target = JavaPsiImplementationHelper.getInstance(getProject()).getClsFileNavigationElement(this); ModificationTracker tracker = FileIndexFacade.getInstance(getProject()).getRootModificationTracker(); return CachedValueProvider.Result.create(target, this, target.getContainingFile(), tracker); }); }
public PsiAnnotation getNotNullAnnotation() { return CachedValuesManager.getManager(myProject).getCachedValue(myProject, new CachedValueProvider<PsiAnnotation>() { @Nullable @Override public Result<PsiAnnotation> compute() { return CachedValueProvider.Result.create(ProjectBytecodeAnalysis.this.createAnnotationFromText("@" + AnnotationUtil.NOT_NULL), ModificationTracker.NEVER_CHANGED); } }); }
public PsiAnnotation getNullableAnnotation() { return CachedValuesManager.getManager(myProject).getCachedValue(myProject, new CachedValueProvider<PsiAnnotation>() { @Nullable @Override public Result<PsiAnnotation> compute() { return CachedValueProvider.Result.create(ProjectBytecodeAnalysis.this.createAnnotationFromText("@" + AnnotationUtil.NULLABLE), ModificationTracker.NEVER_CHANGED); } }); }
@NotNull @Override public Result<Map<String, TaskPsiElement>> compute() { return Result.<Map<String, TaskPsiElement>>create(new SoftHashMap<String, TaskPsiElement>(), new ModificationTracker() { @Override public long getModificationCount() { return 0; } }); }
@NotNull @Override public ModificationTracker getModificationTracker() { //noinspection ReturnOfThis return this; }
@Contract(pure = true) @NotNull @Override public ModificationTracker getModificationTracker() { return this; }
public ComponentsDirectoriesProvider(Project project, NotNullLazyValue<ModificationTracker> tracker) { super(project); this.tracker = tracker; }
public StoresDirectoryProvider(Project project, NotNullLazyValue<ModificationTracker> tracker) { super(project); this.tracker = tracker; }
@Nullable public ModificationTracker getAllSubstitutionsModificationTracker(@NotNull Project project) { return null; }
@Override public ModificationTracker getModificationTracker() { return myModificationTracker; }
@NotNull @Override public ModificationTracker getRootModificationTracker() { return ProjectRootManager.getInstance(myProject); }
@NotNull public ModificationTracker getModificationTracker() { return myModificationTracker; }
@NotNull public abstract ModificationTracker getFacetModificationTracker(@NotNull Facet facet);
@Override public ModificationTracker getModificationTracker() { return new SimpleModificationTracker(); }