private void markAsMoveOrCopyTarget(ASTNode node, ASTNode newChild) {
    if (this.cloneDepth == 0) {
      while (node != null && this.clonedNodes.containsKey(node)) {
        /*
         * A modified node cannot be considered as cloned any more.
         * we can't copy the original formatting/comments and at the same time modify the node.
         *
         * Workaround for https://bugs.eclipse.org/405699 is to remove such nodes from clonedNodes
         * and instead mark all children as cloned (or skip them if they are not in clonedNodes).
         */
        ASTNode orig = (ASTNode) this.clonedNodes.remove(node);
        if (orig != null) {
          List properties = node.structuralPropertiesForType();
          for (int i = 0; i < properties.size(); i++) {
            StructuralPropertyDescriptor property =
                (StructuralPropertyDescriptor) properties.get(i);
            Object child = node.getStructuralProperty(property);
            if (child instanceof ASTNode) {
              markAsMoveOrCopyTarget(node, (ASTNode) child);
            } else if (child instanceof List) {
              List children = (List) child;
              for (int j = 0; j < children.size(); j++) {
                ASTNode clonedChild = (ASTNode) children.get(j);
                markAsMoveOrCopyTarget(node, clonedChild);
              }
            }
          }
        }

        node = node.getParent();
      }
    }

    ASTNode source = (ASTNode) this.clonedNodes.get(newChild);
    if (source != null) {
      if (this.cloneDepth == 0) {
        PropertyLocation propertyLocation =
            this.eventStore.getPropertyLocation(source, RewriteEventStore.ORIGINAL);
        CopySourceInfo sourceInfo =
            this.eventStore.markAsCopySource(
                propertyLocation.getParent(), propertyLocation.getProperty(), source, false);
        this.nodeStore.markAsCopyTarget(newChild, sourceInfo);
      }
    } else if ((newChild.getFlags() & ASTNode.ORIGINAL) != 0) {
      PropertyLocation propertyLocation =
          this.eventStore.getPropertyLocation(newChild, RewriteEventStore.ORIGINAL);
      CopySourceInfo sourceInfo =
          this.eventStore.markAsCopySource(
              propertyLocation.getParent(), propertyLocation.getProperty(), newChild, true);
      this.nodeStore.markAsCopyTarget(newChild, sourceInfo);
    }
  }
 void postCloneNodeEvent(ASTNode node, ASTNode clone) {
   if (node.ast == this.root.ast && clone.ast == this.root.ast) {
     if ((node.getFlags() & ASTNode.ORIGINAL) != 0) {
       this.clonedNodes.put(clone, node);
     } else {
       // node can be a cloned node
       Object original = this.clonedNodes.get(node);
       if (original != null) {
         this.clonedNodes.put(clone, original);
       }
     }
   }
   this.cloneDepth--;
 }