Ejemplo n.º 1
0
 private static void assertPropertyEquals(SNode expectedNode, SNode actualNode) {
   HashSet<String> propertes = new HashSet<String>();
   propertes.addAll(IterableUtil.asCollection(expectedNode.getPropertyNames()));
   propertes.addAll(IterableUtil.asCollection(actualNode.getPropertyNames()));
   for (String key : propertes) {
     String expectedProperty =
         jetbrains.mps.util.SNodeOperations.getProperties(expectedNode).get(key);
     String actualProperty = jetbrains.mps.util.SNodeOperations.getProperties(actualNode).get(key);
     assertEquals(
         getErrorString("property", expectedNode, actualNode), expectedProperty, actualProperty);
   }
 }
Ejemplo n.º 2
0
  private static void assertReferenceEquals(SNode expectedNode, SNode actualNode) {
    Set<String> roles = new HashSet<String>();
    roles.addAll(jetbrains.mps.util.SNodeOperations.getReferenceRoles(expectedNode));
    roles.addAll(jetbrains.mps.util.SNodeOperations.getReferenceRoles(actualNode));
    Map<String, Set<SReference>> expRoleToReferenceMap = createRoleToReferenceMap(expectedNode);
    Map<String, Set<SReference>> actRoleToReferenceMap = createRoleToReferenceMap(actualNode);

    for (String role : roles) {
      Assert.assertEquals(
          getErrorString("different number of referents in role " + role, expectedNode, actualNode),
          expRoleToReferenceMap.get(role).size(),
          actRoleToReferenceMap.get(role).size());

      SReference expectedReference = expectedNode.getReference(role);
      SReference actualReference = actualNode.getReference(role);

      assertReferenceEquals(
          getErrorString("reference in role " + role, expectedNode, actualNode),
          expectedReference,
          actualReference);
    }
  }
Ejemplo n.º 3
0
    @Override
    public boolean met(MPSTreeNode node) {
      if (node instanceof SNodeTreeNode) return false;
      if (node instanceof SModelTreeNode) {
        SModelTreeNode modelNode = (SModelTreeNode) node;
        if (!modelNode.hasModelsUnder()) return false;

        String outerName = SNodeOperations.getModelLongName(modelNode.getSModelDescriptor());
        String innerName = jetbrains.mps.util.SNodeOperations.getModelLongName(myModel);
        return innerName.startsWith(outerName + ".");
      }
      if (!node.isInitialized() && !node.hasInfiniteSubtree()) {
        node.init();
        return true;
      }
      return node.isInitialized();
    }
Ejemplo n.º 4
0
  public boolean canExecute(EditorContext context) {
    EditorCell selectedCell = getCellToPasteTo((EditorCell) context.getSelectedCell());
    if (selectedCell == null) {
      return false;
    }
    SNode selectedNode = selectedCell.getSNode();
    if (selectedNode == null || jetbrains.mps.util.SNodeOperations.isDisposed(selectedNode)) {
      return false;
    }
    List<SNode> pasteNodes = CopyPasteUtil.getNodesFromClipboard(selectedNode.getModel());
    if (pasteNodes == null || pasteNodes.isEmpty()) {
      return CopyPasteUtil.isConversionAvailable(selectedNode.getModel(), selectedNode);
    }

    if (!new NodePaster(pasteNodes).canPaste(selectedCell)) {
      LOG.debug("Couldn't paste node here");
      return false;
    }
    return true;
  }