public void execute(final SNode node, final EditorContext editorContext) {
      SNode templateNode =
          SNodeFactoryOperations.createNewRootNode(
              SNodeOperations.getModel(node),
              "jetbrains.mps.lang.generator.structure.TemplateDeclaration",
              null);
      SNode ruleNode =
          SNodeOperations.getAncestor(
              node, "jetbrains.mps.lang.generator.structure.BaseMappingRule", false, false);
      SLinkOperations.setTarget(
          templateNode,
          "applicableConcept",
          SLinkOperations.getTarget(ruleNode, "applicableConcept", false),
          false);
      SPropertyOperations.set(templateNode, "name", "template1");
      SLinkOperations.setTarget(
          templateNode, "contentNode", SLinkOperations.getTarget(node, "templateNode", true), true);
      SPropertyOperations.set(
          templateNode,
          "virtualPackage",
          SPropertyOperations.getString(SNodeOperations.getContainingRoot(node), "virtualPackage"));

      SNode templateRefNode =
          SNodeFactoryOperations.replaceWithNewChild(
              node, "jetbrains.mps.lang.generator.structure.TemplateDeclarationReference");
      SLinkOperations.setTarget(templateRefNode, "template", templateNode, false);

      SelectionUtil.selectNode(editorContext, templateNode);
    }
 public void execute(final SNode node, final EditorContext editorContext) {
   Iterable<SNode> nodes =
       ListSequence.fromList(SNodeOperations.getChildren(SNodeOperations.getParent(node)))
           .where(
               new IWhereFilter<SNode>() {
                 public boolean accept(SNode it) {
                   return SNodeOperations.isInstanceOf(
                       it, "jetbrains.mps.lang.generator.structure.NodeMacro");
                 }
               });
   boolean seen = false;
   for (SNode n : nodes) {
     if (seen) {
       if (SNodeOperations.isInstanceOf(
           n, "jetbrains.mps.lang.generator.structure.CopySrcNodeMacro")) {
         SNodeOperations.deleteNode(n);
         SNodeFactoryOperations.replaceWithNewChild(
             node, "jetbrains.mps.lang.generator.structure.CopySrcListMacro");
       }
       return;
     } else if (n == node) {
       seen = true;
     }
   }
 }
Exemplo n.º 3
0
 public void execute(SNode node) {
   SNode expr =
       SNodeOperations.cast(
           node,
           MetaAdapterFactory.getConcept(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xf8c37f506fL,
               "jetbrains.mps.baseLanguage.structure.Expression"));
   Object value =
       Expression__BehaviorDescriptor.getCompileTimeConstantValue_idi1LP2xI.invoke(
           expr, SNodeOperations.getModel(expr).getModule());
   if (value instanceof Boolean) {
     SNode v =
         SNodeFactoryOperations.replaceWithNewChild(
             expr,
             SNodeFactoryOperations.asInstanceConcept(
                 MetaAdapterFactory.getConcept(
                     0xf3061a5392264cc5L,
                     0xa443f952ceaf5816L,
                     0xf8cc56b201L,
                     "jetbrains.mps.baseLanguage.structure.BooleanConstant")));
     SPropertyOperations.set(
         v,
         MetaAdapterFactory.getProperty(
             0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b201L, 0xf8cc56b202L, "value"),
         "" + (((Boolean) value).booleanValue()));
   }
 }
 @Override
 public void execute(@NotNull String pattern) {
   SelectionUtil.selectLabelCellAnSetCaret(
       _context.getEditorContext(),
       SNodeFactoryOperations.replaceWithNewChild(
           _context.getNode(),
           SNodeFactoryOperations.asInstanceConcept(
               MetaAdapterFactory.getConcept(
                   0xf3347d8a0e794f35L,
                   0x8ac91574f25c986fL,
                   0x87f99370d7e1ea3L,
                   "jetbrains.mps.execution.commands.structure.CommandProcessType"))),
       SelectionManager.FIRST_ERROR_CELL
           + "|"
           + SelectionManager.FOCUS_POLICY_CELL
           + "|"
           + SelectionManager.FIRST_EDITABLE_CELL
           + "|"
           + SelectionManager.FIRST_CELL,
       -1);
 }
 public void execute(final SNode node, final EditorContext editorContext) {
   List<SNode> TFs =
       SNodeOperations.getDescendants(
           SLinkOperations.getTarget(
               SLinkOperations.getTarget(node, "template", false), "contentNode", true),
           "jetbrains.mps.lang.generator.structure.TemplateFragment",
           true,
           new String[] {});
   if ((int) ListSequence.fromList(TFs).count() == 0) {
     JOptionPane.showMessageDialog(null, "No fragments found");
     return;
   }
   if (ListSequence.fromList(TFs).count() > 1) {
     JOptionPane.showMessageDialog(null, "Too many fragments");
     return;
   }
   // ------
   SNode oldTemplate = SLinkOperations.getTarget(node, "template", false);
   SNode fragmentToSet =
       SNodeOperations.copyNode(SNodeOperations.getParent(ListSequence.fromList(TFs).first()));
   SNode TFtoDelete =
       AttributeOperations.getAttribute(
           fragmentToSet,
           new IAttributeDescriptor.NodeAttribute(
               SConceptOperations.findConceptDeclaration(
                   "jetbrains.mps.lang.generator.structure.TemplateFragment")));
   SNodeOperations.deleteNode(TFtoDelete);
   SNode inlineTemplate =
       SNodeFactoryOperations.replaceWithNewChild(
           node, "jetbrains.mps.lang.generator.structure.InlineTemplate_RuleConsequence");
   SLinkOperations.setTarget(inlineTemplate, "templateNode", fragmentToSet, true);
   // ------
   int option =
       JOptionPane.showConfirmDialog(
           null, "Delete old template?", "", JOptionPane.YES_NO_OPTION);
   if (option == JOptionPane.YES_OPTION) {
     SNodeOperations.deleteNode(oldTemplate);
   }
 }
