@Override public Set<SReference> search( Set<SNode> nodes, @NotNull SearchScope scope, @NotNull ProgressMonitor monitor) { final HashSet<SReference> rv = new HashSet<SReference>(); CollectConsumer<SReference> consumer = new CollectConsumer<SReference>(rv); Collection<FindUsagesParticipant> participants = PersistenceRegistry.getInstance().getFindUsagesParticipants(); monitor.start("Finding usages...", participants.size() + 4); try { Collection<SModel> current = new LinkedHashSet<SModel>(); Collection<SModel> simpleSearch = new LinkedHashSet<SModel>(); for (SModel m : IterableUtil.asCollection(scope.getModels())) { if (m instanceof EditableSModel && ((EditableSModel) m).isChanged()) { simpleSearch.add(m); } else { current.add(m); } } for (FindUsagesParticipant participant : participants) { final Set<SModel> next = new HashSet<SModel>(current); participant.findUsages( current, nodes, consumer, new Consumer<SModel>() { @Override public void consume(SModel sModel) { assert !(sModel instanceof EditableSModel && ((EditableSModel) sModel).isChanged()); next.remove(sModel); } }); current = next; monitor.advance(1); } ProgressMonitor subMonitor = monitor.subTask(4, SubProgressKind.DEFAULT); subMonitor.start("", current.size() + simpleSearch.size()); NodeUsageFinder nf = new NodeUsageFinder(nodes, consumer); showNoFastFindTipIfNeeded(current); current.addAll(simpleSearch); for (SModel m : current) { subMonitor.step(m.getModelName()); nf.collectUsages(m); if (monitor.isCanceled()) { break; } subMonitor.advance(1); } subMonitor.done(); } finally { monitor.done(); } return rv; }
public static boolean findInModule(SModule module, String modelName, String rootName) { for (SModel d : module.getModels()) { if (d.getModelName().equals(modelName)) { for (SNode _n : d.getRootNodes()) { SNode n = (SNode) _n; if (SNodeOperations.isInstanceOf(n, "jetbrains.mps.baseLanguage.structure.Classifier") && SPropertyOperations.getString( SNodeOperations.cast(n, "jetbrains.mps.baseLanguage.structure.Classifier"), "name") .equals(rootName)) { return true; } } } } return false; }
@Override public Set<SReference> search( Set<SNode> nodes, SearchScope scope, @NotNull ProgressMonitor monitor) { CollectConsumer<SReference> consumer = new CollectConsumer(new HashSet<SReference>()); Collection<FindUsagesParticipant> participants = FastFindUsagesRegistry.getInstance().getParticipants(); monitor.start("Finding usages...", participants.size() + 4); try { Collection<SModel> current = IterableUtil.asCollection(scope.getModels()); for (FindUsagesParticipant participant : participants) { final Set<SModel> next = new HashSet<SModel>(current); participant.findUsages( current, nodes, consumer, new Consumer<SModel>() { @Override public void consume(SModel sModel) { next.remove(sModel); } }); current = next; monitor.advance(1); } ProgressMonitor subMonitor = monitor.subTask(4, SubProgressKind.DEFAULT); subMonitor.start("", current.size()); for (SModel m : current) { subMonitor.step(m.getModelName()); FindUsagesManager.collectUsages(m, nodes, consumer); if (monitor.isCanceled()) break; subMonitor.advance(1); } subMonitor.done(); } finally { monitor.done(); } return (Set<SReference>) consumer.getResult(); }
public int getModelKind(SModel model, @Nullable SReference reference) { DataSource source = (model != null ? model.getSource() : null); IFile modelFile = (source instanceof FileDataSource ? ((FileDataSource) source).getFile() : null); if (modelFile != null) { String filePath = modelFile.getAbsolutePath().replace('\\', '/'); if (filePath.startsWith(languagesUtilPath)) { return OTHER; } } SModule module = model.getModule(); if (module instanceof Language) { LanguageAspect aspect = Language.getModelAspect(model); if (aspect != null) { switch (aspect) { case ACTIONS: return EDITOR; case BEHAVIOR: return CORE; case CONSTRAINTS: return CORE; case DATA_FLOW: return CORE; case EDITOR: return EDITOR; case FIND_USAGES: return CORE; case INTENTIONS: return EDITOR; case PLUGIN: return WORKBENCH; case REFACTORINGS: return CORE; case SCRIPTS: return CORE; case STRUCTURE: return CORE; case STUBS: return CORE; case TEST: return EDITOR; case TEXT_GEN: return CORE; case TYPESYSTEM: return CORE; default: } } return CORE; } else if (module instanceof Solution) { String moduleFqName = module.getModuleName(); if (moduleFqName.equals("JDK")) { return CORE; } if (moduleFqName.equals("MPS.Core")) { return CORE; } if (moduleFqName.equals("MPS.Editor")) { return EDITOR; } if (moduleFqName.equals("MPS.Workbench")) { return WORKBENCH; } if (moduleFqName.equals("MPS.Classpath")) { SNode refTargetRoot = reference.getTargetNode().getContainingRoot(); if (SNodeOperations.isInstanceOf( refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier")) { String cName = SPropertyOperations.getString( SNodeOperations.cast( refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier"), "name"); String modelName = model.getModelName(); if (findInModule(coreModule, modelName, cName)) { return CORE; } if (findInModule(editorModule, modelName, cName)) { return EDITOR; } return WORKBENCH; } return OTHER; } Solution sol = (Solution) module; switch (sol.getKind()) { case NONE: return OTHER; case PLUGIN_CORE: return CORE; case PLUGIN_EDITOR: return EDITOR; case PLUGIN_OTHER: return WORKBENCH; default: } } return OTHER; }