@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; }
@Override protected void reloadContents() { try { myHeader = myPersistence.readHeader(); } catch (ModelReadException e) { myTimestampTracker.updateTimestamp(getSource()); SuspiciousModelHandler.getHandler().handleSuspiciousModel(this, false); return; } super.reloadContents(); }
@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; }
public DefaultSModelDescriptor( @NotNull LazyLoadFacility persistence, @NotNull SModelHeader header) { super(header.getModelReference(), persistence.getSource()); myPersistence = persistence; myHeader = header; }
@Override public Map<String, String> getGenerationHashes() { return myPersistence.getGenerationHashes(); }
@Override public String getModelHash() { return myPersistence.getModelHash(); }
@Nullable @Override public ModelFactory getModelFactory() { return myPersistence.getModelFactory(); }