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);
   }
 }
 @Override
 protected boolean acceptModel(SModel model) {
   if (SModelStereotype.isStubModelStereotype(SModelStereotype.getStereotype(model))) {
     return false;
   }
   return acceptModule(model.getModule());
 }
Esempio n. 3
0
  public static Collection<SModel> getModifiedModels(Collection<? extends SModel> models) {
    Set<SModel> result = new LinkedHashSet<SModel>();
    ModelGenerationStatusManager statusManager = ModelGenerationStatusManager.getInstance();
    for (SModel sm : models) {
      if (statusManager.generationRequired(sm)) {
        result.add(sm);
        continue;
      }

      // TODO regenerating all dependant models can be slow, option?
      if (!(SModelStereotype.DESCRIPTOR.equals(SModelStereotype.getStereotype(sm))
          || LanguageAspect.BEHAVIOR.is(sm)
          || LanguageAspect.CONSTRAINTS.is(sm))) {
        // temporary solution: only descriptor/behavior/constraints models
        continue;
      }

      final SRepository repository = sm.getRepository();
      if (repository == null) {
        // no idea how to treat a model which hands in the air; expect it to be editable and tell
        // isChanged if desires re-generation
        continue;
      }
      GenerationDependencies oldDependencies = GenerationDependenciesCache.getInstance().get(sm);
      // FIXME use SRepository to pick proper GenerationDependenciesCache instance
      if (oldDependencies == null) {
        // TODO turn on when generated file will be mandatory
        // result.add(sm);
        continue;
      }

      Map<String, String> externalHashes = oldDependencies.getExternalHashes();
      for (Entry<String, String> entry : externalHashes.entrySet()) {
        String modelReference = entry.getKey();
        SModel rmd =
            PersistenceFacade.getInstance()
                .createModelReference(modelReference)
                .resolve(repository);
        if (rmd == null) {
          result.add(sm);
          break;
        }
        String oldHash = entry.getValue();
        if (oldHash == null) {
          continue;
        }
        String newHash = statusManager.currentHash(rmd);
        if (newHash == null || !oldHash.equals(newHash)) {
          result.add(sm);
          break;
        }
      }
    }

    return result;
  }
 /*package*/ static Object getCompileTimeConstantValue_idi1LP2xI(
     @NotNull SNode __thisNode__, SModule module) {
   SNode classifier =
       SLinkOperations.getTarget(
           __thisNode__,
           MetaAdapterFactory.getReferenceLink(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xf940c80846L,
               0x10a75869f9bL,
               "classifier"));
   if ((classifier != null)
       && SModelStereotype.isStubModelStereotype(
           SModelStereotype.getStereotype(
               SNodeOperations.getModel(classifier).getReference().getModelName()))) {
     return Expression__BehaviorDescriptor.eval_idhEwJgmp.invoke(__thisNode__, module);
   } else {
     return ((boolean)
             Expression__BehaviorDescriptor.isCompileTimeConstant_idi1LOPRp.invoke(
                 SLinkOperations.getTarget(
                     SLinkOperations.getTarget(
                         __thisNode__,
                         MetaAdapterFactory.getReferenceLink(
                             0xf3061a5392264cc5L,
                             0xa443f952ceaf5816L,
                             0xf8c77f1e98L,
                             0xf8cc6bf960L,
                             "variableDeclaration")),
                     MetaAdapterFactory.getContainmentLink(
                         0xf3061a5392264cc5L,
                         0xa443f952ceaf5816L,
                         0xf8c37a7f6eL,
                         0xf8c37f506eL,
                         "initializer")))
         ? Expression__BehaviorDescriptor.getCompileTimeConstantValue_idi1LP2xI.invoke(
             SLinkOperations.getTarget(
                 SLinkOperations.getTarget(
                     __thisNode__,
                     MetaAdapterFactory.getReferenceLink(
                         0xf3061a5392264cc5L,
                         0xa443f952ceaf5816L,
                         0xf8c77f1e98L,
                         0xf8cc6bf960L,
                         "variableDeclaration")),
                 MetaAdapterFactory.getContainmentLink(
                     0xf3061a5392264cc5L,
                     0xa443f952ceaf5816L,
                     0xf8c37a7f6eL,
                     0xf8c37f506eL,
                     "initializer")),
             module)
         : null);
   }
 }
Esempio n. 5
0
    @Override
    public List<SearchResult<ModelCheckerIssue>> checkModel(
        SModel model, ProgressMonitor monitor, SRepository repository) {
      List<SearchResult<ModelCheckerIssue>> results =
          ListSequence.fromList(new ArrayList<SearchResult<ModelCheckerIssue>>());

      monitor.start("adapter usages", 1);
      for (SNode node : ListSequence.fromList(SModelOperations.getNodes(model, null))) {
        if (monitor.isCanceled()) {
          break;
        }
        // Check for adapter references
        for (SReference ref : Sequence.fromIterable(SNodeOperations.getReferences(node))) {
          SModelReference targetSModelReference = ref.getTargetSModelReference();
          if (targetSModelReference != null
              && SModelStereotype.getStereotype(targetSModelReference.getModelName())
                  .equals("java_stub")) {
            SNode target = SLinkOperations.getTargetNode(ref);
            if ((target != null)
                && SNodeOperations.isInstanceOf(
                    target, "jetbrains.mps.baseLanguage.structure.ClassConcept")) {
              String qualifiedName =
                  BehaviorReflection.invokeVirtual(
                      String.class,
                      SNodeOperations.cast(
                          target, "jetbrains.mps.baseLanguage.structure.ClassConcept"),
                      "virtual_getFqName_1213877404258",
                      new Object[] {});
              if ("jetbrains.mps.smodel.INodeAdapter".equals(qualifiedName)
                  || "jetbrains.mps.smodel.BaseAdapter".equals(qualifiedName)) {
                SpecificChecker.addIssue(
                    results,
                    node,
                    "Reference to "
                        + qualifiedName
                        + " in role `"
                        + SLinkOperations.getRole(ref)
                        + "'",
                    ModelChecker.SEVERITY_ERROR,
                    "adapter class usage",
                    null);
              }

              if (SModelStereotype.withoutStereotype(targetSModelReference.getModelName())
                      .endsWith(".structure")
                  && SModelUtil.findConceptDeclaration(qualifiedName) != null) {
                SpecificChecker.addIssue(
                    results,
                    node,
                    "Using adapter of "
                        + qualifiedName
                        + " concept in role `"
                        + SLinkOperations.getRole(ref)
                        + "'",
                    ModelChecker.SEVERITY_ERROR,
                    "adapter class usage",
                    null);
              }
            }
          }
        }
      }
      monitor.done();
      return results;
    }
