Example #1
0
 public void execute(final SNode node, final EditorContext editorContext) {
   String name = CreateFromUsageUtil.getText(editorContext);
   if (name == null || name.length() == 0) {
     name = "default_" + SPropertyOperations.getString(node, "name");
   }
   SNode t =
       SNodeFactoryOperations.createNewRootNode(
           SNodeOperations.getModel(node),
           "jetbrains.mps.lang.generator.structure.TemplateDeclaration",
           null);
   SPropertyOperations.set(t, "name", name);
   t.setProperty(
       SModelTreeNode.PACK,
       SPropertyOperations.getString(
           SNodeOperations.cast(
               SNodeOperations.getContainingRoot(node),
               "jetbrains.mps.lang.core.structure.BaseConcept"),
           "virtualPackage"));
   // make reference
   SNode tr =
       SNodeFactoryOperations.createNewNode(
           "jetbrains.mps.lang.generator.structure.TemplateDeclarationReference", null);
   SLinkOperations.setTarget(tr, "template", t, false);
   SLinkOperations.setTarget(node, "defaultConsequence", tr, true);
 }
 public void execute(final SNode node, final EditorContext editorContext) {
   SNode applicableConcept = SLinkOperations.getTarget(node, "applicableConcept", false);
   String name = CreateFromUsageUtil.getText(editorContext);
   if (name == null || name.length() == 0) {
     name = "weave_";
     if (applicableConcept != null) {
       name += SPropertyOperations.getString(applicableConcept, "name");
     }
   }
   SNode t =
       SNodeFactoryOperations.createNewRootNode(
           SNodeOperations.getModel(node),
           "jetbrains.mps.lang.generator.structure.TemplateDeclaration",
           null);
   SPropertyOperations.set(t, "name", name);
   SLinkOperations.setTarget(t, "applicableConcept", applicableConcept, false);
   t.setProperty(
       SNodeUtil.property_BaseConcept_virtualPackage,
       SPropertyOperations.getString(
           SNodeOperations.cast(
               SNodeOperations.getContainingRoot(node),
               "jetbrains.mps.lang.core.structure.BaseConcept"),
           "virtualPackage"));
   //  initialize 'content node' in template
   SNode contextNodeType =
       TypeChecker.getInstance()
           .getTypeOf(
               SLinkOperations.getTarget(
                   SNodeOperations.cast(
                       node, "jetbrains.mps.lang.generator.structure.Weaving_MappingRule"),
                   "contextNodeQuery",
                   true));
   if (SNodeOperations.isInstanceOf(
       contextNodeType, "jetbrains.mps.lang.smodel.structure.SNodeType")) {
     SNode contextNodeConcept =
         SLinkOperations.getTarget(
             SNodeOperations.cast(
                 contextNodeType, "jetbrains.mps.lang.smodel.structure.SNodeType"),
             "concept",
             false);
     if (contextNodeConcept
         != SConceptOperations.findConceptDeclaration(
             "jetbrains.mps.lang.core.structure.BaseConcept")) {
       if (!(SNodeOperations.isInstanceOf(
           contextNodeConcept,
           "jetbrains.mps.lang.structure.structure.InterfaceConceptDeclaration"))) {
         SLinkOperations.setTarget(
             t,
             "contentNode",
             SNodeFactoryOperations.createNewNode(NameUtil.nodeFQName(contextNodeConcept), null),
             true);
       }
     }
   }
   // make reference
   SNode tr =
       SNodeFactoryOperations.setNewChild(
           node,
           "ruleConsequence",
           "jetbrains.mps.lang.generator.structure.TemplateDeclarationReference");
   SLinkOperations.setTarget(tr, "template", t, false);
 }