Exemplo n.º 1
0
  public String toString() {
    StringBuilder sb = new StringBuilder();

    if (getModuleReference() != null && getModuleReference().getModuleId() != null) {
      sb.append(StringUtil.escapeRefChars(getModuleReference().getModuleId().toString()));
      sb.append("/");
    }

    String modelId =
        myModelId instanceof ModelNameSModelId ? myModelId.getModelName() : myModelId.toString();
    sb.append(StringUtil.escapeRefChars(modelId));

    if (getModuleReference() == null && myModelName.equals(myModelId.getModelName())) {
      return sb.toString();
    }

    sb.append("(");
    if (getModuleReference() != null && getModuleReference().getModuleName() != null) {
      sb.append(StringUtil.escapeRefChars(getModuleReference().getModuleName()));
      sb.append("/");
    }
    if (!myModelName.equals(myModelId.getModelName())) {
      // no reason to write down model name if it's part of module id
      sb.append(StringUtil.escapeRefChars(myModelName));
    }
    sb.append(")");
    return sb.toString();
  }
Exemplo n.º 2
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();
    }
  }
Exemplo n.º 3
0
 private static String getConceptAlias(SNode concept) {
   String alias = SNodeUtil.getConceptAlias(concept);
   if (StringUtil.isEmpty(alias)) {
     return concept.getName();
   } else {
     return alias;
   }
 }
Exemplo n.º 4
0
  /**
   * @deprecated This code shall move to private method of PersistenceRegistry, which would dispatch
   *     to proper registered factories. Use {@link PersistenceFacade#createModelReference(String)}
   *     instead. Format: <code>[ moduleID / ] modelID [ ([moduleName /] modelName ) ]</code>
   */
  @Deprecated
  @ToRemove(version = 3.3)
  public static SModelReference parseReference(String s) {
    if (s == null) return null;
    s = s.trim();
    int lParen = s.indexOf('(');
    int rParen = s.lastIndexOf(')');
    String presentationPart = null;
    if (lParen > 0 && rParen == s.length() - 1) {
      presentationPart = s.substring(lParen + 1, rParen);
      s = s.substring(0, lParen);
      lParen = s.indexOf('(');
      rParen = s.lastIndexOf(')');
    }
    if (lParen != -1 || rParen != -1) {
      throw new IllegalArgumentException("parentheses do not match in: `" + s + "'");
    }

    SModuleId moduleId = null;
    int slash = s.indexOf('/');
    if (slash >= 0) {
      // FIXME I wonder why there's no SModuleIdFactory and corresponding methods in
      // PersistenceFacade
      moduleId = ModuleId.fromString(StringUtil.unescapeRefChars(s.substring(0, slash)));
      s = s.substring(slash + 1);
    }

    String modelIDString = StringUtil.unescapeRefChars(s);
    SModelId modelId;
    if (modelIDString.indexOf(':') >= 0) {
      PersistenceFacade facade = PersistenceFacade.getInstance();
      // temporary: SModelReference can be created without active PersistenceFacade
      if (facade == null) {
        // FIXME get rid of facade == null case, if any
        // Besides, shall move the code to PersistenceRegistry, as it's responsible for prefixes and
        // factory pick
        LOG.warn(
            "Please report stacktrace, which would help us to find out improper MPS initialization sequence",
            new Throwable());
      }
      modelId =
          facade != null
              ? facade.createModelId(modelIDString)
              : jetbrains.mps.smodel.SModelId.fromString(modelIDString);
    } else {
      // dead code? I suspect ModelNameSModelId, if any, would start with "m:" prefix and we'd never
      // get into else clause
      // OTOH, there seems to be a special hack in toString(), that persists ModelNameSModelId
      // without the prefix
      modelId = new ModelNameSModelId(modelIDString);
    }

    String moduleName = null;
    String modelName = null;
    if (presentationPart != null) {
      slash = presentationPart.indexOf('/');
      if (slash >= 0) {
        moduleName = StringUtil.unescapeRefChars(presentationPart.substring(0, slash));
        modelName = StringUtil.unescapeRefChars(presentationPart.substring(slash + 1));
      } else {
        modelName = StringUtil.unescapeRefChars(presentationPart);
      }
    }

    if (modelName == null || modelName.isEmpty()) {
      modelName = modelId.getModelName();
      if (modelName == null) {
        throw new IllegalArgumentException(
            "incomplete model reference, presentation part is absent");
      }
    }

    if (moduleId == null) {
      moduleId = extractModuleIdFromModelIdIfJavaStub(modelId);
    }

    if (SModelRepository.isLegacyJavaStubModelId(modelId)) {
      modelId = SModelRepository.newJavaPackageStubFromLegacy(modelId);
    }

    SModuleReference moduleRef =
        moduleId != null || moduleName != null
            ? new jetbrains.mps.project.structure.modules.ModuleReference(moduleName, moduleId)
            : null;
    return new SModelReference(moduleRef, modelId, modelName);
  }