Esempio n. 6
0
  @Override
  public void doUpdate(AnActionEvent event) {
    removeAll();

    SModel modelDescriptor = event.getData(MPSDataKeys.CONTEXT_MODEL);
    if (modelDescriptor == null) {
      setEnabledState(event.getPresentation(), false);
      return;
    }

    if (!(modelDescriptor instanceof EditableSModel)
        || (((EditableSModel) modelDescriptor).isReadOnly())) {
      event.getPresentation().setEnabled(false);
      event.getPresentation().setVisible(false);
      return;
    }

    IScope scope = event.getData(MPSDataKeys.SCOPE);
    IOperationContext context = event.getData(MPSDataKeys.OPERATION_CONTEXT);

    boolean isStubModel =
        SModelStereotype.isStubModelStereotype(SModelStereotype.getStereotype(modelDescriptor));
    if (scope == null || context == null || isStubModel) {
      setEnabledState(event.getPresentation(), false);
      return;
    }

    boolean inEditor = event.getData(MPSDataKeys.LOGICAL_VIEW_SELECTION_SIZE) == null;

    if (!inEditor) {
      Integer selectedItemsCount = event.getData(MPSDataKeys.LOGICAL_VIEW_SELECTION_SIZE);
      boolean singleItemSelected = selectedItemsCount != null && selectedItemsCount == 1;

      if (!singleItemSelected) {
        setEnabledState(event.getPresentation(), false);
        return;
      }

      TreeNode treeNode = event.getData(MPSDataKeys.LOGICAL_VIEW_NODE);

      if (!(treeNode instanceof PackageNode)) {
        myPackage = null;
      } else {
        final PackageNode node = (PackageNode) treeNode;
        myPackage = node.getPackage();
      }
    } else {
      SNode node = event.getData(MPSDataKeys.NODE);
      myPackage = null;
      if (node != null) {
        SNode root = node.getContainingRoot();
        myPackage =
            SNodeAccessUtil.getProperty(root, SNodeUtil.property_BaseConcept_virtualPackage);
      }
    }

    setEnabledState(event.getPresentation(), true);

    List<Language> modelLanguages = SModelOperations.getLanguages(modelDescriptor, scope);

    LanguageAspect aspect = Language.getModelAspect(modelDescriptor);
    if (aspect != null) {
      SModuleReference ref = aspect.getMainLanguage();
      Language lang = scope.getLanguage(ref);
      if (lang != null) {
        modelLanguages.remove(lang);

        for (SNode conceptDeclaration : lang.getConceptDeclarations()) {
          if (ModelConstraintsManager.canBeRoot(
              context, NameUtil.nodeFQName(conceptDeclaration), modelDescriptor)) {
            add(
                new NewRootNodeAction(
                    new jetbrains.mps.smodel.SNodePointer(conceptDeclaration), modelDescriptor));
          }
        }

        addSeparator();
      }
    }

    Collections.sort(modelLanguages, new ToStringComparator());

    List<Language> languagesWithRoots = new ArrayList<Language>();
    for (final Language language : modelLanguages) {
      for (SNode conceptDeclaration : language.getConceptDeclarations()) {
        if (ModelConstraintsManager.canBeRoot(
            context, NameUtil.nodeFQName(conceptDeclaration), modelDescriptor)) {
          languagesWithRoots.add(language);
          break;
        }
      }
    }

    boolean plain = myPlain || (languagesWithRoots.size() == 1 && aspect == null);

    for (final Language language : languagesWithRoots) {
      String name = language.getModuleName();
      Icon icon = IconManager.getIconForNamespace(language.getModuleName());
      BaseGroup langRootsGroup;

      if (!plain) {
        langRootsGroup = new BaseGroup(NameUtil.compactNamespace(name), name, icon);
        langRootsGroup.setPopup(true);
      } else {
        langRootsGroup = this;
      }

      for (SNode conceptDeclaration : language.getConceptDeclarations()) {
        if (ModelConstraintsManager.getInstance()
            .canBeRoot(context, NameUtil.nodeFQName(conceptDeclaration), modelDescriptor)) {
          langRootsGroup.add(
              new NewRootNodeAction(
                  new jetbrains.mps.smodel.SNodePointer(conceptDeclaration), modelDescriptor));
        }
      }
      if (!plain) {
        this.add(langRootsGroup);
      } else {
        this.addSeparator();
      }
    }

    if (getChildrenCount() == 0) {
      add(
          ActionManager.getInstance()
              .getAction(
                  "jetbrains.mps.ide.editor.actions.AddLanguageImport_Action" /* FIXME AddLanguageImport_Action.class.getName()*/));
    }
  }