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

WIP: GumTree simple #534

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 2 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,10 @@
</repositories>

<dependencies>
<dependency>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-core</artifactId>
<version>10.4.1</version>
</dependency>
<dependency>
<groupId>fr.inria.gforge.spoon.labs</groupId>
<artifactId>gumtree-spoon-ast-diff</artifactId>
<version>1.46</version>
<exclusions>
<exclusion>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-core</artifactId>
</exclusion>
</exclusions>
<version>1.87</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -55,8 +44,7 @@
<version>1.10.2</version>
<scope>test</scope>
</dependency>



<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
34 changes: 16 additions & 18 deletions src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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<T, Int> {
val start = System.nanoTime()

Expand All @@ -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" }
Expand Down Expand Up @@ -210,7 +210,7 @@ object Spoon3dmMerge {
* @return A pair on the form (mergeTree, numConflicts).
*/
fun <T : CtElement> merge(base: T, left: T, right: T): Pair<T, Int> {
return merge(base, left, right, ::matchTrees, ::matchTreesXY)
return merge(base, left, right, ::matchTrees, ::matchTreesLeftRight)
}

private fun mergeMetadataElements(
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/se/kth/spork/spoon/matching/SpoonMapping.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
)
}
Expand Down Expand Up @@ -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?
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/se/kth/spork/Util.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading