Example #1
0
 @Override
 protected boolean saveModel() throws IOException {
   SModel smodel = getSModel();
   if (smodel instanceof InvalidSModel) {
     // we do not save stub model to not overwrite the real model
     return false;
   }
   boolean upgraded = myPersistence.doesSaveUpgradePersistence(myHeader);
   myPersistence.saveModel(myHeader, smodel);
   return upgraded;
 }
Example #2
0
  @Override
  protected void reloadContents() {
    try {
      myHeader = myPersistence.readHeader();
    } catch (ModelReadException e) {
      myTimestampTracker.updateTimestamp(getSource());
      SuspiciousModelHandler.getHandler().handleSuspiciousModel(this, false);
      return;
    }

    super.reloadContents();
  }
Example #3
0
  @Override
  protected ModelLoadResult loadSModel(ModelLoadingState state) {
    DataSource source = getSource();
    if (!source.isReadOnly() && source.getTimestamp() == -1) {
      // no file on disk
      DefaultSModel model = new DefaultSModel(getReference(), myHeader);
      return new ModelLoadResult((SModel) model, ModelLoadingState.FULLY_LOADED);
    }

    ModelLoadResult result;
    try {
      result = myPersistence.readModel(myHeader, state);
    } catch (ModelReadException e) {
      LOG.warning(
          String.format("Failed to load model %s: %s", getSource().getLocation(), e.toString()));
      SuspiciousModelHandler.getHandler().handleSuspiciousModel(this, false);
      InvalidDefaultSModel newModel = new InvalidDefaultSModel(getReference(), e);
      return new ModelLoadResult((SModel) newModel, ModelLoadingState.NOT_LOADED);
    }

    jetbrains.mps.smodel.SModel model = result.getModel();
    if (result.getState() == ModelLoadingState.FULLY_LOADED) {
      boolean needToSave = model.updateSModelReferences() || model.updateModuleReferences();

      if (needToSave && !source.isReadOnly()) {
        setChanged(true);
      }
    }

    LOG.assertLog(
        model.getReference().equals(getReference()),
        "\nError loading model from: \""
            + source.getLocation()
            + "\"\n"
            + "expected model UID     : \""
            + getReference()
            + "\"\n"
            + "but was UID            : \""
            + model.getReference()
            + "\"\n"
            + "the model will not be available.\n"
            + "Make sure that all project's roots and/or the model namespace is correct");
    return result;
  }
Example #4
0
 public DefaultSModelDescriptor(
     @NotNull LazyLoadFacility persistence, @NotNull SModelHeader header) {
   super(header.getModelReference(), persistence.getSource());
   myPersistence = persistence;
   myHeader = header;
 }
Example #5
0
 @Override
 public Map<String, String> getGenerationHashes() {
   return myPersistence.getGenerationHashes();
 }
Example #6
0
 @Override
 public String getModelHash() {
   return myPersistence.getModelHash();
 }
Example #7
0
 @Nullable
 @Override
 public ModelFactory getModelFactory() {
   return myPersistence.getModelFactory();
 }