Exemplo n.º 1
0
 public static SNode getAttribute(SNode node, IAttributeDescriptor descriptor) {
   Iterable<SNode> list = getAttributes(node, descriptor);
   if (Sequence.fromIterable(list).isEmpty()) {
     return null;
   }
   if (Sequence.fromIterable(list).count() > 1) {
     if (LOG.isEnabledFor(Level.ERROR)) {
       LOG.error(
           Sequence.fromIterable(list).count()
               + " nodes match single value attribute. The first found node returned as the value.");
     }
     if (LOG.isEnabledFor(Level.ERROR)) {
       LOG.error(
           "  node="
               + node.getReference()
               + "; attribute="
               + ((String)
                   BHReflection.invoke(
                       SNodeOperations.asSConcept(
                           SNodeOperations.getConcept(Sequence.fromIterable(list).first())),
                       SMethodTrimmedId.create("getRole", null, "1653mnvAgoG")))
               + " ("
               + Sequence.fromIterable(list).first().getNodeId()
               + ")");
     }
   }
   return Sequence.fromIterable(list).first();
 }
Exemplo n.º 2
0
 public static SNode setAttribute(SNode node, IAttributeDescriptor descriptor, SNode value) {
   Iterable<SNode> oldlist = getAttributes(node, descriptor);
   if (Sequence.fromIterable(oldlist).isEmpty() && (value != null)) {
     addAttribute(node, descriptor, value);
   } else if ((value == null)) {
     deleteAttribute(node, descriptor, value);
   } else {
     if (Sequence.fromIterable(oldlist).count() > 1) {
       if (LOG.isEnabledFor(Level.ERROR)) {
         LOG.error(
             Sequence.fromIterable(oldlist).count()
                 + " nodes match signle value attribute during attribute replacing. Only the first found node replaced.");
       }
       if (LOG.isEnabledFor(Level.ERROR)) {
         LOG.error(
             "  node="
                 + node.getReference()
                 + "; attribute="
                 + ((String)
                     BHReflection.invoke(
                         SNodeOperations.asSConcept(
                             SNodeOperations.getConcept(Sequence.fromIterable(oldlist).first())),
                         SMethodTrimmedId.create("getRole", null, "1653mnvAgoG")))
                 + " ("
                 + Sequence.fromIterable(oldlist).first().getNodeId()
                 + ")");
       }
     }
     SNodeOperations.replaceWithAnother(Sequence.fromIterable(oldlist).first(), value);
     descriptor.update(value);
   }
   return value;
 }
Exemplo n.º 3
0
 public static void setBoolean(SNode node, String propertyName, boolean value) {
   if (node != null) {
     SNode conceptProperty = (SNode) findProperty(node, propertyName);
     if (SNodeOperations.isInstanceOf(
             conceptProperty, "jetbrains.mps.lang.structure.structure.BooleanConceptProperty")
         && !(value)) {
       node.removeChild(conceptProperty);
     } else if (conceptProperty == null && value) {
       for (SNode cpd : (List<SNode>) SModelSearchUtil.getConceptPropertyDeclarations(node)) {
         if (SPropertyOperations.getString(cpd, "name").equals(propertyName)) {
           if (SNodeOperations.isInstanceOf(
               cpd, "jetbrains.mps.lang.structure.structure.BooleanConceptPropertyDeclaration")) {
             SNode bcp =
                 SModelOperations.createNewNode(
                     SNodeOperations.getModel(node),
                     null,
                     "jetbrains.mps.lang.structure.structure.BooleanConceptProperty");
             SLinkOperations.setTarget(
                 bcp,
                 "conceptPropertyDeclaration",
                 SNodeOperations.cast(
                     cpd,
                     "jetbrains.mps.lang.structure.structure.BooleanConceptPropertyDeclaration"),
                 false);
             ListSequence.fromList(SLinkOperations.getTargets(node, "conceptProperty", true))
                 .addElement(bcp);
             break;
           }
         }
       }
     }
   }
 }
