public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
   try {
     for (SModel model :
         Sequence.fromIterable(
             ((MPSProject) MapSequence.fromMap(_params).get("mpsProject")).getProjectModels())) {
       if (!(model instanceof RefactorableSModelDescriptor)) {
         continue;
       }
       if (SModelStereotype.isStubModelStereotype(SModelStereotype.getStereotype(model))) {
         continue;
       }
       UpdateRefactoringVersions_Action.this.updateModelVersion(
           (RefactorableSModelDescriptor) model, _params);
     }
     for (SModel model :
         Sequence.fromIterable(
             ((MPSProject) MapSequence.fromMap(_params).get("mpsProject")).getProjectModels())) {
       if (!(model instanceof EditableSModelDescriptor)) {
         continue;
       }
       if (SModelStereotype.isStubModelStereotype(SModelStereotype.getStereotype(model))) {
         continue;
       }
       UpdateRefactoringVersions_Action.this.updateImportVersions(
           (EditableSModelDescriptor) model, _params);
     }
     SModelRepository.getInstance().saveAll();
   } catch (Throwable t) {
     LOG.error("User's action execute method failed. Action:" + "UpdateRefactoringVersions", t);
   }
 }
Beispiel #2
0
  private void rehighlightNode(@NotNull MPSTreeNode node, @NotNull Feature feature) {
    unhighlightNode(node);

    SModel model = SModelRepository.getInstance().getModelDescriptor(feature.getModelReference());
    if (model instanceof EditableSModel && !(model.isReadOnly())) {
      if (feature instanceof ModelFeature) {
        // do not try to compute changes in case we need only model status
        TreeMessage message = getMessage((ModelFeature) feature);
        if (message != null) {
          node.addTreeMessage(message);
        }
        return;
      }

      EditableSModel emd = (EditableSModel) model;
      myRegistry.getCurrentDifference(emd).setEnabled(true);

      ModelChange change = myMap.get(feature);
      if (change == null) {
        change = myMap.getAddedAncestorValue(feature);
      }
      if (change != null) {
        node.addTreeMessage(getMessage(change, emd));
      } else if (myMap.isAncestorOfAddedFeature(feature)) {
        node.addTreeMessage(getMessage(FileStatus.MODIFIED));
      }
    }
  }
  private void openRule(String ruleModel, final String ruleID) {
    if (ruleModel == null || ruleID == null) return;
    final SModelReference modelUID =
        PersistenceFacade.getInstance().createModelReference(ruleModel);
    final SModel modelDescriptor =
        SModelRepository.getInstance()
            .getModelDescriptor(SModelStereotype.withoutStereotype(modelUID.getModelName()));
    if (modelDescriptor == null) {
      LOG.error("can't find rule's model " + ruleModel);
      return;
    }

    ModelAccess.instance()
        .runWriteInEDT(
            new Runnable() {
              @Override
              public void run() {
                jetbrains.mps.smodel.SNodeId nodeId =
                    jetbrains.mps.smodel.SNodeId.fromString(ruleID);
                assert nodeId != null : "wrong node id string";
                SNode rule = modelDescriptor.getNode(nodeId);
                if (rule == null) {
                  LOG.error(
                      "can't find rule with id " + ruleID + " in the model " + modelDescriptor);
                  return;
                }
                NavigationSupport.getInstance()
                    .openNode(
                        myOperationContext,
                        rule,
                        true,
                        !(rule.getModel() != null && rule.getParent() == null));
              }
            });
  }
