private static List<INodeSubstituteAction> createPrimaryChildSubstituteActions(
      SNode parentNode,
      SNode currentChild,
      SNode childConcept,
      IChildNodeSetter childSetter,
      IOperationContext context) {

    if (childConcept == null) {
      return Collections.emptyList();
    }
    final IScope scope = context.getScope();

    String childConceptFqName = NameUtil.nodeFQName(childConcept);
    Set<String> concepts = new HashSet<String>();
    for (Language l : SModelOperations.getLanguages(parentNode.getModel(), scope)) {
      concepts.addAll(
          LanguageHierarchyCache.getInstance()
              .getDefaultSubstitutableDescendantsOf(childConceptFqName, l));
    }

    List<INodeSubstituteAction> actions = new ArrayList<INodeSubstituteAction>();
    for (String fqName : concepts) {
      SNode applicableConcept = SModelUtil.findConceptDeclaration(fqName, scope);
      assert applicableConcept != null : "No concept " + fqName;
      actions.addAll(
          createDefaultActions(applicableConcept, parentNode, currentChild, childSetter, context));
    }

    return actions;
  }
示例#2
0
 private void addNewModels() {
   Set<SModelReference> modelsInProps = new HashSet<SModelReference>(getImportedModels());
   SModel smodel = myModelDescriptor;
   modelsInProps.removeAll(SModelOperations.getImportedModelUIDs(smodel));
   for (SModelReference modelReference : modelsInProps) {
     ((SModelInternal) smodel).addModelImport(modelReference, false);
   }
 }
示例#3
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;
     }
   }
 }
示例#4
0
 private void removeUnusedModels() {
   SModel smodel = myModelDescriptor;
   Set<SModelReference> modelsInModel =
       new HashSet<SModelReference>(SModelOperations.getImportedModelUIDs(smodel));
   modelsInModel.removeAll(getImportedModels());
   for (SModelReference modelReference : modelsInModel) {
     ((SModelInternal) smodel).deleteModelImport(modelReference);
   }
 }
示例#5
0
 private static void addImportIfNeed(SModel model, SModel toImport) {
   if (model == null || toImport == null) {
     return;
   }
   SModelReference ref = toImport.getReference();
   if (model == toImport || SModelOperations.getImportedModelUIDs(model).contains(ref)) {
     return;
   }
   ((SModelInternal) model).addModelImport(ref, false);
 }
示例#6
0
  public static void showCreateNewRootMenu(
      @NotNull jetbrains.mps.openapi.editor.EditorContext editorContext,
      @Nullable Setter<SNode> newRootHandler,
      @Nullable Condition<SConcept> conceptsFilter) {
    final EditorCell selectedCell = editorContext.getSelectedCell();
    int x = selectedCell.getX();
    int y = selectedCell.getY();
    if (selectedCell instanceof EditorCell_Label) {
      y += selectedCell.getHeight();
    }
    Component editorComponent = ((EditorContext) editorContext).getNodeEditorComponent();
    final DataContext dataContext = DataManager.getInstance().getDataContext(editorComponent, x, y);
    final SModel model = selectedCell.getSNode().getModel();

    if (conceptsFilter == null) {
      conceptsFilter = Condition.TRUE_CONDITION;
    }

    BaseGroup group = new BaseGroup("");
    Set<SLanguage> modelLanguages =
        new SLanguageHierarchy(SModelOperations.getAllLanguageImports(model)).getExtended();
    SLanguage[] languages = modelLanguages.toArray(new SLanguage[modelLanguages.size()]);
    Arrays.sort(languages, new ToStringComparator());
    for (SLanguage language : languages) {
      boolean hasChildren = false;
      for (SAbstractConcept ac : language.getConcepts()) {
        if (!(ac instanceof SConcept)) {
          continue;
        }
        final SConcept concept = (SConcept) ac;
        if (concept.isRootable() && conceptsFilter.met(concept)) {
          group.add(new AddNewRootAction(model, concept, newRootHandler));
          hasChildren = true;
        }
      }

      if (hasChildren) {
        group.addSeparator();
      }
    }

    ListPopup popup =
        JBPopupFactory.getInstance()
            .createActionGroupPopup(
                IdeBundle.message("title.popup.new.element"),
                group,
                dataContext,
                JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
                false);
    //    popup.showInBestPositionFor(dataContext);
    popup.show(new RelativePoint(editorComponent, new Point(x, y)));
  }
示例#7
0
 public static List<SNode> nodes(SModel model, final SAbstractConcept concept) {
   if (model == null) {
     return new ArrayList<SNode>();
   }
   if (concept != null) {
     return jetbrains.mps.smodel.SModelOperations.getNodes(model, concept);
   }
   List<SNode> result = new ArrayList<SNode>();
   for (SNode node : SNodeUtil.getDescendants(model)) {
     result.add(node);
   }
   return result;
 }
示例#8
0
 public ModelProperties(SModel modelDescriptor) {
   myModelDescriptor = modelDescriptor;
   SModel model = myModelDescriptor;
   myImportedModels.addAll(SModelOperations.getImportedModelUIDs(model));
   myUsedLanguages.addAll(((SModelInternal) model).importedLanguageIds());
   myUsedDevKits.addAll(((SModelInternal) model).importedDevkits());
   myLanguagesEngagedOnGeneration.addAll(((SModelInternal) model).engagedOnGenerationLanguages());
   myDoNotGenerate =
       myModelDescriptor instanceof GeneratableSModel
           && ((GeneratableSModel) myModelDescriptor).isDoNotGenerate();
   myGenerateIntoModelFolder =
       myModelDescriptor instanceof GeneratableSModel
           && ((GeneratableSModel) myModelDescriptor).isGenerateIntoModelFolder();
 }
