diff --git a/pom.xml b/pom.xml index 51ee3eda..b08d7395 100644 --- a/pom.xml +++ b/pom.xml @@ -27,21 +27,10 @@ - - fr.inria.gforge.spoon - spoon-core - 10.4.1 - fr.inria.gforge.spoon.labs gumtree-spoon-ast-diff - 1.46 - - - fr.inria.gforge.spoon - spoon-core - - + 1.87 org.junit.jupiter @@ -55,8 +44,7 @@ 1.10.2 test - - + org.slf4j diff --git a/src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt b/src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt index 31801282..674fa5c7 100644 --- a/src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt +++ b/src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt @@ -1,8 +1,8 @@ package se.kth.spork.spoon -import com.github.gumtreediff.matchers.Matcher -import com.github.gumtreediff.matchers.Matchers -import com.github.gumtreediff.tree.ITree +import com.github.gumtreediff.matchers.CompositeMatchers +import com.github.gumtreediff.matchers.MappingStore +import com.github.gumtreediff.tree.Tree import gumtree.spoon.builder.SpoonGumTreeBuilder import se.kth.spork.base3dm.ChangeSet import se.kth.spork.base3dm.Revision @@ -39,7 +39,7 @@ import java.util.Arrays import java.util.HashSet /** - * Spoon specialization of the 3DM merge algorithm. + * Spoon specialization of the 3DM merge algorithm for Spork. * * @author Simon Larsén */ @@ -86,8 +86,8 @@ object Spoon3dmMerge { base: T, left: T, right: T, - baseMatcher: (ITree, ITree) -> Matcher, - leftRightMatcher: (ITree, ITree) -> Matcher, + baseMatcher: (Tree, Tree) -> MappingStore, + leftRightMatcher: (Tree, Tree) -> MappingStore, ): Pair { val start = System.nanoTime() @@ -101,9 +101,9 @@ object Spoon3dmMerge { val baseRightGumtreeMatch = baseMatcher(baseGumtree, rightGumtree) val leftRightGumtreeMatch = leftRightMatcher(leftGumtree, rightGumtree) LOGGER.info { "Converting GumTree matches to Spoon matches" } - val baseLeft = fromGumTreeMapping(baseLeftGumtreeMatch.mappings) - val baseRight = fromGumTreeMapping(baseRightGumtreeMatch.mappings) - val leftRight = fromGumTreeMapping(leftRightGumtreeMatch.mappings) + val baseLeft = fromGumTreeMapping(baseLeftGumtreeMatch) + val baseRight = fromGumTreeMapping(baseRightGumtreeMatch) + val leftRight = fromGumTreeMapping(leftRightGumtreeMatch) // 3DM PHASE LOGGER.info { "Mapping nodes to class representatives" } @@ -210,7 +210,7 @@ object Spoon3dmMerge { * @return A pair on the form (mergeTree, numConflicts). */ fun merge(base: T, left: T, right: T): Pair { - return merge(base, left, right, ::matchTrees, ::matchTreesXY) + return merge(base, left, right, ::matchTrees, ::matchTreesLeftRight) } private fun mergeMetadataElements( @@ -356,16 +356,14 @@ object Spoon3dmMerge { return merge.toList().sortedBy(CtImport::toString) } - private fun matchTrees(src: ITree, dst: ITree): Matcher { - val matcher = Matchers.getInstance().getMatcher(src, dst) - matcher.match() - return matcher + private fun matchTrees(src: Tree, dst: Tree): MappingStore { + val matcher = CompositeMatchers.SimpleIdGumtree() + return matcher.match(src, dst) } - private fun matchTreesXY(src: ITree, dst: ITree): Matcher { - val matcher = Matchers.getInstance().getMatcher("xy", src, dst) - matcher.match() - return matcher + private fun matchTreesLeftRight(src: Tree, dst: Tree): MappingStore { + val matcher = CompositeMatchers.SimpleIdGumtree() + return matcher.match(src, dst) } init { diff --git a/src/main/kotlin/se/kth/spork/spoon/matching/SpoonMapping.kt b/src/main/kotlin/se/kth/spork/spoon/matching/SpoonMapping.kt index 1e54a7e5..9fc56c77 100644 --- a/src/main/kotlin/se/kth/spork/spoon/matching/SpoonMapping.kt +++ b/src/main/kotlin/se/kth/spork/spoon/matching/SpoonMapping.kt @@ -1,7 +1,7 @@ package se.kth.spork.spoon.matching import com.github.gumtreediff.matchers.MappingStore -import com.github.gumtreediff.tree.ITree +import com.github.gumtreediff.tree.Tree import com.github.gumtreediff.utils.Pair import gumtree.spoon.builder.CtWrapper import gumtree.spoon.builder.SpoonGumTreeBuilder @@ -164,9 +164,9 @@ class SpoonMapping private constructor() { if (spoonSrc == null || spoonDst == null) { // at least one was non-null check(!(spoonSrc !== spoonDst)) - check(m.first.type == -1) { // -1 is the type given to root node in SpoonGumTreeBuilder + check(m.first.type.name.equals("root")) { // -1 is the type given to root node in SpoonGumTreeBuilder ( - "non-root node " + m.first.toShortString() + + "non-root node " + m.first.toString() + " had no mapped Spoon object" ) } @@ -213,7 +213,7 @@ class SpoonMapping private constructor() { return elem.parent is CtAnnotation<*> && elem.roleInParent == CtRole.VALUE } - private fun getSpoonNode(gumtreeNode: ITree): CtElement? { + private fun getSpoonNode(gumtreeNode: Tree): CtElement? { return gumtreeNode.getMetadata(SpoonGumTreeBuilder.SPOON_OBJECT) as CtElement? } } diff --git a/src/test/java/se/kth/spork/Util.java b/src/test/java/se/kth/spork/Util.java index 0ab39fec..0a1d199c 100644 --- a/src/test/java/se/kth/spork/Util.java +++ b/src/test/java/se/kth/spork/Util.java @@ -1,6 +1,6 @@ package se.kth.spork; -import com.github.gumtreediff.tree.ITree; +import com.github.gumtreediff.tree.Tree; import gumtree.spoon.builder.SpoonGumTreeBuilder; import java.io.File; import java.io.IOException; @@ -53,7 +53,7 @@ public static String read(Path path) throws IOException { return String.join("\n", Files.readAllLines(path)); } - public static ITree toGumTree(String clazz) { + public static Tree toGumTree(String clazz) { CtClass spoonTree = Launcher.parseClass(clazz); SpoonGumTreeBuilder builder = new SpoonGumTreeBuilder(); return builder.getTree(spoonTree);