Beispiel #4
0
  public LanguageEditorChecker() {
    SetSequence.fromSet(myRules).addElement(new ConstraintsChecker());
    SetSequence.fromSet(myRules).addElement(new RefScopeChecker());
    SetSequence.fromSet(myRules).addElement(new CardinalitiesChecker());
    SetSequence.fromSet(myRules).addElement(new TargetConceptChecker());

    SModelRepository.getInstance().addModelRepositoryListener(this.myRepositoryListener);
  }
  private static String asString(MappingConfig_AbstractRef mappingRef, boolean moreDetails) {
    if (mappingRef instanceof MappingConfig_RefAllLocal) {
      return "*";
    }
    if (mappingRef instanceof MappingConfig_RefAllGlobal) {
      return "[*:*]";
    }

    if (mappingRef instanceof MappingConfig_RefSet) {
      String s = "{";
      int count = ((MappingConfig_RefSet) mappingRef).getMappingConfigs().size();
      for (MappingConfig_AbstractRef mappingSimpleRef :
          ((MappingConfig_RefSet) mappingRef).getMappingConfigs()) {
        count--;
        s = s + asString(mappingSimpleRef, moreDetails);
        if (count > 0) s += ", ";
      }
      return s + "}";
    }

    if (mappingRef instanceof MappingConfig_SimpleRef) {
      final String modelUID = ((MappingConfig_SimpleRef) mappingRef).getModelUID();
      final String nodeID = ((MappingConfig_SimpleRef) mappingRef).getNodeID();
      final SModelReference modelReference =
          PersistenceFacade.getInstance().createModelReference(modelUID);
      String modelName =
          moreDetails
              ? SModelStereotype.withoutStereotype(modelReference.getModelName())
              : NameUtil.shortNameFromLongName(
                  SModelStereotype.withoutStereotype(modelReference.getModelName()));
      StringBuilder sb = new StringBuilder();
      sb.append(modelName);
      sb.append('.');
      if (nodeID.equals("*")) {
        return sb.append('*').toString();
      } else {
        SModel refModel = SModelRepository.getInstance().getModelDescriptor(modelReference);
        if (refModel != null) {
          SNodeId nodeId = PersistenceFacade.getInstance().createNodeId(nodeID);
          assert nodeId != null : "wrong node id string";
          SNode mappingConfig = refModel.getNode(nodeId);
          if (mappingConfig != null) {
            return sb.append(mappingConfig.getName()).toString();
          }
        }
      }
      return sb.append(nodeID).append("!unresolved!").toString();
    }

    if (mappingRef instanceof MappingConfig_ExternalRef) {
      SModuleReference generatorRef = ((MappingConfig_ExternalRef) mappingRef).getGenerator();
      MappingConfig_AbstractRef extMappingRef =
          ((MappingConfig_ExternalRef) mappingRef).getMappingConfig();
      return "[" + asString(generatorRef) + ":" + asString(extMappingRef, moreDetails) + "]";
    }

    return "???";
  }
Beispiel #6
0
 public static SNode getBinaryOperationType(SNode leftType, SNode rightType, boolean mayBeString) {
   List<SNode> leastCommonSupertypes =
       SubtypingUtil.leastCommonSuperTypes(Arrays.asList(leftType, rightType), null);
   if (mayBeString) {
     SModel javaLangJavaStubModelDescriptor =
         SModelRepository.getInstance()
             .getModelDescriptor(SModelReference.fromString("java.lang@java_stub"));
     assert javaLangJavaStubModelDescriptor != null;
     SModel javaLang = javaLangJavaStubModelDescriptor.getSModel();
     SNode stringClass = SModelOperations.getRootByName(javaLang, "String");
     if (SNodeOperations.isInstanceOf(
                 leftType, "jetbrains.mps.baseLanguage.structure.ClassifierType")
             && SLinkOperations.getTarget(
                     (SNodeOperations.cast(
                         leftType, "jetbrains.mps.baseLanguage.structure.ClassifierType")),
                     "classifier",
                     false)
                 == stringClass
         || SNodeOperations.isInstanceOf(
                 rightType, "jetbrains.mps.baseLanguage.structure.ClassifierType")
             && SLinkOperations.getTarget(
                     (SNodeOperations.cast(
                         rightType, "jetbrains.mps.baseLanguage.structure.ClassifierType")),
                     "classifier",
                     false)
                 == stringClass) {
       SNode classifierType =
           SConceptOperations.createNewNode(
               "jetbrains.mps.baseLanguage.structure.ClassifierType", null);
       SLinkOperations.setTarget(
           classifierType,
           "classifier",
           SNodeOperations.cast(stringClass, "jetbrains.mps.baseLanguage.structure.Classifier"),
           false);
       return classifierType;
     }
   }
   if (leastCommonSupertypes.isEmpty()) {
     SNode runtimeErrorType =
         SConceptOperations.createNewNode(
             "jetbrains.mps.lang.typesystem.structure.RuntimeErrorType", null);
     SPropertyOperations.set(runtimeErrorType, "errorText", "incompatible types");
     return runtimeErrorType;
   }
   SNode type = leastCommonSupertypes.iterator().next();
   {
     IMatchingPattern pattern_j6k1pf_e0c =
         HUtil.createMatchingPatternByConceptFQName(
             "jetbrains.mps.baseLanguage.structure.PrimitiveType");
     SNode coercedNode_j6k1pf_e0c =
         TypeChecker.getInstance().getRuntimeSupport().coerce_(type, pattern_j6k1pf_e0c);
     if (coercedNode_j6k1pf_e0c != null) {
       return coercedNode_j6k1pf_e0c;
     } else {
       return type;
     }
   }
 }
