Example #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();
  }
Example #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());
 }
Example #3
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    SModelReference that = (SModelReference) o;

    if (!myModelId.equals(that.myModelId)) return false;
    if (myModelId.isGloballyUnique() && that.myModelId.isGloballyUnique()) return true;
    return getModuleReference().equals(that.getModuleReference());
  }
Example #4
0
 public SModelReference(
     @Nullable SModuleReference module, @NotNull SModelId modelId, @NotNull String modelName) {
   myModelId = modelId;
   myModelName = modelName;
   if (module == null) {
     if (!modelId.isGloballyUnique()) {
       throw new IllegalArgumentException(
           String.format(
               "Only globally unique model id could be used without module specification: %s",
               modelId));
     }
   }
   myModuleReference = module;
 }
Example #5
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);
  }
Example #6
0
 @Override
 public int hashCode() {
   int result = myModelId.hashCode();
   result = 31 * result + (myModelId.isGloballyUnique() ? 0 : getModuleReference().hashCode());
   return result;
 }