@Override
 protected InequalitySystem getInequalitiesSystem(EditorCell contextCell) {
   HashMap<SNode, SNode> mapping = new HashMap<SNode, SNode>();
   CopyUtil.copy(Arrays.asList(mySourceNode.getContainingRoot()), mapping).get(0);
   SNode nodeToEquatePeer = mySourceNode;
   TypeChecker typeChecker = TypeChecker.getInstance();
   while (nodeToEquatePeer != null && typeChecker.getTypeOf(nodeToEquatePeer) == null) {
     nodeToEquatePeer = nodeToEquatePeer.getParent();
   }
   if (nodeToEquatePeer == null) {
     return null;
   }
   SNode nodeToEquate = mapping.get(nodeToEquatePeer);
   SNode parent = nodeToEquate.getParent();
   if (parent == null) {
     return null;
   }
   SNode hole =
       SModelUtil_new.instantiateConceptDeclaration(
           jetbrains.mps.smodel.SNodeUtil.concept_BaseConcept, null, null, true);
   SNodeUtil.replaceWithAnother(nodeToEquate, hole);
   InequalitySystem inequalitiesForHole =
       TypeChecker.getInstance().getInequalitiesForHole(hole, false);
   return inequalitiesForHole;
 }
Ejemplo n.º 2
0
 private SNode findTopMostNodeWithSingularContainment(SNode childNode) {
   while (childNode.getParent() != null
       && SNodeUtil.getLinkDeclaration_IsSingular(
           ((jetbrains.mps.smodel.SNode) childNode).getRoleLink())) {
     childNode = childNode.getParent();
   }
   return childNode;
 }
Ejemplo n.º 3
0
 private static MigrationScriptBase.SNodePlacePointer createSNodePlacePointer(SNode node) {
   if (node.getParent() != null) {
     return new MigrationScriptBase.SNodePlacePointer.ChildPointer(node);
   } else {
     return new MigrationScriptBase.SNodePlacePointer.RootPointer(node);
   }
 }
Ejemplo n.º 4
0
 @Override
 public void nodeRoleRead(SNode node, SNodeReference linkPointer, boolean unorderedRole) {
   Tuples._2<String, String> key =
       MultiTuple.<String, String>from(
           node.getParent().getConcept().getConceptId(), node.getRoleInParent());
   storeAndCheckConsistency(myNodeRolesToPointers, key, linkPointer);
   storeAndCheckConsistency(myChildLinkToUnordered, key, unorderedRole);
 }
Ejemplo n.º 5
0
 public static SNode addChild(SNode parent, String role, SNode child) {
   if (parent != null && child != null) {
     SNode childParent = child.getParent();
     if (childParent != null) {
       childParent.removeChild(child);
     }
     parent.addChild(role, child);
   }
   return child;
 }
Ejemplo n.º 6
0
 @Override
 public SNodeReference getNodeRoleId(SNode node) {
   String roleInParent = node.getRoleInParent();
   if (roleInParent == null) {
     return null;
   }
   return MapSequence.fromMap(myNodeRolesToPointers)
       .get(
           MultiTuple.<String, String>from(
               node.getParent().getConcept().getConceptId(), roleInParent));
 }
Ejemplo n.º 7
0
 @Override
 public boolean isInUnorderedRole(SNode node) {
   SNode parent = node.getParent();
   if (parent == null) {
     return false;
   }
   Boolean b =
       MapSequence.fromMap(myChildLinkToUnordered)
           .get(
               MultiTuple.<String, String>from(
                   parent.getConcept().getQualifiedName(), node.getRoleInParent()));
   return b != null && b.booleanValue();
 }
Ejemplo n.º 8
0
  private boolean canPasteBefore(EditorCell selectedCell, List<SNode> pasteNodes) {
    if (!APICellAdapter.isFirstPositionInBigCell(selectedCell)) return false;
    SNode anchor = selectedCell.getSNode();
    if (anchor.getParent() == null) return false;

    NodeAndRole nodeAndRole =
        new NodePaster(pasteNodes).getActualAnchorNode(anchor, anchor.getRoleInParent(), false);
    if (nodeAndRole == null) return false;

    EditorCell targetCell = selectedCell.getEditorComponent().findNodeCell(nodeAndRole.myNode);
    return targetCell != null
        && ((jetbrains.mps.nodeEditor.cells.EditorCell) targetCell)
                .getFirstLeaf(CellConditions.SELECTABLE)
            == selectedCell
        && new NodePaster(pasteNodes).canPasteRelative(nodeAndRole.myNode);
  }
Ejemplo n.º 9
0
    void build() {
      for (SNode cd : myLanguage.getConceptDeclarations()) {
        if (!(cd.getModel() != null && cd.getParent() == null)) continue;
        if (!SNodeUtil.isDefaultSubstitutable(cd)) {
          continue;
        }

        String fqName = NameUtil.nodeFQName(cd);

        for (String ancestor : getAncestorsNames_internal(fqName)) {
          Set<String> addTo = mySubconcepts.get(ancestor);
          if (addTo == null) {
            addTo = new HashSet<String>();
            mySubconcepts.put(ancestor, addTo);
          }
          addTo.add(fqName);
        }
      }
    }