Beispiel #7
0
  public void init() {
    if (INSTANCE != null) {
      throw new IllegalStateException("double initialization");
    }

    INSTANCE = this;
    myClassLoaderManager.addReloadHandler(myReloadHandler);
    SModelRepository.getInstance().addModelRepositoryListener(mySModelRepositoryListener);
  }
  @Override
  public void init() {
    if (INSTANCE != null) {
      throw new IllegalStateException("double initialization");
    }

    INSTANCE = this;
    SModelRepository.getInstance().registerModelDescriptor(ourInstance, this);
  }
 protected void addListeners() {
   VirtualFileManager.getInstance().addVirtualFileManagerListener(myRefreshListener);
   SModelRepository.getInstance().addModelRepositoryListener(mySModelRepositoryListener);
   ModelAccess.instance().addCommandListener(myModelAccessListener);
   MPSModuleRepository.getInstance().addModuleRepositoryListener(myRepositoryListener);
   if (IMakeService.INSTANCE.isSessionActive()) {
     IMakeService.INSTANCE.get().addListener(myMakeNotificationListener);
   }
   ClassLoaderManager.getInstance().addReloadHandler(myReloadListener);
 }
 protected void removeListeners() {
   ClassLoaderManager.getInstance().removeReloadHandler(myReloadListener);
   SModelRepository.getInstance().removeModelRepositoryListener(mySModelRepositoryListener);
   ModelAccess.instance().removeCommandListener(myModelAccessListener);
   MPSModuleRepository.getInstance().removeModuleRepositoryListener(myRepositoryListener);
   if (IMakeService.INSTANCE.hasMakeService()) {
     IMakeService.INSTANCE.get().removeListener(myMakeNotificationListener);
   }
   VirtualFileManager.getInstance().removeVirtualFileManagerListener(myRefreshListener);
 }
Beispiel #11
0
 @Nullable
 private TreeMessage getMessage(@NotNull ModelFeature modelFeature) {
   SModel md = SModelRepository.getInstance().getModelDescriptor(modelFeature.getModelReference());
   if (md instanceof EditableSModel) {
     FileStatus status = getModelFileStatus((EditableSModel) md, myRegistry.getProject());
     return (status == null ? null : getMessage(status));
   } else {
     return null;
   }
 }
Beispiel #12
0
 public ChangesTracking(@NotNull Project project, @NotNull CurrentDifference difference) {
   myDifference = difference;
   myProject = project;
   myModelDescriptor = myDifference.getModelDescriptor();
   myQueue = CurrentDifferenceRegistry.getInstance(project).getCommandQueue();
   synchronized (this) {
     SModelRepository.getInstance().addModelRepositoryListener(myModelListener);
     myEventsCollector.add(myModelDescriptor);
   }
 }
  public void stopListening() {
    ModelAccess.instance().removeCommandListener(myCommandListener);

    myNodes.clear();
    myModels.clear();
    myModules.clear();

    GlobalSModelEventsManager.getInstance().removeGlobalCommandListener(myModelListener);
    SModelRepository.getInstance().removeModelRepositoryListener(myModelRepositoryListener);
    MPSModuleRepository.getInstance().removeRepositoryListener(myModuleRepositoryListener);
  }
  public static GenerationDependencies fromIncremental(
      Map<SNode, SNode> currentToOriginalMap,
      RootDependenciesBuilder[] roots,
      String modelHash,
      String parametersHash,
      IOperationContext operationContext,
      IncrementalGenerationStrategy incrementalStrategy,
      int skippedCount,
      int fromCacheCount) {
    Map<String, List<String>> generatedFiles = getGeneratedFiles(currentToOriginalMap);

    List<GenerationRootDependencies> unchanged = null;
    List<GenerationRootDependencies> rootDependencies =
        new ArrayList<GenerationRootDependencies>(roots.length);
    Map<String, String> externalHashes = new HashMap<String, String>();
    for (RootDependenciesBuilder l : roots) {
      SNode originalRoot = l.getOriginalRoot();
      List<String> files = generatedFiles.get(originalRoot != null ? originalRoot.getId() : "");
      if (files == null) {
        files = Collections.emptyList();
      }
      GenerationRootDependencies dep;
      if (l.isUnchanged()) {
        dep = l.getSavedDependencies();
        if (unchanged == null) {
          unchanged = new ArrayList<GenerationRootDependencies>();
        }
        unchanged.add(dep);
      } else {
        dep = GenerationRootDependencies.fromData(l, files);
      }
      rootDependencies.add(dep);
      for (String modelReference : dep.getExternal()) {
        if (!externalHashes.containsKey(modelReference)) {
          SModelDescriptor sm =
              SModelRepository.getInstance()
                  .getModelDescriptor(SModelReference.fromString(modelReference));
          Map<String, String> hashes = incrementalStrategy.getModelHashes(sm, operationContext);
          String value = hashes != null ? hashes.get(ModelDigestHelper.FILE) : null;
          externalHashes.put(modelReference, value);
        }
      }
    }
    return new GenerationDependencies(
        rootDependencies,
        modelHash,
        parametersHash,
        externalHashes,
        unchanged == null ? Collections.<GenerationRootDependencies>emptyList() : unchanged,
        skippedCount,
        fromCacheCount);
  }
Beispiel #15
0
 public void dispose() {
   for (SModel model : myListeningForModels) {
     ((SModelInternal) model).removeModelListener(myModelListener);
   }
   myListeningForModels.clear();
   for (SNodeReference nodePointer :
       new ArrayList<SNodeReference>(myTypeCheckingContexts.keySet())) {
     removeContextForNode(nodePointer);
   }
   SModelRepository.getInstance().removeModelRepositoryListener(mySModelRepositoryListener);
   myClassLoaderManager.removeReloadHandler(myReloadHandler);
   INSTANCE = null;
 }
Beispiel #16
0
 @Override
 public void doDispose() {
   for (LanguageErrorsComponent comp : MapSequence.fromMap(myNodePointersToComponents).values()) {
     comp.dispose();
   }
   for (EditorComponent component : myEditorComponents) {
     component.removeDisposeListener(myDisposeListener);
   }
   SModelRepository.getInstance().removeModelRepositoryListener(myRepositoryListener);
   for (SModel modelDescriptor :
       SetSequence.fromSetWithValues(new HashSet<SModel>(), myListenedModels)) {
     removeModelListener(modelDescriptor);
   }
   super.doDispose();
 }
Beispiel #17
0
 public void dispose() {
   synchronized (this) {
     if (!(myDisposed)) {
       myDisposed = true;
       SModelRepository.getInstance().removeModelRepositoryListener(myModelListener);
       myEventsCollector.remove(myModelDescriptor);
       myEventsCollector.dispose();
       myQueue.runTask(
           new Runnable() {
             public void run() {
               myDifference.removeChangeSet();
             }
           });
     }
   }
 }
Beispiel #18
0
  public synchronized Set<SModelReference> resolveModel(
      SModule module, String name, @Nullable SNodeId nodeId) {
    Pair<SModuleReference, String> key =
        new Pair<SModuleReference, String>(module.getModuleReference(), name);
    ensureInitialized(key);

    Set<SModelReference> models = myStubModulesCache.get(key);
    if (nodeId == null) return new HashSet<SModelReference>(models);

    Set<SModelReference> result = new HashSet<SModelReference>();
    for (SModelReference ref : models) {
      SModel m = SModelRepository.getInstance().getModelDescriptor(ref);
      if (m.getNode(nodeId) != null) {
        result.add(ref);
      }
    }

    return result;
  }
Beispiel #19
0
  public static void createModuleForModel(
      SModel model, String version, Project project, boolean mergeResultModel) {
    if (model.getModelDescriptor() != null) {
      return;
    }
    IModule module = null;
    if (mergeResultModel) {
      SModelDescriptor mdInRepo =
          SModelRepository.getInstance().getModelDescriptor(model.getSModelReference());
      if (mdInRepo != null) {
        module = mdInRepo.getModule();
      }
    }

    if (module == null) {
      module = new DiffTemporaryModule(model, version, project);
    }
    model.setModelDescriptor(
        new DiffTemporaryModule.DiffSModelDescriptor(module, model, mergeResultModel));
  }
  public void startListening(DataNode root) {
    ModelAccess.instance().addCommandListener(myCommandListener);

    for (DataNode node : root.getDescendantsByDataClass(NodeNodeData.class)) {
      NodeNodeData nodeData = (NodeNodeData) node.getData();
      myNodes.add(nodeData.getNodePointer());
    }

    for (DataNode node : root.getDescendantsByDataClass(ModelNodeData.class)) {
      ModelNodeData modelData = (ModelNodeData) node.getData();
      myModels.add(modelData.getModelReference());
    }

    for (DataNode node : root.getDescendantsByDataClass(ModuleNodeData.class)) {
      ModuleNodeData moduleData = (ModuleNodeData) node.getData();
      myModules.add(moduleData.getModuleReference());
    }

    GlobalSModelEventsManager.getInstance().addGlobalCommandListener(myModelListener);
    SModelRepository.getInstance().addModelRepositoryListener(myModelRepositoryListener);
    MPSModuleRepository.getInstance().addRepositoryListener(myModuleRepositoryListener);
  }
