Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void match() {

for (Iterator<ITree> srcLeaves = TreeUtils.leafIterator(
TreeUtils.postOrderIterator(src)); srcLeaves.hasNext();) {
ITree srcLeaf = srcLeaves.next();
for (ITree dstLeaf: dstLeaves) {
ITree srcLeaf = srcLeaves.next();
if (isMappingAllowed(srcLeaf, dstLeaf)) {
double sim = StringMetrics.qGramsDistance().compare(srcLeaf.getLabel(), dstLeaf.getLabel());
if (sim > LABEL_SIM_THRESHOLD) leafMappings.add(new Mapping(srcLeaf, dstLeaf));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ public AbstractMappingComparator(List<Mapping> ambiguousMappings, MappingStore m
}

public int compare(Mapping m1, Mapping m2) {
return Double.compare(similarities.get(m2), similarities.get(m1));
if (similarities.get(m2).compareTo(similarities.get(m1)) != 0) {
return Double.compare(similarities.get(m2), similarities.get(m1));
}
if (m1.first.getId() != m2.first.getId()) {
return Integer.compare(m1.first.getId(), m2.first.getId());
}
return Integer.compare(m1.second.getId(), m2.second.getId());
}

protected abstract double similarity(ITree src, ITree dst);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

public abstract class AbstractSubtreeMatcher extends Matcher {

public static int MIN_HEIGHT = Integer.parseInt(System.getProperty("gt.stm.mh", "2"));
public static int MIN_HEIGHT = Integer.parseInt(System.getProperty("gt.stm.mh", "1"));

public AbstractSubtreeMatcher(ITree src, ITree dst, MappingStore store) {
super(src, dst, store);
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/com/github/gumtreediff/tree/TreeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ public ITree next() {
if (current.isLeaf())
break;
}
if (!it.hasNext()) {
current = null;
}
return val;
}

Expand Down
48 changes: 48 additions & 0 deletions core/src/test/java/com/github/gumtreediff/test/TestCdMatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of GumTree.
*
* GumTree is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GumTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
* Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
*/

package com.github.gumtreediff.test;

import com.github.gumtreediff.matchers.MappingStore;
import com.github.gumtreediff.matchers.Matcher;
import com.github.gumtreediff.matchers.heuristic.cd.ChangeDistillerLeavesMatcher;
import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.utils.Pair;
import com.github.gumtreediff.tree.TreeContext;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class TestCdMatcher {

@Test
public void testLeafMatcher() {
Pair<TreeContext, TreeContext> trees = TreeLoader.getCdCustomPair();
ITree src = trees.getFirst().getRoot();
ITree dst = trees.getSecond().getRoot();
Matcher matcher = new ChangeDistillerLeavesMatcher(src, dst, new MappingStore());
matcher.match();
assertEquals(2, matcher.getMappingSet().size());
assertTrue(matcher.getMappings().has(src.getChild(0), dst.getChild(1)));
assertTrue(matcher.getMappings().has(src.getChild(1), dst.getChild(0)));
}

}
14 changes: 14 additions & 0 deletions core/src/test/java/com/github/gumtreediff/test/TestTreeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,18 @@ public void testBfs3() {
Iterator<ITree> it = TreeUtils.breadthFirstIterator(big);
compareListIterator(lst, it);
}

@Test
public void testLeafIterator() {
ITree src = TreeLoader.getDummySrc();
Iterator<ITree> srcLeaves = TreeUtils.leafIterator(TreeUtils.postOrderIterator(src));
ITree leaf = null;
leaf = srcLeaves.next();
leaf = srcLeaves.next();
leaf = srcLeaves.next();
leaf = srcLeaves.next();
leaf = srcLeaves.next();
assertNull(leaf);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public static Pair<TreeContext, TreeContext> getDummyPair() {
return new Pair<>(load("/Dummy_v0.xml"), load("/Dummy_v1.xml"));
}

public static Pair<TreeContext, TreeContext> getCdCustomPair() {
return new Pair<>(load("/cd_v0.xml"), load("/cd_v1.xml"));
}

public static ITree getDummySrc() {
return load("/Dummy_v0.xml").getRoot();
}
Expand Down
23 changes: 23 additions & 0 deletions core/src/test/resources/cd_v0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
This file is part of GumTree.

GumTree is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

GumTree is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with GumTree. If not, see <http://www.gnu.org/licenses/>.

Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
-->
<tree type="0" label="a">
<tree type="1" label="b"/>
<tree type="2" label="c"/>
</tree>
23 changes: 23 additions & 0 deletions core/src/test/resources/cd_v1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
This file is part of GumTree.

GumTree is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

GumTree is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with GumTree. If not, see <http://www.gnu.org/licenses/>.

Copyright 2011-2015 Jean-Rémy Falleri <jr.falleri@gmail.com>
Copyright 2011-2015 Floréal Morandat <florealm@gmail.com>
-->
<tree type="0" label="a">
<tree type="2" label="c"/>
<tree type="1" label="b"/>
</tree>
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ public void endVisit(BreakStatement node) {

@Override
public boolean visit(CatchClause node) {
pushNode(node, ((SimpleType) node.getException().getType()).getName().getFullyQualifiedName());
if (node.getException().getType() instanceof SimpleType) {
pushNode(node, ((SimpleType) node.getException().getType()).getName().getFullyQualifiedName());
} else {
pushNode(node, ((UnionType) node.getException().getType()).toString());
}
// since exception type is used as value, visit children by hand
node.getBody().accept(this);
return false;
Expand Down