Skip to content

Commit

Permalink
enable consistency check
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed May 27, 2018
1 parent 597a52e commit 465aa18
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/spoon/support/util/ModelList.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ConcurrentModificationException;
import java.util.List;

import spoon.SpoonException;
import spoon.experimental.modelobs.FineModelChangeListener;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.path.CtRole;
Expand Down Expand Up @@ -89,6 +90,12 @@ public T set(int index, T element) {
}

static void linkToParent(CtElement owner, CtElement element) {
if (owner.getFactory().getEnvironment().checksAreSkipped() == false && element.isParentInitialized() && element.getParent() != owner) {
//the `e` already has an different parent. Check if it is still linked to that parent
if (element.getRoleInParent() != null) {
throw new SpoonException("The element " + element + " is already used by another part of SpoonModel. Remove it from previous model or clone it before.");
}
}
element.setParent(owner);
}

Expand Down

0 comments on commit 465aa18

Please sign in to comment.