Ejemplo n.º 10
0
  // todo rewrite using findTreeNode
  protected MPSTreeNodeEx findSNodeTreeNodeInParent(
      @NotNull final SNode node, @NotNull final SModelTreeNode parent) {
    LinkedList<SNode> ancestors = new LinkedList<SNode>();
    SNode current = node;
    while (current != null) {
      ancestors.addFirst(current);
      current = current.getParent();
    }

    MPSTreeNode currentTreeNode = parent;
    for (final SNode anc : ancestors) {
      final MPSTreeNode finalCurrentTreeNode = currentTreeNode;
      if (!currentTreeNode.isInitialized() && !currentTreeNode.hasInfiniteSubtree())
        currentTreeNode.init();

      currentTreeNode =
          findTreeNode(
              finalCurrentTreeNode,
              new Condition<MPSTreeNode>() {
                @Override
                public boolean met(MPSTreeNode object) {
                  if (object == finalCurrentTreeNode) return true;
                  if (!(object instanceof PackageNode)) return false;
                  String pack = ((PackageNode) object).getFullPackage();
                  String vp =
                      node.getContainingRoot()
                          .getProperty(SNodeUtil.property_BaseConcept_virtualPackage);
                  return vp != null && vp.startsWith(pack);
                }
              },
              new Condition<MPSTreeNode>() {
                @Override
                public boolean met(MPSTreeNode tNode) {
                  return (tNode instanceof SNodeTreeNode)
                      && (((SNodeTreeNode) tNode).getSNode() == anc);
                }
              });
      if (currentTreeNode == null) return null;
    }

    return (MPSTreeNodeEx) currentTreeNode;
  }
Ejemplo n.º 11
0
 @Override
 public EditorCell getCellForParentNodeInMainEditor(final EditorComponent editor) {
   return new ModelAccessHelper(editor.getRepository())
       .runReadAction(
           () -> {
             if (getNode() == null) {
               return null;
             }
             if (editor instanceof InspectorEditorComponent) {
               return null;
             }
             SNode parent = getNode().getParent();
             while (parent != null) {
               EditorCell result = editor.getBigValidCellForNode(parent);
               if (result != null) {
                 return result;
               }
               parent = parent.getParent();
             }
             return null;
           });
 }
Ejemplo n.º 12
0
  public static SNode setTarget(SNode node, String role, SNode targetNode, boolean child) {
    if (node != null) {
      if (child) {
        SNode oldChild = SNodeOperations.getChild(node, role);
        if (oldChild != null) {
          node.removeChild(oldChild);
        }

        if (targetNode != null) {
          SNode targetParent = targetNode.getParent();
          if (targetParent != node) {
            if (targetParent != null) {
              targetParent.removeChild(targetNode);
            }
            node.addChild(role, targetNode);
          }
        }
      } else {
        SNodeAccessUtil.setReferenceTarget(node, role, targetNode);
      }
    }
    return targetNode;
  }
Ejemplo n.º 13
0
 public static SReferenceLink getLink(SNode attribute) {
   String linkId =
       attribute.getProperty(
           MetaAdapterFactory.getProperty(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x2eb1ad060897da51L,
               0x129f3f612792fc5cL,
               "linkId"));
   String linkName =
       attribute.getProperty(
           MetaAdapterFactory.getProperty(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x2eb1ad060897da51L,
               0x18649a5c82123514L,
               "linkRole"));
   if (linkId == null) {
     return ((ConceptMetaInfoConverter) attribute.getParent().getConcept())
         .convertAssociation(linkName);
   }
   SReferenceLinkId lid = SReferenceLinkId.deserialize(linkId);
   return MetaAdapterFactory.getReferenceLink(lid, (linkName == null ? "" : linkName));
 }
Ejemplo n.º 14
0
 public static SProperty getProperty(SNode attribute) {
   String propertyId =
       attribute.getProperty(
           MetaAdapterFactory.getProperty(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x2eb1ad060897da56L,
               0x129f3f61278d556dL,
               "propertyId"));
   String propertyName =
       attribute.getProperty(
           MetaAdapterFactory.getProperty(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x2eb1ad060897da56L,
               0x18649a5c82123515L,
               "propertyName"));
   if (propertyId == null) {
     return ((ConceptMetaInfoConverter) attribute.getParent().getConcept())
         .convertProperty(propertyName);
   }
   SPropertyId pid = SPropertyId.deserialize(propertyId);
   return MetaAdapterFactory.getProperty(pid, (propertyName == null ? "" : propertyName));
 }
Ejemplo n.º 15
0
 public static SContainmentLink getChildLink(SNode attribute) {
   String linkId =
       attribute.getProperty(
           MetaAdapterFactory.getProperty(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x9d98713f247885aL,
               0x9d98713f249b587L,
               "linkId"));
   String linkName =
       attribute.getProperty(
           MetaAdapterFactory.getProperty(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x9d98713f247885aL,
               0x9d98713f249b585L,
               "linkRole"));
   if (linkId == null) {
     return ((ConceptMetaInfoConverter) attribute.getParent().getConcept())
         .convertAggregation(linkName);
   }
   SContainmentLinkId lid = SContainmentLinkId.deserialize(linkId);
   return MetaAdapterFactory.getContainmentLink(lid, (linkName == null ? "" : linkName));
 }
Ejemplo n.º 16
0
 /*package*/ ChildPointer(SNode node) {
   this.node = node;
   parent = node.getParent();
   link = node.getContainmentLink();
   nextSibling = node.getNextSibling();
 }
Ejemplo n.º 17
0
 public boolean isNodeInPlace() {
   return node.getParent() == parent;
 }
Ejemplo n.º 18
0
 public boolean isNodeInPlace() {
   return node.getParent() == null && node.getModel() == model;
 }