@Override
 protected boolean acceptModel(SModel model) {
   if (SModelStereotype.isStubModelStereotype(SModelStereotype.getStereotype(model))) {
     return false;
   }
   return acceptModule(model.getModule());
 }
 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);
   }
 }
  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 "???";
  }
 /*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);
   }
 }
Example #5
0
 private TestSModelDescriptor(String modelName, SModel toCopy) {
   super(
       PersistenceFacade.getInstance()
           .createModelReference(null, jetbrains.mps.smodel.SModelId.generate(), modelName));
   myLongName = SModelStereotype.withoutStereotype(modelName);
   myToCopy = toCopy;
 }
  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));
              }
            });
  }
Example #7
0
  public static List<SModelDescriptor> getLanguageModels(Language lang) {
    List<SModelDescriptor> inputModels = new ArrayList<SModelDescriptor>();
    for (LanguageAspect aspect : LanguageAspect.values()) {
      SModelDescriptor model = aspect.get(lang);
      if (model != null) {
        inputModels.add(model);
      }
    }

    Set<SModelDescriptor> ownModels = new HashSet<SModelDescriptor>(lang.getOwnModelDescriptors());
    for (SModelDescriptor sm : lang.getAccessoryModels()) {
      if (!SModelStereotype.isUserModel(sm)) continue;
      if (!(sm instanceof EditableSModelDescriptor)) continue;

      if (ownModels.contains(sm)) {
        inputModels.add(((EditableSModelDescriptor) sm));
      }
    }

    inputModels.addAll(lang.getUtilModels());

    // add it from all generators
    List<Generator> list = lang.getGenerators();
    for (Generator generator : list) {
      inputModels.addAll(generator.getGeneratorModels());
    }
    return inputModels;
  }
Example #8
0
 public static Collection<String> getUsedLanguageNamespaces(
     SModel model, boolean isTemplateModel) {
   if (isTemplateModel) {
     return getUsedLanguageNamespacesInTemplateModel(model);
   }
   if (SModelStereotype.isGeneratorModel(model)) {
     TemplateModelScanner templateModelScanner = new TemplateModelScanner(model);
     templateModelScanner.scan();
     Set<String> namespaces = new HashSet<String>(templateModelScanner.getQueryLanguages());
     for (SModuleReference ref :
         ((jetbrains.mps.smodel.SModelInternal) model).engagedOnGenerationLanguages()) {
       namespaces.add(ref.getModuleName());
     }
     return namespaces;
   }
   Set<String> namespaces = new HashSet<String>();
   for (SModuleReference ref :
       ((jetbrains.mps.smodel.SModelInternal) model).engagedOnGenerationLanguages()) {
     namespaces.add(ref.getModuleName());
   }
   for (SNode root : model.getRootNodes()) {
     namespaces.add(NameUtil.namespaceFromConceptFQName(root.getConcept().getId()));
     for (SNode child : jetbrains.mps.util.SNodeOperations.getDescendants(root, null)) {
       namespaces.add(NameUtil.namespaceFromConceptFQName(child.getConcept().getId()));
     }
   }
   // empty behavior model should have it's behavior aspect descriptor generated
   if (model.getModule() instanceof Language && LanguageAspect.BEHAVIOR.is(model)) {
     namespaces.add(BootstrapLanguages.BEHAVIOR.getModuleName());
   }
   return namespaces;
 }
Example #9
0
  @Override
  public List<String> getWarnings() {
    List<String> warnings = new ArrayList<String>(super.getWarnings());
    Set<String> usedLanguages = new HashSet<String>();
    for (SModel model : myModule.getOwnTemplateModels()) {
      if (SModelStereotype.isGeneratorModel(model)) {
        usedLanguages.addAll(ModelContentUtil.getUsedLanguageNamespacesInTemplateModel(model));
      }
    }
    Set<String> extendedLanguages = new HashSet<String>();
    Language sourceLanguage = myModule.getSourceLanguage();
    usedLanguages.remove(sourceLanguage.getModuleName());

    Set<Language> ext = new LinkedHashSet<Language>();
    sourceLanguage.getDependenciesManager().collectAllExtendedLanguages(ext);

    for (Language language : ext) {
      extendedLanguages.add(language.getModuleName());
    }

    for (String lang : usedLanguages) {
      Language language = ModuleRepositoryFacade.getInstance().getModule(lang, Language.class);
      if (language == null) continue;

      if (!extendedLanguages.contains(lang) && !language.getRuntimeModulesReferences().isEmpty()) {
        warnings.add(sourceLanguage + " should extend " + lang);
      }
    }
    return warnings;
  }
  public void stopListening() {
    if (!SModelStereotype.isStubModelStereotype(myModel.getStereotype())) {
      ModelGenerationStatusManager.getInstance().removeGenerationStatusListener(myStatusListener);
    }

    myModel.removeModelListener(mySimpleModelListener);
    SModelEventsDispatcher.getInstance().unregisterListener(myEventsListener);
  }
 private static boolean renderingCondition_1x071y_a01a(
     SNode node, EditorContext editorContext, IScope scope) {
   return SNodeOperations.getAncestor(
               node, "jetbrains.mps.baseLanguage.structure.AnonymousClass", false, false)
           == null
       && !(SModelStereotype.isStubModelStereotype(
           SNodeOperations.getModel(node).getStereotype()));
 }
Example #12
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;
  }
  public void startListening() {
    visitNode(myTreeNode);

    SModelEventsDispatcher.getInstance().registerListener(myEventsListener);
    myModel.addModelListener(mySimpleModelListener);

    if (!SModelStereotype.isStubModelStereotype(myModel.getStereotype())) {
      ModelGenerationStatusManager.getInstance().addGenerationStatusListener(myStatusListener);
    }
  }
Example #14
0
 @Override
 public SModel resolveInDependencies(SModelId reference) {
   boolean own =
       reference.getModelName() != null
           && myModels
               .keySet()
               .contains(SModelStereotype.withoutStereotype(reference.getModelName()));
   if (!own) return super.resolveInDependencies(reference);
   return myModels.get(reference.getModelName());
 }
  private boolean checkResolvedTarget(AbstractTemplateGenerator generator, SNode outputTargetNode) {
    Status status =
        generator
            .getReferentRoleValidator(myOutputSourceNode, myReferenceRole)
            .validate(outputTargetNode);
    if (status != null) {
      generator
          .getLogger()
          .error(
              myOutputSourceNode.getReference(),
              status.getMessage(getClass().getSimpleName()),
              getErrorDescriptions());
      return false;
    }

    SModel referentNodeModel = outputTargetNode.getModel();
    if (referentNodeModel != null && referentNodeModel != myOutputSourceNode.getModel()) {
      if (SModelStereotype.isGeneratorModel(referentNodeModel)) {
        // references to template nodes are not acceptable
        String msg = "bad reference, cannot refer to a generator model: %s for role '%s' in %s";
        generator
            .getLogger()
            .error(
                myOutputSourceNode.getReference(),
                String.format(
                    msg,
                    SNodeUtil.getDebugText(outputTargetNode),
                    myReferenceRole,
                    SNodeUtil.getDebugText(myOutputSourceNode)),
                getErrorDescriptions());
        return false;
      }
      if (referentNodeModel.getModule() instanceof TransientModelsModule) {
        // references to transient nodes in a model outside one being generated are not acceptable
        String msg =
            "bad reference, cannot refer to an external transient model: %s  for role '%s' in %s";
        generator
            .getLogger()
            .error(
                myOutputSourceNode.getReference(),
                String.format(
                    msg,
                    SNodeUtil.getDebugText(outputTargetNode),
                    myReferenceRole,
                    SNodeUtil.getDebugText(myOutputSourceNode)),
                getErrorDescriptions());
        return false;
      }
    }
    return true;
  }
 public static void warnIfUnitNameInvalid(String unitName, SNode node) {
   String longName =
       SModelStereotype.withoutStereotype(node.getModel().getReference().getModelName());
   if (!(unitName.startsWith(longName))) {
     LOG.warning(
         "Unit name has to start with model fqName. Fix " + unitName + " in " + longName + ".",
         node);
   } else if (unitName.length() <= longName.length() + 1
       || !(unitName.substring(longName.length()).startsWith("."))
       || unitName.substring(longName.length() + 1).contains(".")) {
     LOG.warning(
         "Unit name has to match \"modelFqName.shortUnitName\" where short unit name does not contain dots. Fix "
             + unitName
             + " in "
             + longName
             + ".",
         node);
   }
 }
  public static Object virtual_getCompileTimeConstantValue_1238860310638(
      SNode thisNode, IModule module) {
    if (SNodeOperations.isInstanceOf(
        SLinkOperations.getTarget(thisNode, "variableDeclaration", false),
        "jetbrains.mps.baseLanguage.structure.StaticFieldDeclaration")) {
      // todo
      SNode declaration =
          SNodeOperations.cast(
              SLinkOperations.getTarget(thisNode, "variableDeclaration", false),
              "jetbrains.mps.baseLanguage.structure.StaticFieldDeclaration");
      SNode classifier =
          SNodeOperations.as(
              SNodeOperations.getParent(declaration),
              "jetbrains.mps.baseLanguage.structure.Classifier");
      if ((classifier != null)
          && SModelStereotype.isStubModelStereotype(
              SNodeOperations.getModel(classifier).getSModelReference().getStereotype())) {
        return Expression_Behavior.call_eval_1213877519769(thisNode, module);
      } else {
        return (BehaviorReflection.invokeVirtual(
                Boolean.TYPE,
                SLinkOperations.getTarget(declaration, "initializer", true),
                "virtual_isCompileTimeConstant_1238860258777",
                new Object[] {})
            ? BehaviorReflection.invokeVirtual(
                Object.class,
                SLinkOperations.getTarget(declaration, "initializer", true),
                "virtual_getCompileTimeConstantValue_1238860310638",
                new Object[] {module})
            : null);
      }
    }

    return BehaviorReflection.invokeSuper(
        Object.class,
        thisNode,
        "jetbrains.mps.baseLanguage.structure.Expression",
        "virtual_getCompileTimeConstantValue_1238860310638",
        new Object[] {module});
  }
Example #18
0
  @Override
  public List<String> getErrors() {
    List<String> errors = new ArrayList<String>(super.getErrors());
    for (SModuleReference lang : myModule.getExtendedLanguageRefs()) {
      if (MPSModuleRepository.getInstance().getModule(lang) == null) {
        errors.add("Can't find extended language: " + lang.getModuleName());
      }
    }
    checkBehaviorAspectPresence(myModule, errors);
    for (SModuleReference mr : myModule.getRuntimeModulesReferences()) {
      SModule runtimeModule = MPSModuleRepository.getInstance().getModule(mr);
      if (runtimeModule == null) continue;
      if (!(runtimeModule instanceof Solution)) {
        errors.add("Runtime module " + runtimeModule + " is not a solution");
      }
    }
    for (SModelReference accessory : myModule.getModuleDescriptor().getAccessoryModels()) {
      // this check is wrong in common as we don't know what the user wants to do with the acc model
      // in build.
      // but I'll not delete it until accessories removal just to have some warning on project
      // consistency
      org.jetbrains.mps.openapi.model.SModel accModel =
          accessory.resolve(MPSModuleRepository.getInstance());
      if (accModel == null) continue;

      if (!VisibilityUtil.isVisible(myModule, accModel)) {
        errors.add(
            "Can't find accessory model: "
                + SModelStereotype.withoutStereotype(accessory.getModelName()));
      }
    }
    for (SModuleReference ref : myModule.getModuleDescriptor().getRuntimeModules()) {
      if (MPSModuleRepository.getInstance().getModule(ref) == null) {
        errors.add("Can't find runtime module: " + ref.getModuleName());
      }
    }
    return errors;
  }
Example #19
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()*/));
    }
  }
