Skip to content

Commit

Permalink
feature: CloneHelper#addClone - support of clone process customization
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Jan 1, 2018
1 parent 3c8d2ff commit 1590762
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/main/java/spoon/support/visitor/equals/CloneHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public <T extends CtElement> Collection<T> clone(Collection<T> elements) {
}
Collection<T> others = new ArrayList<>();
for (T element : elements) {
others.add(clone(element));
addClone(others, element);
}
return others;
}
Expand All @@ -69,7 +69,7 @@ public <T extends CtElement> List<T> clone(List<T> elements) {
}
List<T> others = new ArrayList<>();
for (T element : elements) {
others.add(clone(element));
addClone(others, element);
}
return others;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public <T extends CtElement> Set<T> clone(Set<T> elements) {

Set<T> others = createRightSet(elements);
for (T element : elements) {
others.add(clone(element));
addClone(others, element);
}
return others;
}
Expand All @@ -111,8 +111,27 @@ public <T extends CtElement> Map<String, T> clone(Map<String, T> elements) {
}
Map<String, T> others = new HashMap<>();
for (Map.Entry<String, T> tEntry : elements.entrySet()) {
others.put(tEntry.getKey(), clone(tEntry.getValue()));
addClone(others, tEntry.getKey(), tEntry.getValue());
}
return others;
}

/**
* clones a element and adds it's clone as value into targetCollection
* @param targetCollection - the collection which will receive a clone of element
* @param element to be cloned element
*/
protected <T extends CtElement> void addClone(Collection<T> targetCollection, T element) {
targetCollection.add(clone(element));
}

/**
* clones a value and adds it's clone as value into targetMap under key
* @param targetMap - the Map which will receive a clone of value
* @param key the target key, which has to be used to add cloned value into targetMap
* @param value to be cloned element
*/
protected <T extends CtElement> void addClone(Map<String, T> targetMap, String key, T value) {
targetMap.put(key, clone(value));
}
}

0 comments on commit 1590762

Please sign in to comment.