Beispiel #21
0
  private void addModelsForDir(
      PsiDirectory sourceRoot, PsiDirectory dir, Map<PsiJavaStubDataSource, SModel> resultMap) {
    if (Sequence.fromIterable(Sequence.fromArray(dir.getFiles()))
        .ofType(PsiJavaFile.class)
        .isNotEmpty()) {

      SModelReference modelRef = makeModelReference(sourceRoot, dir);
      SModel model = SModelRepository.getInstance().getModelDescriptor(modelRef);

      if (model == null) {
        model = makeModelDescriptor(modelRef, dir);
      }

      assert model instanceof PsiJavaStubModelDescriptor;

      PsiJavaStubDataSource dataSource = ((PsiJavaStubModelDescriptor) model).getSource();
      MapSequence.fromMap(resultMap).put(dataSource, model);
    }

    for (PsiDirectory subDir : dir.getSubdirectories()) {
      addModelsForDir(sourceRoot, subDir, resultMap);
    }
  }
 /*package*/ void updateImportVersions(
     EditableSModelDescriptor model, final Map<String, Object> _params) {
   jetbrains.mps.smodel.SModel m = model.getSModel();
   for (jetbrains.mps.smodel.SModel.ImportElement importElement :
       ListSequence.fromList(SModelOperations.getAllImportElements(model.getSModel()))) {
     RefactorableSModelDescriptor usedModel =
         as_hexye9_a0a0a1a7(
             SModelRepository.getInstance().getModelDescriptor(importElement.getModelReference()),
             RefactorableSModelDescriptor.class);
     if (usedModel == null) {
       continue;
     }
     if (importElement.getUsedVersion() < usedModel.getVersion()) {
       LOG.info(
           model
               + ": updating used version of "
               + importElement.getModelReference()
               + " from "
               + importElement.getUsedVersion()
               + " to "
               + usedModel.getVersion());
       m.updateImportedModelUsedVersion(importElement.getModelReference(), usedModel.getVersion());
       model.setChanged(true);
     } else if (importElement.getUsedVersion() > usedModel.getVersion()) {
       LOG.error(
           model
               + ": used version of "
               + importElement.getModelReference()
               + " is greater than model version: "
               + importElement.getUsedVersion()
               + ">"
               + usedModel.getVersion());
       m.updateImportedModelUsedVersion(importElement.getModelReference(), usedModel.getVersion());
       model.setChanged(true);
     }
   }
 }
Beispiel #23
0
 public LanguageErrorsComponent(SModel model) {
   myModel = model;
   SModelRepository.getInstance().addModelRepositoryListener(myModelRepositoryListener);
 }
Beispiel #24
0
 public FileStatus getFileStatus() {
   SModel md = SModelRepository.getInstance().getModelDescriptor(myModelReference);
   boolean changed = md instanceof EditableSModel && ((EditableSModel) md).isChanged();
   return changed ? FileStatus.MODIFIED : FileStatus.NOT_CHANGED;
 }
Beispiel #25
0
 private boolean isValidName(String modelName) {
   return SModelRepository.getInstance().getModelDescriptor(modelName) == null
       && !myModels.containsKey(modelName);
 }
Beispiel #26
0
 public SNode findRuleNode() {
   SModelDescriptor modelDescriptor =
       SModelRepository.getInstance().getModelDescriptor(SModelReference.fromString(myRuleModel));
   if (modelDescriptor == null) return null;
   return modelDescriptor.getSModel().getNodeById(myRuleId);
 }
Beispiel #27
0
 public void dispose() {
   this.removeModelListener();
   SModelRepository.getInstance().removeModelRepositoryListener(myModelRepositoryListener);
 }
Beispiel #28
0
 public SModel getMyModel() {
   return SModelRepository.getInstance()
       .getModelDescriptor(
           "jetbrains.mps.execution.impl.configurations.tests.commands.sandbox@tests");
 }