Skip to content

Commit

Permalink
[fix] Throw exception on move conflict #57
Browse files Browse the repository at this point in the history
  • Loading branch information
slarse committed Mar 18, 2020
1 parent 9484de2 commit 1092688
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/se/kth/spork/spoon/PcsInterpreter.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package se.kth.spork.spoon;

import se.kth.spork.base3dm.*;
import se.kth.spork.util.Pair;
import spoon.SpoonException;
import spoon.reflect.code.CtExpression;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtTypeReference;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -41,7 +42,6 @@ private PcsInterpreter(TStar<SpoonNode, RoledValues> delta, SpoonMapping baseLef
rootToChildren = buildRootToChildren(delta.getStar());
visitor = new Builder(delta.getContents(), baseLeft, baseRight);
this.structuralConflicts = delta.getStructuralConflicts();
// TODO what to do about root conflicts?
}

private static <T extends ListNode> Map<T, Map<T, Pcs<T>>> buildRootToChildren(Set<Pcs<T>> pcses) {
Expand Down Expand Up @@ -217,6 +217,11 @@ private Builder(Map<SpoonNode, Set<Content<SpoonNode, RoledValues>>> contents, S
* @param origRootWrapper A wrapper around the current node's parent.
*/
public void visit(SpoonNode origRootWrapper, SpoonNode origTreeWrapper) {
if (nodes.containsKey(origTreeWrapper)) {
// if this happens, then there is a duplicate node in the tree, indicating a move conflict
throw new IllegalStateException("Move conflict detected");
}

CtElement mergeParent = origRootWrapper == NodeFactory.ROOT ? null : nodes.get(origRootWrapper).getElement();

CtElement originalTree = origTreeWrapper.getElement();
Expand All @@ -235,7 +240,6 @@ public void visit(SpoonNode origRootWrapper, SpoonNode origTreeWrapper) {
mergeParent.setValueByRole(mergeTreeRole, inserted);
}

assert !nodes.containsKey(origTreeWrapper); // if this happens, then there is a duplicate node in the tree
nodes.put(origTreeWrapper, NodeFactory.wrap(mergeTree));

if (actualRoot == null)
Expand Down

0 comments on commit 1092688

Please sign in to comment.