Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: CloneHelper#addClone - support of clone process customization #1802

Merged
merged 1 commit into from
Jan 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}