Esempio n. 1
0
    public void test_removeChild() throws Exception {
      this.addNodeById("8150353254540236423");
      this.addNodeById("8150353254540236549");
      this.addNodeById("4195712261513743410");
      SNode sNode =
          SNodeOperations.cast(
              this.getNodeById("8150353254540236424"),
              "jetbrains.mps.baseLanguage.structure.BlockStatement");
      SNode child =
          SNodeOperations.cast(
              this.getNodeById("8150353254540236551"),
              "jetbrains.mps.baseLanguage.structure.LocalVariableDeclarationStatement");
      child.getParent().removeChild(child);
      sNode.addChild("", child);

      StatCountNodeReadAccessInEditorListener listener =
          new StatCountNodeReadAccessInEditorListener(sNode);
      NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener);

      sNode.removeChild(child);

      this.assertMethod(
          "public void jetbrains.mps.smodel.SNode.removeChild(org.jetbrains.mps.openapi.model.SNode)",
          listener.getResults().o1);
    }
Esempio n. 2
0
 // todo: this method can be called from inference rules - by calling behavior methods,
 // todo: in which there are no typechecking context(
 public static SNode copyIfNecessary(SNode node) {
   if (node != null
       && (node.getParent() != null || node.getModel() != null && node.getModel().isRoot(node))) {
     // this copies all the atributes, because can be used in migration scripts
     SNode copy = CopyUtil.copy(node, new THashMap<SNode, SNode>(1), true);
     return copy;
   } else {
     return node;
   }
 }
Esempio n. 3
0
  private boolean canPasteBefore(EditorCell selectedCell, List<SNode> pasteNodes) {
    if (!selectedCell.isFirstPositionInBigCell()) return false;
    SNode anchor = selectedCell.getSNode();
    if (anchor.getParent() == null) return false;

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

    EditorCell targetCell = selectedCell.getEditor().findNodeCell(nodeAndRole.myNode);
    return targetCell != null
        && targetCell.getFirstLeaf(CellConditions.SELECTABLE) == selectedCell
        && new NodePaster(pasteNodes).canPasteRelative(nodeAndRole.myNode);
  }
Esempio n. 4
0
  public static SNode copyIfNecessary(SNode node, TypeCheckingContext typeCheckingContext) {
    if (node != null
        && (node.getParent() != null || node.getModel() != null && node.getModel().isRoot(node))) {

      // this method is used only when quotations create a type
      // so it should not copy attributes, for instance generator macros of a certain type
      SNode copy = CopyUtil.copy(node, new THashMap<SNode, SNode>(1), false);

      if (typeCheckingContext != null) {
        if (isRuntimeTypeVariable(copy)) {
          typeCheckingContext.registerTypeVariable(copy);
        }
      }
      return copy;
    } else {
      return node;
    }
  }