Skip to content

Commit

Permalink
TreeMetricsProvider is now the container
Browse files Browse the repository at this point in the history
  • Loading branch information
morandat committed Apr 17, 2019
1 parent 49cdcc1 commit 02a496d
Show file tree
Hide file tree
Showing 30 changed files with 241 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void run() {
writer.write("}\n");
for (Mapping m: matcher.getMappingsAsSet()) {
writer.write(String.format("%s -> %s [style=dashed]\n;",
getDotId(getSrcTreeContext(), m.getFirst()), getDotId(getDstTreeContext(), m.getSecond())));
getDotId(getSrcTreeContext(), m.first), getDotId(getDstTreeContext(), m.second)));
}
writer.write("}\n");
System.out.println(writer.toString());
Expand All @@ -77,7 +77,7 @@ private void writeTree(TreeContext context, Writer writer, Matcher matcher) thro
}

private String getDotId(TreeContext context, ITree tree) {
return "n_" + context.hashCode() + "_" + tree.getId();
return "n_" + context.hashCode() + "_" + tree.hashCode();
}

private String getDotLabel(TreeContext context, ITree tree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void renderOn(HtmlCanvas html) throws IOException {
for (Pair<File, File> file : files) {
tbody
.tr()
.td(class_("col-md-10")).content(comparator.getSrc().relativize(file.getFirst().toPath()).toString())
.td(class_("col-md-10")).content(comparator.getSrc().relativize(file.first.toPath()).toString())
.td(class_("col-md-2"))
.a(class_("btn btn-primary btn-xs").href("/diff/" + id)).content("diff")
.write(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.TreeContext;
import gnu.trove.map.TIntIntMap;
import gnu.trove.map.TObjectIntMap;
import gnu.trove.map.hash.TIntIntHashMap;
import gnu.trove.map.hash.TObjectIntHashMap;

import java.io.*;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -71,21 +73,21 @@ public HtmlDiffs(File fSrc, File fDst, TreeContext src, TreeContext dst, Matcher

public void produce() throws IOException {
TreeClassifier c = new OnlyRootsClassifier(src, dst, matcher);
TIntIntMap mappingIds = new TIntIntHashMap();
TObjectIntMap mappingIds = new TObjectIntHashMap();

int uId = 1;
int mId = 1;

TagIndex ltags = new TagIndex();
for (ITree t: src.getRoot().getTrees()) {
if (c.getSrcMvTrees().contains(t)) {
mappingIds.put(mappings.getDstForSrc(t).getId(), mId);
mappingIds.put(mappings.getDstForSrc(t), mId);
ltags.addStartTag(t.getPos(), String.format(ID_SPAN, uId++));
ltags.addTags(t.getPos(), String.format(
SRC_MV_SPAN, "token mv", mId++, tooltip(src, t)), t.getEndPos(), END_SPAN);
}
if (c.getSrcUpdTrees().contains(t)) {
mappingIds.put(mappings.getDstForSrc(t).getId(), mId);
mappingIds.put(mappings.getDstForSrc(t), mId);
ltags.addStartTag(t.getPos(), String.format(ID_SPAN, uId++));
ltags.addTags(t.getPos(), String.format(
SRC_MV_SPAN, "token upd", mId++, tooltip(src, t)), t.getEndPos(), END_SPAN);
Expand All @@ -104,13 +106,13 @@ public void produce() throws IOException {
TagIndex rtags = new TagIndex();
for (ITree t: dst.getRoot().getTrees()) {
if (c.getDstMvTrees().contains(t)) {
int dId = mappingIds.get(t.getId());
int dId = mappingIds.get(t);
rtags.addStartTag(t.getPos(), String.format(ID_SPAN, uId++));
rtags.addTags(t.getPos(), String.format(
DST_MV_SPAN, "token mv", dId, tooltip(dst, t)), t.getEndPos(), END_SPAN);
}
if (c.getDstUpdTrees().contains(t)) {
int dId = mappingIds.get(t.getId());
int dId = mappingIds.get(t);
rtags.addStartTag(t.getPos(), String.format(ID_SPAN, uId++));
rtags.addTags(t.getPos(), String.format(
DST_MV_SPAN, "token upd", dId, tooltip(dst, t)), t.getEndPos(), END_SPAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public void configureSpark(final DirectoryComparator comparator, int port) {
get("/diff/:id", (request, response) -> {
int id = Integer.parseInt(request.params(":id"));
Pair<File, File> pair = comparator.getModifiedFiles().get(id);
Renderable view = new DiffView(pair.getFirst(), pair.getSecond(),
this.getTreeContext(pair.getFirst().getAbsolutePath()),
this.getTreeContext(pair.getSecond().getAbsolutePath()));
Renderable view = new DiffView(pair.first, pair.second,
this.getTreeContext(pair.first.getAbsolutePath()),
this.getTreeContext(pair.second.getAbsolutePath()));
return render(view);
});
get("/mergely/:id", (request, response) -> {
Expand All @@ -116,17 +116,17 @@ public void configureSpark(final DirectoryComparator comparator, int port) {
get("/left/:id", (request, response) -> {
int id = Integer.parseInt(request.params(":id"));
Pair<File, File> pair = comparator.getModifiedFiles().get(id);
return readFile(pair.getFirst().getAbsolutePath(), Charset.defaultCharset());
return readFile(pair.first.getAbsolutePath(), Charset.defaultCharset());
});
get("/right/:id", (request, response) -> {
int id = Integer.parseInt(request.params(":id"));
Pair<File, File> pair = comparator.getModifiedFiles().get(id);
return readFile(pair.getSecond().getAbsolutePath(), Charset.defaultCharset());
return readFile(pair.second.getAbsolutePath(), Charset.defaultCharset());
});
get("/script/:id", (request, response) -> {
int id = Integer.parseInt(request.params(":id"));
Pair<File, File> pair = comparator.getModifiedFiles().get(id);
Renderable view = new ScriptView(pair.getFirst(), pair.getSecond());
Renderable view = new ScriptView(pair.first, pair.second);
return render(view);
});
get("/quit", (request, response) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.MetricProviderFactory;
import com.github.gumtreediff.tree.TreeMetricsProviderFactory;
import com.github.gumtreediff.tree.TreeMetricsProvider;
import org.atteo.classindex.IndexSubclasses;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;

Expand All @@ -41,9 +40,9 @@ public abstract class Matcher {

protected final MappingStore mappings;

protected final TreeMetricsProviderFactory.TreeMetricsProvider srcMetrics;
protected final TreeMetricsProvider srcMetrics;

protected final TreeMetricsProviderFactory.TreeMetricsProvider dstMetrics;
protected final TreeMetricsProvider dstMetrics;

public Matcher(ITree src, ITree dst, MappingStore mappings) {
this.src = src;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.github.gumtreediff.matchers.Mapping;
import com.github.gumtreediff.matchers.MappingStore;
import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.TreeMetricsProviderFactory;
import com.github.gumtreediff.tree.TreeMetricsProvider;

import java.util.Comparator;
import java.util.HashMap;
Expand All @@ -31,9 +31,9 @@

public abstract class AbstractMappingComparator implements Comparator<Mapping> {

protected TreeMetricsProviderFactory.TreeMetricsProvider srcMetrics;
protected TreeMetricsProvider srcMetrics;

protected TreeMetricsProviderFactory.TreeMetricsProvider dstMetrics;
protected TreeMetricsProvider dstMetrics;

protected List<Mapping> ambiguousMappings;

Expand All @@ -44,8 +44,8 @@ public abstract class AbstractMappingComparator implements Comparator<Mapping> {
protected MappingStore mappings;

public AbstractMappingComparator(List<Mapping> ambiguousMappings, MappingStore mappings,
TreeMetricsProviderFactory.TreeMetricsProvider srcMetrics,
TreeMetricsProviderFactory.TreeMetricsProvider dstMetrics, int maxTreeSize) {
TreeMetricsProvider srcMetrics,
TreeMetricsProvider dstMetrics, int maxTreeSize) {
this.maxTreeSize = maxTreeSize;
this.mappings = mappings;
this.ambiguousMappings = ambiguousMappings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.github.gumtreediff.matchers.MappingStore;
import com.github.gumtreediff.matchers.MultiMappingStore;
import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.TreeMetricsProviderFactory;
import com.github.gumtreediff.tree.TreeMetricsProvider;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -123,14 +123,14 @@ private static class PriorityTreeList {

private List<ITree>[] trees;

private TreeMetricsProviderFactory.TreeMetricsProvider treeMetrics;
private TreeMetricsProvider treeMetrics;

private int maxHeight;

private int currentIdx;

@SuppressWarnings("unchecked")
public PriorityTreeList(ITree tree, TreeMetricsProviderFactory.TreeMetricsProvider treeMetrics) {
public PriorityTreeList(ITree tree, TreeMetricsProvider treeMetrics) {
this.treeMetrics = treeMetrics;
int listSize = treeMetrics.get(tree).height - MIN_HEIGHT + 1;
if (listSize < 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
import com.github.gumtreediff.matchers.Mapping;
import com.github.gumtreediff.matchers.MappingStore;
import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.TreeMetricsProviderFactory;
import com.github.gumtreediff.tree.TreeMetricsProvider;
import com.github.gumtreediff.utils.StringAlgorithms;

import java.util.*;

public final class ParentsMappingComparator extends AbstractMappingComparator {

public ParentsMappingComparator(List<Mapping> ambiguousMappings, MappingStore mappings,
TreeMetricsProviderFactory.TreeMetricsProvider srcMetrics,
TreeMetricsProviderFactory.TreeMetricsProvider dstMetrics, int maxTreeSize) {
TreeMetricsProvider srcMetrics,
TreeMetricsProvider dstMetrics, int maxTreeSize) {
super(ambiguousMappings, mappings, srcMetrics, dstMetrics, maxTreeSize);
for (Mapping ambiguousMapping: ambiguousMappings)
similarities.put(ambiguousMapping, similarity(ambiguousMapping.first, ambiguousMapping.second));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.github.gumtreediff.matchers.Mapping;
import com.github.gumtreediff.matchers.MappingStore;
import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.TreeMetricsProviderFactory;
import com.github.gumtreediff.tree.TreeMetricsProvider;

import java.util.*;

Expand All @@ -33,8 +33,8 @@ public final class SiblingsMappingComparator extends AbstractMappingComparator {
private Map<ITree, Set<ITree>> dstDescendants = new HashMap<>();

public SiblingsMappingComparator(List<Mapping> ambiguousMappings, MappingStore mappings,
TreeMetricsProviderFactory.TreeMetricsProvider srcMetrics,
TreeMetricsProviderFactory.TreeMetricsProvider dstMetrics, int maxTreeSize) {
TreeMetricsProvider srcMetrics,
TreeMetricsProvider dstMetrics, int maxTreeSize) {
super(ambiguousMappings, mappings, srcMetrics, dstMetrics, maxTreeSize);
for (Mapping ambiguousMapping: ambiguousMappings)
similarities.put(ambiguousMapping, similarity(ambiguousMapping.first, ambiguousMapping.second));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.github.gumtreediff.matchers.optimal.rted;

import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.TreeMetricsProviderFactory;
import com.github.gumtreediff.tree.TreeMetricsProvider;

import java.util.*;

Expand All @@ -29,7 +29,7 @@
@SuppressWarnings({"rawtypes", "unchecked"})
public class InfoTree {
private ITree inputTree;
private TreeMetricsProviderFactory.TreeMetricsProvider treeMetrics;
private TreeMetricsProvider treeMetrics;

private static final byte LEFT = 0;
private static final byte RIGHT = 1;
Expand Down Expand Up @@ -97,7 +97,7 @@ public static void main(String[] args) {
* @param aInputTree an LblTree object
* @param aLd a LabelDictionary object
*/
public InfoTree(ITree aInputTree, TreeMetricsProviderFactory.TreeMetricsProvider treeMetrics, LabelDictionary aLd) {
public InfoTree(ITree aInputTree, TreeMetricsProvider treeMetrics, LabelDictionary aLd) {
this.inputTree = aInputTree;
this.treeMetrics = treeMetrics;
treeSize = treeMetrics.get(inputTree).size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.*;

import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.TreeMetricsProviderFactory;
import com.github.gumtreediff.tree.TreeMetricsProvider;


/**
Expand Down Expand Up @@ -119,7 +119,7 @@ public double nonNormalizedTreeDist() {
return computeDistUsingStrArray(it1, it2);
}

public void init(ITree src, TreeMetricsProviderFactory.TreeMetricsProvider srcMetrics, ITree dst, TreeMetricsProviderFactory.TreeMetricsProvider dstMetrics) {
public void init(ITree src, TreeMetricsProvider srcMetrics, ITree dst, TreeMetricsProvider dstMetrics) {
ld = new LabelDictionary();
it1 = new InfoTree(src, srcMetrics, ld);
it2 = new InfoTree(dst, dstMetrics, ld);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.github.gumtreediff.matchers.MappingStore;
import com.github.gumtreediff.matchers.Matcher;
import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.TreeMetricsProviderFactory;
import com.github.gumtreediff.tree.TreeMetricsProvider;
import org.simmetrics.StringMetrics;

import java.util.*;
Expand Down Expand Up @@ -189,7 +189,7 @@ private static final class ZsTree {

private int[] kr;

private ZsTree(ITree t, TreeMetricsProviderFactory.TreeMetricsProvider treeMetrics) {
private ZsTree(ITree t, TreeMetricsProvider treeMetrics) {
this.start = 0;
this.nodeCount = treeMetrics.get(t).size;
this.leafCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
package com.github.gumtreediff.tree;

public interface MetricProviderFactory<M> {
static TreeMetricsProviderFactory.TreeMetricsProvider computeTreeMetrics(ITree tree) {
return new TreeMetricsProviderFactory().computeMetric(tree);
static TreeMetricsProvider computeTreeMetrics(ITree tree) {
return new TreeMetricsProvider.Factory().computeMetric(tree);
}

MetricProvider<M> computeMetric(ITree tree);
Expand Down
Loading

0 comments on commit 02a496d

Please sign in to comment.