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 postAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property) { if (property.isChildListProperty()) { ListRewriteEvent event = getListEvent(node, property); List list = (List) node.getStructuralProperty(property); int i = list.indexOf(child); int s = list.size(); int index; if (i + 1 < s) { ASTNode nextNode = (ASTNode) list.get(i + 1); index = event.getIndex(nextNode, ListRewriteEvent.NEW); } else { index = -1; } event.insert(child, index); if (child != null) { markAsMoveOrCopyTarget(node, child); } } }
void postValueChangeEvent(ASTNode node, SimplePropertyDescriptor property) { NodeRewriteEvent event = getNodeEvent(node, property); event.setNewValue(node.getStructuralProperty(property)); }