Example #1
0
 @Override
 public jetbrains.mps.smodel.SModel createModel() {
   if (!myToCopy.isLoaded()) {
     // we are going to access internal/implementation model which might be in a partially-loaded
     // state (only public API guarantees proper loading). With partial model, we could face odd
     // issues (e.g. incomplete set of implicit imports as implementation node's concepts are not
     // considered)
     myToCopy.load();
   }
   Document document = ModelPersistence.saveModel(((SModelBase) myToCopy).getSModel());
   Element rootElement = document.getRootElement();
   rootElement.setAttribute(ModelPersistence.REF, getReference().toString());
   String modelContent = JDOMUtil.asString(document);
   try {
     return ModelPersistence.readModel(modelContent, false);
   } catch (ModelReadException e) {
     return new StubModel(PersistenceFacade.getInstance().createModelReference(myLongName), e);
   }
 }
Example #2
0
  private void update(boolean force) {
    final Wrappers._boolean _force = new Wrappers._boolean(force);
    myQueue.assertSoftlyIsCommandThread();
    if (!(myDifference.isEnabled())) {
      return;
    }

    IFile modelFile = myModelDescriptor.getSource().getFile();
    if (!(modelFile.exists())) {
      return;
    }
    VirtualFile modelVFile = VirtualFileUtils.getVirtualFile(modelFile);
    if (modelVFile == null
        || ProjectLevelVcsManager.getInstance(myProject).getVcsFor(modelVFile) == null) {
      return;
    }
    FileStatus status = FileStatusManager.getInstance(myProject).getStatus(modelVFile);
    if (ConflictsUtil.isModelOrModuleConflicting(myModelDescriptor, myProject)) {
      status = FileStatus.MERGED_WITH_CONFLICTS;
    }

    if (myDifference.getChangeSet() != null) {
      ModelAccess.instance()
          .runReadAction(
              new Runnable() {
                public void run() {
                  if (myDifference.getChangeSet().getNewModel() != myModelDescriptor.getSModel()) {
                    _force.value = true;
                  }
                }
              });
    }

    if (myStatusOnLastUpdate == status && !(_force.value)) {
      return;
    }
    myDifference.removeChangeSet();
    myStatusOnLastUpdate = status;
    if (FileStatus.NOT_CHANGED == status && !(_force.value)) {
      return;
    }
    final Wrappers._T<SModel> baseVersionModel = new Wrappers._T<SModel>(null);
    if (BaseVersionUtil.isAddedFileStatus(status)
        || ConflictsUtil.isModelOrModuleConflicting(myModelDescriptor, myProject)) {
      baseVersionModel.value =
          new jetbrains.mps.smodel.SModel(myModelDescriptor.getSModelReference());
    } else {
      String content = BaseVersionUtil.getBaseVersionContent(modelVFile, myProject);
      if (content == null && status != FileStatus.NOT_CHANGED) {
        LOG.error("Base version content is null while file status is " + status);
      }
      if (content == null) {
        return;
      }
      try {
        baseVersionModel.value = ModelPersistence.readModel(content, false);
      } catch (ModelReadException e) {
        LOG.warning("", e);
        return;
      }
    }
    ModelAccess.instance()
        .runReadAction(
            new Runnable() {
              public void run() {
                synchronized (ChangesTracking.this) {
                  if (!(myDisposed)) {
                    ChangeSet changeSet =
                        ChangeSetBuilder.buildChangeSet(
                            baseVersionModel.value, myModelDescriptor.getSModel(), true);
                    myDifference.setChangeSet((ChangeSetImpl) changeSet);
                    buildCaches();
                  }
                }
              }
            });
  }