Ejemplo 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();
  }
Ejemplo n.º 2
0
 @Override
 public SModel resolveInDependencies(SModelId reference) {
   boolean own =
       reference.getModelName() != null
           && myModels
               .keySet()
               .contains(SModelStereotype.withoutStereotype(reference.getModelName()));
   if (!own) return super.resolveInDependencies(reference);
   return myModels.get(reference.getModelName());
 }
Ejemplo n.º 3
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);
  }