Exemplo n.º 6
0
        @Override
        public void execute(@NotNull String pattern) {
          SNode method =
              SNodeOperations.cast(
                  SNodeOperations.getParent(_context.getNode()),
                  MetaAdapterFactory.getConcept(
                      0xf3061a5392264cc5L,
                      0xa443f952ceaf5816L,
                      0xf8cc56b21dL,
                      "jetbrains.mps.baseLanguage.structure.InstanceMethodDeclaration"));
          SNode staticMethod =
              SNodeFactoryOperations.replaceWithNewChild(
                  method,
                  SNodeFactoryOperations.asInstanceConcept(
                      MetaAdapterFactory.getConcept(
                          0xf3061a5392264cc5L,
                          0xa443f952ceaf5816L,
                          0xfbbebabf0aL,
                          "jetbrains.mps.baseLanguage.structure.StaticMethodDeclaration")));
          MemberDeclarationRefactoringUtil.rewireMethodReferences(method, staticMethod);

          SelectionUtil.selectLabelCellAnSetCaret(
              _context.getEditorContext(), staticMethod, "staticModifier", -1);
        }
 public void execute(final SNode node, final EditorContext editorContext) {
   SNodeFactoryOperations.replaceWithNewChild(
       node, "jetbrains.mps.lang.smodel.structure.SNodeListType");
 }
Exemplo n.º 8
0
 public static SNode parenthesiseIfNecessary(@NotNull SNode contextNode) {
   if (SNodeOperations.isInstanceOf(
       SNodeOperations.getParent(contextNode),
       MetaAdapterFactory.getConcept(
           0xf3061a5392264cc5L,
           0xa443f952ceaf5816L,
           0xfbdeb6fecfL,
           "jetbrains.mps.baseLanguage.structure.BinaryOperation"))) {
     SNode parentBinaryOperation =
         SNodeOperations.cast(
             SNodeOperations.getParent(contextNode),
             MetaAdapterFactory.getConcept(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0xfbdeb6fecfL,
                 "jetbrains.mps.baseLanguage.structure.BinaryOperation"));
     if (SNodeOperations.getContainingLinkDeclaration(contextNode)
             == SLinkOperations.findLinkDeclaration(
                 MetaAdapterFactory.getContainmentLink(
                     0xf3061a5392264cc5L,
                     0xa443f952ceaf5816L,
                     0xfbdeb6fecfL,
                     0xfbdeb7a11bL,
                     "rightExpression"))
         && isHigherPriority(parentBinaryOperation, contextNode)) {
       SNode result =
           SNodeFactoryOperations.replaceWithNewChild(
               contextNode,
               SNodeFactoryOperations.asInstanceConcept(
                   MetaAdapterFactory.getConcept(
                       0xf3061a5392264cc5L,
                       0xa443f952ceaf5816L,
                       0xfb4ed32b7fL,
                       "jetbrains.mps.baseLanguage.structure.ParenthesizedExpression")));
       SLinkOperations.setTarget(
           result,
           MetaAdapterFactory.getContainmentLink(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xfb4ed32b7fL,
               0xfb4ed32b80L,
               "expression"),
           contextNode);
       return result;
     }
   } else if (SNodeOperations.isInstanceOf(
       SNodeOperations.getParent(contextNode),
       MetaAdapterFactory.getConcept(
           0xf3061a5392264cc5L,
           0xa443f952ceaf5816L,
           0xf940dabe4aL,
           "jetbrains.mps.baseLanguage.structure.CastExpression"))) {
     SNode parentCastExpression =
         SNodeOperations.cast(
             SNodeOperations.getParent(contextNode),
             MetaAdapterFactory.getConcept(
                 0xf3061a5392264cc5L,
                 0xa443f952ceaf5816L,
                 0xf940dabe4aL,
                 "jetbrains.mps.baseLanguage.structure.CastExpression"));
     if (PrecedenceUtil.needsParensAroundCastExpression(parentCastExpression)) {
       SNode result =
           SNodeFactoryOperations.replaceWithNewChild(
               contextNode,
               SNodeFactoryOperations.asInstanceConcept(
                   MetaAdapterFactory.getConcept(
                       0xf3061a5392264cc5L,
                       0xa443f952ceaf5816L,
                       0xfb4ed32b7fL,
                       "jetbrains.mps.baseLanguage.structure.ParenthesizedExpression")));
       SLinkOperations.setTarget(
           result,
           MetaAdapterFactory.getContainmentLink(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xfb4ed32b7fL,
               0xfb4ed32b80L,
               "expression"),
           contextNode);
       return result;
     }
   }
   return contextNode;
 }