Example #1
0
  private void collectGroupChangesWithOthersConflicts(
      Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> arrangedChanges,
      ChangeSet thisChangeSet,
      ChangeSet otherChangeSet) {
    Map<SNodeId, DeleteRootChange> deleteRootChanges =
        MergeConflictsBuilder.<SNodeId, DeleteRootChange>arrangeChanges(
            thisChangeSet,
            new _FunctionTypes._return_P1_E0<SNodeId, DeleteRootChange>() {
              public SNodeId invoke(DeleteRootChange drc) {
                return drc.getRootId();
              }
            },
            DeleteRootChange.class);
    for (ModelChange change : ListSequence.fromList(otherChangeSet.getModelChanges())) {
      if (MapSequence.fromMap(myConflictingChanges).containsKey(change)) {
        continue;
      }

      SNodeId nodeId = null;
      if (change instanceof NodeChange) {
        nodeId = ((NodeChange) change).getAffectedNodeId();
      } else if (change instanceof NodeGroupChange) {
        nodeId = ((NodeGroupChange) change).getParentNodeId();
      }
      if (nodeId == null) {
        continue;
      }
      SNode node = myBaseModel.getNode(nodeId);
      while (node != null) {
        if (SNodeOperations.getParent(node) == null) {
          DeleteRootChange conflicting =
              MapSequence.fromMap(deleteRootChanges).get(node.getNodeId());
          if (conflicting != null) {
            addPossibleConflict(change, conflicting);
          }
        } else {
          Tuples._2<SNodeId, String> nodeRole =
              MultiTuple.<SNodeId, String>from(
                  SNodeOperations.getParent(node).getNodeId(),
                  SNodeOperations.getContainingLinkRole(node));
          final int index = SNodeOperations.getIndexInParent(node);
          NodeGroupChange conflicting =
              ListSequence.fromList(MapSequence.fromMap(arrangedChanges).get(nodeRole))
                  .findFirst(
                      new IWhereFilter<NodeGroupChange>() {
                        public boolean accept(NodeGroupChange ch) {
                          return ch.getBegin() <= index && index < ch.getEnd();
                        }
                      });
          if (conflicting != null) {
            addPossibleConflict(change, conflicting);
            break;
          }
        }
        node = SNodeOperations.getParent(node);
      }
    }
  }
  private static NodeCaretPair smartDelete_id7PYAiugbmRz(
      @NotNull SNode __thisNode__, boolean isBeginning) {
    SNode line =
        SNodeOperations.cast(
            SNodeOperations.getParent(__thisNode__),
            MetaAdapterFactory.getConcept(
                0xf280165065d5424eL,
                0xbb1b463a8781b786L,
                0x757ba20a4c87f96cL,
                "jetbrains.mps.baseLanguage.javadoc.structure.CommentLine"));
    int index = SNodeOperations.getIndexInParent(__thisNode__);
    Iterable<SNode> lines =
        SLinkOperations.getChildren(
            __thisNode__,
            MetaAdapterFactory.getContainmentLink(
                0xf280165065d5424eL,
                0xbb1b463a8781b786L,
                0x5bc4aa08e154b399L,
                0x5bc4aa08e154b39bL,
                "line"));

    SNode nodeToSelect = null;
    int caret = -1;

    if (Sequence.fromIterable(lines).isEmpty()) {
      SNode prev = SNodeOperations.getPrevSibling(__thisNode__);
      if (isNotEmptyString(
          SPropertyOperations.getString(
              SNodeOperations.cast(
                  prev,
                  MetaAdapterFactory.getConcept(
                      0xf280165065d5424eL,
                      0xbb1b463a8781b786L,
                      0x7c7f5b2f31990287L,
                      "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")),
              MetaAdapterFactory.getProperty(
                  0xf280165065d5424eL,
                  0xbb1b463a8781b786L,
                  0x7c7f5b2f31990287L,
                  0x7c7f5b2f31990288L,
                  "text")))) {
        caret =
            SPropertyOperations.getString(
                    SNodeOperations.cast(
                        prev,
                        MetaAdapterFactory.getConcept(
                            0xf280165065d5424eL,
                            0xbb1b463a8781b786L,
                            0x7c7f5b2f31990287L,
                            "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")),
                    MetaAdapterFactory.getProperty(
                        0xf280165065d5424eL,
                        0xbb1b463a8781b786L,
                        0x7c7f5b2f31990287L,
                        0x7c7f5b2f31990288L,
                        "text"))
                .length();
      }
      SNodeOperations.deleteNode(__thisNode__);
      CommentLine_BehaviorDescriptor.tryMergeToRight_idooaTF_3fF3.invoke(line, index - 1);
      return new NodeCaretPair(prev, caret);
    } else {
      //  Merging first line
      for (SNode part :
          ListSequence.fromList(
              SLinkOperations.getChildren(
                  ListSequence.fromList(
                          SLinkOperations.getChildren(
                              __thisNode__,
                              MetaAdapterFactory.getContainmentLink(
                                  0xf280165065d5424eL,
                                  0xbb1b463a8781b786L,
                                  0x5bc4aa08e154b399L,
                                  0x5bc4aa08e154b39bL,
                                  "line")))
                      .first(),
                  MetaAdapterFactory.getContainmentLink(
                      0xf280165065d5424eL,
                      0xbb1b463a8781b786L,
                      0x757ba20a4c87f96cL,
                      0x7c7f5b2f3199028dL,
                      "part")))) {
        SNodeOperations.insertPrevSiblingChild(__thisNode__, part);
      }
      SNodeOperations.deleteNode(
          ListSequence.fromList(
                  SLinkOperations.getChildren(
                      __thisNode__,
                      MetaAdapterFactory.getContainmentLink(
                          0xf280165065d5424eL,
                          0xbb1b463a8781b786L,
                          0x5bc4aa08e154b399L,
                          0x5bc4aa08e154b39bL,
                          "line")))
              .first());
      if (isBeginning) {
        nodeToSelect =
            ListSequence.fromList(
                    SLinkOperations.getChildren(
                        line,
                        MetaAdapterFactory.getContainmentLink(
                            0xf280165065d5424eL,
                            0xbb1b463a8781b786L,
                            0x757ba20a4c87f96cL,
                            0x7c7f5b2f3199028dL,
                            "part")))
                .getElement(index - 1);
        caret =
            SPropertyOperations.getString(
                    SNodeOperations.cast(
                        ListSequence.fromList(
                                SLinkOperations.getChildren(
                                    line,
                                    MetaAdapterFactory.getContainmentLink(
                                        0xf280165065d5424eL,
                                        0xbb1b463a8781b786L,
                                        0x757ba20a4c87f96cL,
                                        0x7c7f5b2f3199028dL,
                                        "part")))
                            .getElement(index - 1),
                        MetaAdapterFactory.getConcept(
                            0xf280165065d5424eL,
                            0xbb1b463a8781b786L,
                            0x7c7f5b2f31990287L,
                            "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")),
                    MetaAdapterFactory.getProperty(
                        0xf280165065d5424eL,
                        0xbb1b463a8781b786L,
                        0x7c7f5b2f31990287L,
                        0x7c7f5b2f31990288L,
                        "text"))
                .length();
      }
      CommentLine_BehaviorDescriptor.tryMergeToRight_idooaTF_3fF3.invoke(line, index - 1);

      //  Merging other lines
      SNode lastElementLine =
          ListSequence.fromList(
                  SLinkOperations.getChildren(
                      __thisNode__,
                      MetaAdapterFactory.getContainmentLink(
                          0xf280165065d5424eL,
                          0xbb1b463a8781b786L,
                          0x5bc4aa08e154b399L,
                          0x5bc4aa08e154b39bL,
                          "line")))
              .last();
      for (SNode elementLine :
          ListSequence.fromList(
                  SLinkOperations.getChildren(
                      __thisNode__,
                      MetaAdapterFactory.getContainmentLink(
                          0xf280165065d5424eL,
                          0xbb1b463a8781b786L,
                          0x5bc4aa08e154b399L,
                          0x5bc4aa08e154b39bL,
                          "line")))
              .reversedList()) {
        SNodeOperations.insertNextSiblingChild(line, elementLine);
      }

      if ((lastElementLine == null)) {
        index = SNodeOperations.getIndexInParent(__thisNode__);
        SNodeOperations.deleteNode(__thisNode__);
        if (!(isBeginning)) {
          nodeToSelect =
              ListSequence.fromList(
                      SLinkOperations.getChildren(
                          line,
                          MetaAdapterFactory.getContainmentLink(
                              0xf280165065d5424eL,
                              0xbb1b463a8781b786L,
                              0x757ba20a4c87f96cL,
                              0x7c7f5b2f3199028dL,
                              "part")))
                  .getElement(index - 1);
          caret =
              SPropertyOperations.getString(
                      SNodeOperations.cast(
                          ListSequence.fromList(
                                  SLinkOperations.getChildren(
                                      line,
                                      MetaAdapterFactory.getContainmentLink(
                                          0xf280165065d5424eL,
                                          0xbb1b463a8781b786L,
                                          0x757ba20a4c87f96cL,
                                          0x7c7f5b2f3199028dL,
                                          "part")))
                              .getElement(index - 1),
                          MetaAdapterFactory.getConcept(
                              0xf280165065d5424eL,
                              0xbb1b463a8781b786L,
                              0x7c7f5b2f31990287L,
                              "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")),
                      MetaAdapterFactory.getProperty(
                          0xf280165065d5424eL,
                          0xbb1b463a8781b786L,
                          0x7c7f5b2f31990287L,
                          0x7c7f5b2f31990288L,
                          "text"))
                  .length();
        }
        CommentLine_BehaviorDescriptor.tryMergeToRight_idooaTF_3fF3.invoke(line, index - 1);
      } else {
        //  Merging last line parts
        index =
            ListSequence.fromList(
                        SLinkOperations.getChildren(
                            lastElementLine,
                            MetaAdapterFactory.getContainmentLink(
                                0xf280165065d5424eL,
                                0xbb1b463a8781b786L,
                                0x757ba20a4c87f96cL,
                                0x7c7f5b2f3199028dL,
                                "part")))
                    .count()
                - 1;
        for (SNode linePart :
            ListSequence.fromList(SNodeOperations.getNextSiblings(__thisNode__, false))) {
          ListSequence.fromList(
                  SLinkOperations.getChildren(
                      lastElementLine,
                      MetaAdapterFactory.getContainmentLink(
                          0xf280165065d5424eL,
                          0xbb1b463a8781b786L,
                          0x757ba20a4c87f96cL,
                          0x7c7f5b2f3199028dL,
                          "part")))
              .addElement(
                  SNodeOperations.cast(
                      linePart,
                      MetaAdapterFactory.getConcept(
                          0xf280165065d5424eL,
                          0xbb1b463a8781b786L,
                          0x7c7f5b2f31990286L,
                          "jetbrains.mps.baseLanguage.javadoc.structure.CommentLinePart")));
        }
        SNodeOperations.deleteNode(__thisNode__);
        if (!(isBeginning)) {
          nodeToSelect =
              ListSequence.fromList(
                      SLinkOperations.getChildren(
                          lastElementLine,
                          MetaAdapterFactory.getContainmentLink(
                              0xf280165065d5424eL,
                              0xbb1b463a8781b786L,
                              0x757ba20a4c87f96cL,
                              0x7c7f5b2f3199028dL,
                              "part")))
                  .getElement(index);
          caret =
              SPropertyOperations.getString(
                      SNodeOperations.cast(
                          ListSequence.fromList(
                                  SLinkOperations.getChildren(
                                      lastElementLine,
                                      MetaAdapterFactory.getContainmentLink(
                                          0xf280165065d5424eL,
                                          0xbb1b463a8781b786L,
                                          0x757ba20a4c87f96cL,
                                          0x7c7f5b2f3199028dL,
                                          "part")))
                              .getElement(index),
                          MetaAdapterFactory.getConcept(
                              0xf280165065d5424eL,
                              0xbb1b463a8781b786L,
                              0x7c7f5b2f31990287L,
                              "jetbrains.mps.baseLanguage.javadoc.structure.TextCommentLinePart")),
                      MetaAdapterFactory.getProperty(
                          0xf280165065d5424eL,
                          0xbb1b463a8781b786L,
                          0x7c7f5b2f31990287L,
                          0x7c7f5b2f31990288L,
                          "text"))
                  .length();
        }
        CommentLine_BehaviorDescriptor.tryMergeToRight_idooaTF_3fF3.invoke(lastElementLine, index);
      }
    }
    return new NodeCaretPair(nodeToSelect, caret);
  }