Example #1
0
  @Override
  public SearchResults find(SearchQuery query, ProgressMonitor monitor) {
    myResults = new SearchResults<SNode>();
    SearchScope queryScope = query.getScope();

    monitor.start("Searching applicable nodes", myScripts.size());
    try {
      for (RefactoringScript scriptInstance : myScripts) {
        if (monitor.isCanceled()) {
          break;
        }
        Collection<AbstractMigrationRefactoring> refactorings = scriptInstance.getRefactorings();
        for (AbstractMigrationRefactoring ref : refactorings) {
          if (monitor.isCanceled()) {
            break;
          }
          monitor.step(scriptInstance.getName() + " [" + ref.getAdditionalInfo() + "]");
          Set<SNode> instances =
              FindUsagesFacade.getInstance()
                  .findInstances(
                      queryScope,
                      Collections.singleton(ref.getApplicableConcept()),
                      false,
                      new EmptyProgressMonitor());
          for (SNode instance : instances) {
            try {
              if (ref.isApplicableInstanceNode(instance)) {
                String category =
                    StringUtil.escapeXml(scriptInstance.getName())
                        + " </b>["
                        + StringUtil.escapeXml(ref.getAdditionalInfo())
                        + "]<b>";
                SearchResult<SNode> result = new SearchResult<SNode>(instance, category);
                myMigrationBySearchResult.put(result, ref);
                myResults.getSearchResults().add(result);
              }
            } catch (Throwable th) {
              if (LOG.isEnabledFor(Level.ERROR)) {
                LOG.error("Failed to evaluate script applicability", th);
              }
            }
          }
        }
        monitor.advance(1);
      }
      fireResultsChanged();
      return myResults;
    } finally {
      monitor.done();
    }
  }
Example #2
0
 public Set<SReference> findUsages(MPSProject project, Iterable<SNode> nodes) {
   return FindUsagesFacade.getInstance()
       .findUsages(
           project.getScope(),
           SetSequence.fromSetWithValues(
               new HashSet<SNode>(),
               Sequence.fromIterable(nodes)
                   .translate(
                       new ITranslator2<SNode, SNode>() {
                         public Iterable<SNode> translate(SNode it) {
                           return SNodeOperations.getNodeDescendants(
                               it, null, true, new SAbstractConcept[] {});
                         }
                       })),
           new EmptyProgressMonitor());
 }