Exemplo n.º 4
0
 public static void setInteger(SNode node, String propertyName, int value) {
   if (node != null) {
     SNode conceptProperty = (SNode) findProperty(node, propertyName);
     if (SNodeOperations.isInstanceOf(
         conceptProperty, "jetbrains.mps.lang.structure.structure.IntegerConceptProperty")) {
       SPropertyOperations.set(
           SNodeOperations.cast(
               conceptProperty, "jetbrains.mps.lang.structure.structure.IntegerConceptProperty"),
           "value",
           "" + (value));
     }
   }
 }
Exemplo n.º 5
0
 public static int getInteger(SNode node, String propertyName) {
   if (node == null) {
     return 0;
   }
   SNode conceptProperty = (SNode) findProperty(node, propertyName);
   if (SNodeOperations.isInstanceOf(
       conceptProperty, "jetbrains.mps.lang.structure.structure.IntegerConceptProperty")) {
     return SPropertyOperations.getInteger(
         SNodeOperations.cast(
             conceptProperty, "jetbrains.mps.lang.structure.structure.IntegerConceptProperty"),
         "value");
   }
   return 0;
 }
Exemplo n.º 6
0
 public static Iterable<SNode> getPropertyAttributes(SNode node, final SProperty property) {
   return Sequence.fromIterable(
           SNodeOperations.ofConcept(
               SLinkOperations.getChildren(
                   node,
                   MetaAdapterFactory.getContainmentLink(
                       0xceab519525ea4f22L,
                       0x9b92103b95ca8c0cL,
                       0x10802efe25aL,
                       0x47bf8397520e5942L,
                       "smodelAttribute")),
               MetaAdapterFactory.getConcept(
                   0xceab519525ea4f22L,
                   0x9b92103b95ca8c0cL,
                   0x2eb1ad060897da56L,
                   "jetbrains.mps.lang.core.structure.PropertyAttribute")))
       .where(
           new IWhereFilter<SNode>() {
             public boolean accept(SNode it) {
               return eq_b2vkxw_a0a0a0a0a0a0bb(
                   ((SProperty)
                       BHReflection.invoke(
                           it,
                           SMethodTrimmedId.create(
                               "getProperty",
                               MetaAdapterFactory.getConcept(
                                   0xceab519525ea4f22L,
                                   0x9b92103b95ca8c0cL,
                                   0x2eb1ad060897da56L,
                                   "jetbrains.mps.lang.core.structure.PropertyAttribute"),
                               "1avfQ4BBzOo"))),
                   property);
             }
           });
 }
Exemplo n.º 7
0
 @Deprecated
 @ToRemove(version = 3.2)
 public static Iterable<SNode> getLinkAttributes(SNode node, final String linkRole) {
   return Sequence.fromIterable(
           SNodeOperations.ofConcept(
               SLinkOperations.getChildren(
                   node,
                   MetaAdapterFactory.getContainmentLink(
                       0xceab519525ea4f22L,
                       0x9b92103b95ca8c0cL,
                       0x10802efe25aL,
                       0x47bf8397520e5942L,
                       "smodelAttribute")),
               MetaAdapterFactory.getConcept(
                   0xceab519525ea4f22L,
                   0x9b92103b95ca8c0cL,
                   0x2eb1ad060897da51L,
                   "jetbrains.mps.lang.core.structure.LinkAttribute")))
       .where(
           new IWhereFilter<SNode>() {
             public boolean accept(SNode it) {
               return eq_b2vkxw_a0a0a0a0a0a0cb(getLink(it).getRoleName(), linkRole);
             }
           });
 }
