public void rebuild(T t, Runnable r) { MyNodeReadListener listener = new MyNodeReadListener(); NodeReadEventsCaster.setNodesReadListener(listener); try { r.run(); } finally { NodeReadEventsCaster.removeNodesReadListener(); } myObjectsToNodes.clearFirst(t); for (SNode n : listener.getDependencies()) { myObjectsToNodes.addLink(t, n); } }
private <T> MultiMap<SModel, T> findCandidates( Collection<SModel> models, Set<T> elems, Consumer<SModel> processedModels, Function<T, UsageEntry> id) { // get all files in scope final ManyToManyMap<SModel, VirtualFile> scopeFiles = new ManyToManyMap<SModel, VirtualFile>(); for (final SModel sm : models) { if (sm instanceof EditableSModel && ((EditableSModel) sm).isChanged()) { continue; } DataSource source = sm.getSource(); // these are data sources this participant knows about if (!(source instanceof FileDataSource || source instanceof FilePerRootDataSource)) { continue; } /* This is a tmp fix for MPS-24151. See the issue to learn about the correct fix */ if (!(sm instanceof DefaultSModelDescriptor)) { continue; } Collection<IFile> modelFiles = getDataSourceFiles(source); for (IFile modelFile : modelFiles) { String ext = FileUtil.getExtension(modelFile.getName()); if (ext == null || modelFile.isDirectory()) { continue; } VirtualFile vf = VirtualFileUtils.getOrCreateVirtualFile(modelFile); if (vf == null) { LogManager.getLogger(MPSModelsFastFindSupport.class) .warn( String.format( "Model %s: virtual file not found for model file. Model file: %s", sm.getName(), modelFile.getPath())); continue; } processedModels.consume(sm); scopeFiles.addLink(sm, vf); } } // filter files with usages ConcreteFilesGlobalSearchScope allFiles = new ConcreteFilesGlobalSearchScope(scopeFiles.getSecond()); // process indexes MultiMap<SModel, T> result = new SetBasedMultiMap<SModel, T>(); for (T elem : elems) { UsageEntry entry = id.apply(elem); Collection<VirtualFile> matchingFiles; try { matchingFiles = MPSModelsIndexer.getContainingFiles(entry, allFiles); } catch (ProcessCanceledException ce) { matchingFiles = Collections.emptyList(); } // back-transform for (VirtualFile file : matchingFiles) { for (SModel m : scopeFiles.getBySecond(file)) { result.putValue(m, elem); } } } return result; }
public Set<T> getDependOn(SNode n) { return myObjectsToNodes.getBySecond(n); }
public Set<SNode> getDependencies(T t) { return myObjectsToNodes.getByFirst(t); }
public void remove(T t) { myObjectsToNodes.clearFirst(t); }