Example #20
0
 public static boolean call_isInTemplates_1213877396627(SNode thisNode) {
   return SModelStereotype.isGeneratorModel(SNodeOperations.getModel(thisNode));
 }
Example #21
0
  @Override
  public SModel loadSModel(IModule module, SModelDescriptor descriptor) {
    SModel model = new SModel(descriptor.getSModelReference(), new ForeignNodeIdMap());
    ModuleReference lang =
        MPSModuleRepository.getInstance()
            .getModuleById(ModuleId.fromString("32d0a39c-772f-4490-8142-e50f9a9f19d4"))
            .getModuleReference();
    model.addLanguage(lang);

    String pkg = model.getSModelFqName().getLongName();
    List<Tuples._4<String, String, SNode, PathItem>> doclst =
        ListSequence.fromList(new ArrayList<Tuples._4<String, String, SNode, PathItem>>());
    SNode sample =
        SConceptOperations.createNewNode(
            "jetbrains.mps.platform.conf.structure.ConfigurationXmlDocument", null);
    for (String path : roots) {
      PathItem pi = ConfPathItem.getPathItem(path);
      for (String docres : ListSequence.fromList(pi.resources(pkg))) {
        SNodeId id = ConfReader.createForeignId(pi.baseName(docres));
        SNode doc = (SNode) model.getNodeById(id);
        if ((doc == null)) {
          doc =
              SConceptOperations.createNewNode(
                  NameUtil.nodeFQName(
                      SConceptOperations.findConceptDeclaration(
                          "jetbrains.mps.platform.conf.structure.ConfigurationXmlDocument")),
                  sample);
          ((jetbrains.mps.smodel.SNode) doc).setId(id);
          SPropertyOperations.set(doc, "name", pi.baseName(docres));
          SModelOperations.addRootNode(((SModel) model), doc);
          ListSequence.fromList(doclst)
              .addElement(MultiTuple.<String, String, SNode, PathItem>from(pkg, docres, doc, pi));
        }
      }
    }
    final StubModelDescriptors descs =
        new StubModelDescriptors(SModelStereotype.getStubStereotypeForId("conf"), roots, module) {
          @Override
          public StubModelDataSource createStubsSource(String path) {
            return new ConfStubSource(path);
          }
        };
    ConfReader reader =
        new ConfReader(
            new ConfReader.Resolver() {
              public SModelReference stubModelReference(String pk) {
                return descs.javaStubRef(pk);
              }
            },
            new ConfReader.Resolver() {
              public SModelReference stubModelReference(String pk) {
                return descs.smodelRefWithId(pk);
              }
            });
    for (Tuples._4<String, String, SNode, PathItem> doctuple : ListSequence.fromList(doclst)) {
      InputStream is = null;
      try {
        is = doctuple._3().openResource(doctuple._0(), doctuple._1());
        reader.read(doctuple._2(), new SAXBuilder().build(is));
      } catch (IOException e) {
        e.printStackTrace();
      } catch (JDOMException e) {
        e.printStackTrace();
      }
      if (is != null) {
        try {
          is.close();
        } catch (IOException e) {
        }
      }
    }
    SNodeOperations.deleteNode(sample);
    return model;
  }