Exemplo n.º 8
0
 public static Iterable<SNode> getChildAttributes(SNode node, final SContainmentLink link) {
   return Sequence.fromIterable(
           SNodeOperations.ofConcept(
               SLinkOperations.getChildren(
                   node,
                   MetaAdapterFactory.getContainmentLink(
                       0xceab519525ea4f22L,
                       0x9b92103b95ca8c0cL,
                       0x10802efe25aL,
                       0x47bf8397520e5942L,
                       "smodelAttribute")),
               MetaAdapterFactory.getConcept(
                   0xceab519525ea4f22L,
                   0x9b92103b95ca8c0cL,
                   0x9d98713f247885aL,
                   "jetbrains.mps.lang.core.structure.ChildAttribute")))
       .where(
           new IWhereFilter<SNode>() {
             public boolean accept(SNode it) {
               return eq_b2vkxw_a0a0a0a0a0a0eb(
                   ((SContainmentLink)
                       BHReflection.invoke(
                           it,
                           SMethodTrimmedId.create(
                               "getLink",
                               MetaAdapterFactory.getConcept(
                                   0xceab519525ea4f22L,
                                   0x9b92103b95ca8c0cL,
                                   0x9d98713f247885aL,
                                   "jetbrains.mps.lang.core.structure.ChildAttribute"),
                               "BpxLfMirzf"))),
                   link);
             }
           });
 }
Exemplo n.º 9
0
 public static boolean getBoolean(SNode node, String propertyName) {
   if (node == null) {
     return false;
   }
   SNode conceptProperty = (SNode) findProperty(node, propertyName);
   return SNodeOperations.isInstanceOf(
       conceptProperty, "jetbrains.mps.lang.structure.structure.BooleanConceptProperty");
 }
Exemplo n.º 10
0
 public static void deleteAttribute(SNode node, IAttributeDescriptor descriptor, SNode value) {
   List<SNode> list = new ArrayList<SNode>();
   ListSequence.fromList(list).addSequence(Sequence.fromIterable(getAttributes(node, descriptor)));
   for (SNode attribute : ListSequence.fromList(list)) {
     if (value == null || value == attribute) {
       SNodeOperations.deleteNode(attribute);
     }
   }
 }
Exemplo n.º 11
0
 public static boolean isLinkAttribute(SNode node) {
   return isAttribute(node)
       && SNodeOperations.isInstanceOf(
           ((SNode) node),
           MetaAdapterFactory.getConcept(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x2eb1ad060897da51L,
               "jetbrains.mps.lang.core.structure.LinkAttribute"));
 }
Exemplo n.º 12
0
 public static boolean isChildAttribute(SNode node) {
   return isAttribute(node)
       && SNodeOperations.isInstanceOf(
           ((SNode) node),
           MetaAdapterFactory.getConcept(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x9d98713f247885aL,
               "jetbrains.mps.lang.core.structure.ChildAttribute"));
 }
Exemplo n.º 13
0
 public static SNode findProperty(SNode node, String name) {
   boolean cpt =
       eq_yzaoi3_a0a0a0g(
               node.getConcept().getId(),
               "jetbrains.mps.lang.structure.structure.ConceptDeclaration")
           || eq_yzaoi3_a0a0a0g_0(
               node.getConcept().getId(),
               "jetbrains.mps.lang.structure.structure.InterfaceConceptDeclaration");
   SNode conceptNode = (cpt ? ((SNode) node) : SNodeOperations.getConceptDeclaration(node));
   return SModelSearchUtil.findConceptProperty(conceptNode, name);
 }
Exemplo n.º 14
0
 public static Iterable<SNode> getNodeAttributes(SNode node) {
   return SNodeOperations.ofConcept(
       SLinkOperations.getChildren(
           node,
           MetaAdapterFactory.getContainmentLink(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x10802efe25aL,
               0x47bf8397520e5942L,
               "smodelAttribute")),
       MetaAdapterFactory.getConcept(
           0xceab519525ea4f22L,
           0x9b92103b95ca8c0cL,
           0x2eb1ad060897da54L,
           "jetbrains.mps.lang.core.structure.NodeAttribute"));
 }