示例#9
0
 private static List<SNode> allNodesIncludingImported(
     SModel sModel, boolean roots, @Nullable SAbstractConcept concept) {
   List<SModel> modelsList = new ArrayList<SModel>();
   modelsList.add(sModel);
   List<SModel> modelDescriptors = jetbrains.mps.smodel.SModelOperations.allImportedModels(sModel);
   for (SModel descriptor : modelDescriptors) {
     modelsList.add(descriptor);
   }
   List<SNode> resultNodes = new ArrayList<SNode>();
   final Condition<SNode> instanceCondition =
       (concept == null ? null : new InstanceOfCondition(concept));
   for (SModel aModel : modelsList) {
     if (concept == null || roots) {
       ConditionalIterable<SNode> nodes =
           new ConditionalIterable<SNode>(
               (roots ? aModel.getRootNodes() : SNodeUtil.getDescendants(aModel)),
               instanceCondition);
       resultNodes.addAll(IterableUtil.asList(nodes));
     } else {
       resultNodes.addAll(jetbrains.mps.smodel.SModelOperations.getNodes(aModel, concept));
     }
   }
   return resultNodes;
 }
示例#10
0
 public static Iterable sourceNodesQuery_1220369573364040170(
     final IOperationContext operationContext, final SourceSubstituteMacroNodesContext _context) {
   List<SNode> result = new ArrayList<SNode>();
   List<Language> langs =
       SModelOperations.getLanguages(
           SNodeOperations.getModel(_context.getNode()), GlobalScope.getInstance());
   for (Language lang : langs) {
     for (ModuleReference mr : lang.getRuntimeModulesReferences()) {
       for (SModelDescriptor smd :
           MPSModuleRepository.getInstance().getModule(mr).getOwnModelDescriptors()) {
         SModel rtModel = smd.getSModel();
         for (SNode gwtmod :
             jetbrains.mps.lang.smodel.generator.smodelAdapter.SModelOperations.getRoots(
                 rtModel, "jetbrains.mps.gwt.client.structure.GWTModule")) {
           ListSequence.fromList(result).addElement(gwtmod);
         }
       }
     }
   }
   return result;
 }
示例#11
0
 public void apply() {
   if (myNodesToApply.isEmpty()) {
     return;
   }
   SNode first = myNodesToApply.iterator().next();
   SModel model = first.getModel();
   if (model == null) {
     LOG.warning(
         "Checking node which is not attached to the model: "
             + first.getPresentation()
             + " "
             + first.getNodeId());
     return;
   }
   // XXX could I demand here that model has to be attached to a repository, so that I can use one
   // to obtain LanguageRegistry?
   for (SLanguage language : SModelOperations.getAllLanguageImports(model)) {
     LanguageRuntime languageRuntime = LanguageRegistry.getInstance().getLanguage(language);
     if (languageRuntime == null) {
       continue;
     }
     DataFlowAspectDescriptor aspect = languageRuntime.getAspect(DataFlowAspectDescriptor.class);
     if (aspect == null) {
       continue;
     }
     for (DataFlowConstructor rule : aspect.getConstructors(myAnalyzerId)) {
       myRules.add(rule);
     }
   }
   Set<SNode> descendants = new LinkedHashSet<SNode>();
   for (SNode myNodeToApply : myNodesToApply) {
     descendants.addAll(
         SNodeOperations.getNodeDescendants(
             myNodeToApply, null, false, new SAbstractConcept[] {}));
   }
   for (SNode descendant : descendants) {
     getRules(descendant).forEach(rule -> rule.performActions(myProgram, descendant));
   }
 }
 /*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);
     }
   }
 }
 @Nullable
 @Override
 protected Iterable<? extends SNode> getParameters(SubstituteMenuContext _context) {
   // TODO: Use link scopes here
   List<SNode> result = ListSequence.fromList(new ArrayList<SNode>());
   Set<SModel> allVisibleModels =
       SetSequence.fromSetWithValues(
           new HashSet<SModel>(),
           (List<SModel>) SModelOperations.allImportedModels(_context.getModel()));
   SetSequence.fromSet(allVisibleModels).addElement(_context.getModel());
   for (SModel nextModel : SetSequence.fromSet(allVisibleModels)) {
     ListSequence.fromList(result)
         .addSequence(
             ListSequence.fromList(
                 jetbrains.mps.lang.smodel.generator.smodelAdapter.SModelOperations.nodes(
                     nextModel,
                     MetaAdapterFactory.getConcept(
                         0x18bc659203a64e29L,
                         0xa83a7ff23bde13baL,
                         0x527faacef50d095eL,
                         "jetbrains.mps.lang.editor.structure.ConceptEditorHintDeclaration"))));
   }
   return result;
 }
示例#14
0
 private static void assertSameModelImports(SModel expectedModel, SModel actualModel) {
   assertListsEqual(
       SModelOperations.getImportedModelUIDs(expectedModel),
       SModelOperations.getImportedModelUIDs(actualModel),
       "model import");
 }
示例#15
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()*/));
    }
  }