Example #22
0
 public boolean isApplicable(SModelDescriptor model) {
   return SModelStereotype.isTestModel(model);
 }
 private static boolean _StyleParameter_QueryFunction_fao2ea_a0a0(
     EditorContext editorContext, SNode node) {
   return !(SModelStereotype.isStubModelStereotype(
       SNodeOperations.getModelStereotype(
           jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations.getModel(node))));
 }
Example #24
0
 public static boolean shouldReportError(SNode node) {
   if (SModelUtil_new.getMetaLevel(node) != 0) return false;
   if (SModelStereotype.isStubModelStereotype(node.getModel().getStereotype())) return false;
   return true;
 }
Example #25
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;
    }
 private static boolean staticCanBeARoot(SModel model, final IOperationContext operationContext) {
   return SModuleOperations.isAspect(model, "editor") || SModelStereotype.isGeneratorModel(model);
 }
Example #27
0
 public static Iterable<SNode> getRootsToIterate(SModel model) {
   if (SModelStereotype.isStubModelStereotype(
       jetbrains.mps.util.SNodeOperations.getModelStereotype(model)))
     return new EmptyIterable<SNode>();
   return new ConditionalIterable<SNode>(model.getRootNodes(), new MyCondition());
 }
 public static boolean static_canBeARoot(SModel model, final IOperationContext operationContext) {
   return LanguageAspect.EDITOR.is(model) || SModelStereotype.isGeneratorModel(model);
 }
  private void update(SNode method, SNode baseMethod) {
    if (SModelStereotype.isStubModelStereotype(
        SNodeOperations.getModel(baseMethod).getStereotype())) {
      setVariableNames(method, MapSequence.fromMap(new HashMap<String, Integer>()));
    }
    if (myRemoveAttributes) {
      for (SNode child : SNodeOperations.getChildren(method)) {
        removeAttributes(child);
      }
    }
    boolean isInterfaceMethod =
        SNodeOperations.isInstanceOf(
                SNodeOperations.getParent(baseMethod),
                "jetbrains.mps.baseLanguage.structure.Interface")
            || SPropertyOperations.getBoolean(baseMethod, "isAbstract");
    if (myInsertOverride && !(isInterfaceMethod)) {
      boolean isNeedAddAnnotation = true;
      for (SNode annotation : SLinkOperations.getTargets(method, "annotation", true)) {
        if (SLinkOperations.getTarget(annotation, "annotation", false)
            == SNodeOperations.getNode(
                "f:java_stub#6354ebe7-c22a-4a0f-ac54-50b52ab9b065#java.lang(JDK/java.lang@java_stub)",
                "~Override")) {
          isNeedAddAnnotation = false;
          break;
        }
      }
      if (isNeedAddAnnotation) {
        ListSequence.fromList(SLinkOperations.getTargets(method, "annotation", true))
            .addElement(_quotation_createNode_tfz3o4_a0a0a2a3a8());
      }
    }

    Iterable<SNode> paramList =
        ListSequence.fromList(SLinkOperations.getTargets(method, "parameter", true))
            .select(
                new ISelector<SNode, SNode>() {
                  public SNode select(SNode it) {
                    return _quotation_createNode_tfz3o4_a0a0a0a5a8(it);
                  }
                });
    SNode defaultExpr;
    if (isInterfaceMethod) {
      defaultExpr =
          BehaviorReflection.invokeVirtual(
              (Class<SNode>) ((Class) Object.class),
              SLinkOperations.getTarget(baseMethod, "returnType", true),
              "virtual_createDefaultTypeExpression_3359611512358152580",
              new Object[] {});
    } else {
      defaultExpr =
          _quotation_createNode_tfz3o4_a0a0a7a8(
              baseMethod, Sequence.fromIterable(paramList).toListSequence());
    }

    if (SNodeOperations.isInstanceOf(
        SLinkOperations.getTarget(method, "returnType", true),
        "jetbrains.mps.baseLanguage.structure.VoidType")) {
      if (!(isInterfaceMethod)) {
        ListSequence.fromList(
                SLinkOperations.getTargets(
                    SLinkOperations.getTarget(method, "body", true), "statement", true))
            .addElement(_quotation_createNode_tfz3o4_a0a0a0a9a8(defaultExpr));
      }
    } else {
      ListSequence.fromList(
              SLinkOperations.getTargets(
                  SLinkOperations.getTarget(method, "body", true), "statement", true))
          .addElement(getReturnStatement(defaultExpr));
    }
  }