Exemplo n.º 15
0
 public AttributeList(SNode attributed, IAttributeDescriptor descriptor) {
   super(
       attributed,
       "smodelAttribute",
       (List)
           Sequence.fromIterable(
                   AttributeOperations.getAttributes(
                       SNodeOperations.cast(
                           attributed,
                           MetaAdapterFactory.getConcept(
                               0xceab519525ea4f22L,
                               0x9b92103b95ca8c0cL,
                               0x10802efe25aL,
                               "jetbrains.mps.lang.core.structure.BaseConcept")),
                       descriptor))
               .toListSequence());
   myAttributeDescriptor = descriptor;
 }
Exemplo n.º 16
0
 public static boolean hasChildAttributes(SNode node) {
   return Sequence.fromIterable(
           SNodeOperations.ofConcept(
               SLinkOperations.getChildren(
                   node,
                   MetaAdapterFactory.getContainmentLink(
                       0xceab519525ea4f22L,
                       0x9b92103b95ca8c0cL,
                       0x10802efe25aL,
                       0x47bf8397520e5942L,
                       "smodelAttribute")),
               MetaAdapterFactory.getConcept(
                   0xceab519525ea4f22L,
                   0x9b92103b95ca8c0cL,
                   0x9d98713f247885aL,
                   "jetbrains.mps.lang.core.structure.ChildAttribute")))
       .isNotEmpty();
 }
Exemplo n.º 17
0
 public static SNode insertAttribute(
     SNode node, SNode anchor, IAttributeDescriptor descriptor, SNode value) {
   // shall insert value *after* anchor
   if (anchor == null
       || !(ListSequence.fromList(
               SLinkOperations.getChildren(
                   node,
                   MetaAdapterFactory.getContainmentLink(
                       0xceab519525ea4f22L,
                       0x9b92103b95ca8c0cL,
                       0x10802efe25aL,
                       0x47bf8397520e5942L,
                       "smodelAttribute")))
           .contains(anchor))) {
     addAttribute(node, descriptor, value);
   } else {
     SNodeOperations.insertNextSiblingChild(anchor, value);
   }
   descriptor.update(value);
   return value;
 }
Exemplo n.º 18
0
 public static Iterable<SNode> getChildNodesAndAttributes(
     SNode parent, final SContainmentLink link) {
   return ListSequence.fromList(SNodeOperations.getChildren(parent))
       .where(
           new IWhereFilter<SNode>() {
             public boolean accept(SNode it) {
               return eq_b2vkxw_a0a0a0a0a0a0a13(it.getContainmentLink(), link)
                   || SNodeOperations.isInstanceOf(
                           it,
                           MetaAdapterFactory.getConcept(
                               0xceab519525ea4f22L,
                               0x9b92103b95ca8c0cL,
                               0x9d98713f247885aL,
                               "jetbrains.mps.lang.core.structure.ChildAttribute"))
                       && eq_b2vkxw_a0a0a0a0a0a0a0fb(
                           ((SContainmentLink)
                               BHReflection.invoke(
                                   SNodeOperations.cast(
                                       it,
                                       MetaAdapterFactory.getConcept(
                                           0xceab519525ea4f22L,
                                           0x9b92103b95ca8c0cL,
                                           0x9d98713f247885aL,
                                           "jetbrains.mps.lang.core.structure.ChildAttribute")),
                                   SMethodTrimmedId.create(
                                       "getLink",
                                       MetaAdapterFactory.getConcept(
                                           0xceab519525ea4f22L,
                                           0x9b92103b95ca8c0cL,
                                           0x9d98713f247885aL,
                                           "jetbrains.mps.lang.core.structure.ChildAttribute"),
                                       "BpxLfMirzf"))),
                           link);
             }
           });
 }
Exemplo n.º 19
0
 public static SNode createAndAddAttribute(
     SNode node, IAttributeDescriptor descriptor, SConcept newConceptFqname) {
   SModel model = SNodeOperations.getModel(node);
   return addAttribute(
       node, descriptor, (SNode) SModelOperations.createNewNode(model, null, newConceptFqname));
 }