コード例 #1
0
 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);
   }
 }
コード例 #2
0
ファイル: TreeHighlighter.java プロジェクト: Guojin118/MPS-1
  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));
      }
    }
  }
コード例 #3
0
  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));
              }
            });
  }
コード例 #4
0
ファイル: LanguageEditorChecker.java プロジェクト: qyqx/MPS
  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);
  }
コード例 #5
0
  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 "???";
  }
コード例 #6
0
ファイル: Queries.java プロジェクト: strategist922/MPS
 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;
     }
   }
 }
コード例 #7
0
ファイル: TypeContextManager.java プロジェクト: sprig/MPS
  public void init() {
    if (INSTANCE != null) {
      throw new IllegalStateException("double initialization");
    }

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

    INSTANCE = this;
    SModelRepository.getInstance().registerModelDescriptor(ourInstance, this);
  }
コード例 #9
0
 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);
 }
コード例 #10
0
 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);
 }
コード例 #11
0
ファイル: TreeHighlighter.java プロジェクト: Guojin118/MPS-1
 @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;
   }
 }
コード例 #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);
   }
 }
コード例 #13
0
  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);
  }
コード例 #14
0
  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);
  }
コード例 #15
0
ファイル: TypeContextManager.java プロジェクト: sprig/MPS
 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;
 }
コード例 #16
0
ファイル: LanguageEditorChecker.java プロジェクト: qyqx/MPS
 @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();
 }
コード例 #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();
             }
           });
     }
   }
 }
コード例 #18
0
ファイル: StubModelsResolver.java プロジェクト: brigand/MPS
  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;
  }
コード例 #19
0
ファイル: DiffTemporaryModule.java プロジェクト: blutkind/MPS
  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));
  }
コード例 #20
0
  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);
  }
コード例 #21
0
ファイル: PsiJavaStubModelRoot.java プロジェクト: qyqx/MPS
  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);
    }
  }
コード例 #22
0
 /*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);
     }
   }
 }
コード例 #23
0
 public LanguageErrorsComponent(SModel model) {
   myModel = model;
   SModelRepository.getInstance().addModelRepositoryListener(myModelRepositoryListener);
 }
コード例 #24
0
ファイル: BaseModelItem.java プロジェクト: strategist922/MPS
 public FileStatus getFileStatus() {
   SModel md = SModelRepository.getInstance().getModelDescriptor(myModelReference);
   boolean changed = md instanceof EditableSModel && ((EditableSModel) md).isChanged();
   return changed ? FileStatus.MODIFIED : FileStatus.NOT_CHANGED;
 }
コード例 #25
0
ファイル: TestModule.java プロジェクト: handong890/MPS
 private boolean isValidName(String modelName) {
   return SModelRepository.getInstance().getModelDescriptor(modelName) == null
       && !myModels.containsKey(modelName);
 }
コード例 #26
0
ファイル: EquationInfo.java プロジェクト: lilongthinker/MPS
 public SNode findRuleNode() {
   SModelDescriptor modelDescriptor =
       SModelRepository.getInstance().getModelDescriptor(SModelReference.fromString(myRuleModel));
   if (modelDescriptor == null) return null;
   return modelDescriptor.getSModel().getNodeById(myRuleId);
 }
コード例 #27
0
 public void dispose() {
   this.removeModelListener();
   SModelRepository.getInstance().removeModelRepositoryListener(myModelRepositoryListener);
 }
コード例 #28
0
 public SModel getMyModel() {
   return SModelRepository.getInstance()
       .getModelDescriptor(
           "jetbrains.mps.execution.impl.configurations.tests.commands.sandbox@tests");
 }