diff --git a/benchmark/src/main/java/com/github/gumtree/dist/BenchmarkCollector.java b/benchmark/src/main/java/com/github/gumtree/dist/BenchmarkCollector.java index d3ca199ba..bd554e5f9 100644 --- a/benchmark/src/main/java/com/github/gumtree/dist/BenchmarkCollector.java +++ b/benchmark/src/main/java/com/github/gumtree/dist/BenchmarkCollector.java @@ -20,7 +20,7 @@ package com.github.gumtree.dist; import com.github.gumtreediff.client.Run; -import com.github.gumtreediff.gen.Generators; +import com.github.gumtreediff.gen.TreeGenerators; import com.github.gumtreediff.io.TreeIoUtils; import com.github.gumtreediff.tree.TreeContext; @@ -68,7 +68,7 @@ public static void collectTrees(String dir) throws Exception { private static TreeContext getTreeContext(String file) { try { - TreeContext t = Generators.getInstance().getTree(file); + TreeContext t = TreeGenerators.getInstance().getTree(file); return t; } catch (IOException e) { e.printStackTrace(); diff --git a/client.diff/src/main/java/com/github/gumtreediff/client/diff/AbstractDiffClient.java b/client.diff/src/main/java/com/github/gumtreediff/client/diff/AbstractDiffClient.java index 53285559b..b84dd5a7e 100644 --- a/client.diff/src/main/java/com/github/gumtreediff/client/diff/AbstractDiffClient.java +++ b/client.diff/src/main/java/com/github/gumtreediff/client/diff/AbstractDiffClient.java @@ -20,16 +20,10 @@ package com.github.gumtreediff.client.diff; -import com.github.gumtreediff.actions.ChawatheScriptGenerator; import com.github.gumtreediff.actions.Diff; -import com.github.gumtreediff.actions.EditScript; import com.github.gumtreediff.client.Option; import com.github.gumtreediff.client.Client; -import com.github.gumtreediff.gen.Generators; -import com.github.gumtreediff.matchers.MappingStore; -import com.github.gumtreediff.matchers.Matcher; -import com.github.gumtreediff.matchers.Matchers; -import com.github.gumtreediff.tree.TreeContext; +import com.github.gumtreediff.gen.TreeGenerators; import java.io.IOException; import java.io.PrintStream; @@ -94,7 +88,7 @@ public AbstractDiffClient(String[] args) { opts.dump(System.out); } - if (opts.treeGenerator != null && Generators.getInstance().find(opts.treeGenerator) == null) + if (opts.treeGenerator != null && TreeGenerators.getInstance().find(opts.treeGenerator) == null) throw new Option.OptionException("Error loading tree generator: " + opts.treeGenerator); if (!Files.exists(Paths.get(opts.src))) @@ -109,26 +103,6 @@ protected Diff getDiff() throws IOException { } protected Diff getDiff(String src, String dst) throws IOException { - TreeContext srcCtx = getTreeContext(src); - TreeContext dstCtx = getTreeContext(dst); - MappingStore mappings = getMatcher().match(srcCtx.getRoot(), dstCtx.getRoot()); - EditScript editScript = new ChawatheScriptGenerator().computeActions(mappings); - return new Diff(srcCtx, dstCtx, mappings, editScript); - } - - protected Matcher getMatcher() { - return Matchers.getInstance().getMatcherWithFallback(opts.matcher); - } - - protected TreeContext getSrcTreeContext() throws IOException { - return getTreeContext(opts.src); - } - - protected TreeContext getDstTreeContext() throws IOException { - return getTreeContext(opts.dst); - } - - protected TreeContext getTreeContext(String file) throws IOException { - return Generators.getInstance().getTree(file, opts.treeGenerator); + return Diff.compute(src, dst, opts.treeGenerator, opts.matcher); } } diff --git a/client.diff/src/main/java/com/github/gumtreediff/client/diff/ClusterDiff.java b/client.diff/src/main/java/com/github/gumtreediff/client/diff/ClusterDiff.java index dc061950f..cc76bf366 100644 --- a/client.diff/src/main/java/com/github/gumtreediff/client/diff/ClusterDiff.java +++ b/client.diff/src/main/java/com/github/gumtreediff/client/diff/ClusterDiff.java @@ -20,13 +20,9 @@ package com.github.gumtreediff.client.diff; import com.github.gumtreediff.actions.ActionClusterFinder; -import com.github.gumtreediff.actions.ChawatheScriptGenerator; import com.github.gumtreediff.actions.Diff; -import com.github.gumtreediff.actions.EditScript; import com.github.gumtreediff.actions.model.Action; import com.github.gumtreediff.client.Register; -import com.github.gumtreediff.matchers.MappingStore; -import org.eclipse.jetty.util.IO; import java.io.IOException; import java.util.Set; @@ -42,7 +38,7 @@ public ClusterDiff(String[] args) { @Override public void run() throws IOException { Diff diff = getDiff(); - ActionClusterFinder f = new ActionClusterFinder(diff.src, diff.dst, diff.editScript); + ActionClusterFinder f = new ActionClusterFinder(diff.editScript); for (Set cluster: f.getClusters()) { System.out.println("New cluster:"); System.out.println(f.getClusterLabel(cluster)); diff --git a/client.diff/src/main/java/com/github/gumtreediff/client/diff/dot/DotDiff.java b/client.diff/src/main/java/com/github/gumtreediff/client/diff/dot/DotDiff.java index e5d3ac885..e9ab7784b 100644 --- a/client.diff/src/main/java/com/github/gumtreediff/client/diff/dot/DotDiff.java +++ b/client.diff/src/main/java/com/github/gumtreediff/client/diff/dot/DotDiff.java @@ -52,7 +52,7 @@ public void run() throws Exception { writer.write("}\n"); for (Mapping m: diff.mappings) { writer.write(String.format("%s -> %s [style=dashed]\n;", - getDotId(getSrcTreeContext(), m.first), getDotId(getDstTreeContext(), m.second))); + getDotId(diff.src, m.first), getDotId(diff.dst, m.second))); } writer.write("}\n"); System.out.println(writer.toString()); diff --git a/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java b/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java index ed2182948..45aa4ae34 100644 --- a/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java +++ b/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/MappingsPanel.java @@ -45,7 +45,6 @@ import com.github.gumtreediff.actions.Diff; import com.github.gumtreediff.actions.ITreeClassifier; import com.github.gumtreediff.matchers.MappingStore; -import com.github.gumtreediff.actions.AllNodesClassifier; import com.github.gumtreediff.tree.ITree; import com.github.gumtreediff.tree.TreeContext; @@ -66,7 +65,6 @@ public class MappingsPanel extends JPanel implements TreeSelectionListener { private static final Color DEL_COLOR = new Color(190, 0, 0); private static final Color ADD_COLOR = new Color(0, 158, 0); private static final Color UPD_COLOR = new Color(189, 162, 0); - //private static final Color MIS_COLOR = new Color(0, 0, 128); private static final Color MV_COLOR = new Color(128, 0, 128); public MappingsPanel(String srcPath, String dstPath, Diff diff) { @@ -143,11 +141,11 @@ public void valueChanged(TreeSelectionEvent e) { JTree jtree = (JTree) e.getSource(); if (jtree.getSelectionPath() == null) return; ITree sel = (ITree) ((DefaultMutableTreeNode) jtree.getLastSelectedPathComponent()).getUserObject(); - JTextArea selJTextArea = null; + JTextArea selJTextArea; boolean isMapped = false; ITree match = null; - TreePanel matchTreePanel = null; - JTextArea matchJTextArea = null; + TreePanel matchTreePanel; + JTextArea matchJTextArea; if (jtree == panSrc.getJTree()) { selJTextArea = txtSrc; diff --git a/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/SwingTree.java b/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/SwingTree.java index 6ba558cf5..167feaf43 100644 --- a/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/SwingTree.java +++ b/client.diff/src/main/java/com/github/gumtreediff/client/diff/swing/SwingTree.java @@ -20,7 +20,7 @@ package com.github.gumtreediff.client.diff.swing; -import com.github.gumtreediff.gen.Generators; +import com.github.gumtreediff.gen.TreeGenerators; import com.github.gumtreediff.tree.TreeContext; import javax.swing.*; @@ -29,7 +29,7 @@ public final class SwingTree { public static void main(String[] args) throws IOException { - final TreeContext t = Generators.getInstance().getTree(args[0]); + final TreeContext t = TreeGenerators.getInstance().getTree(args[0]); javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { diff --git a/client.diff/src/main/java/com/github/gumtreediff/client/diff/web/DirectoryDiffView.java b/client.diff/src/main/java/com/github/gumtreediff/client/diff/web/DirectoryDiffView.java index 4b3939a19..cb5de4f21 100644 --- a/client.diff/src/main/java/com/github/gumtreediff/client/diff/web/DirectoryDiffView.java +++ b/client.diff/src/main/java/com/github/gumtreediff/client/diff/web/DirectoryDiffView.java @@ -20,7 +20,7 @@ package com.github.gumtreediff.client.diff.web; -import com.github.gumtreediff.gen.Generators; +import com.github.gumtreediff.gen.TreeGenerators; import com.github.gumtreediff.utils.Pair; import com.github.gumtreediff.io.DirectoryComparator; import org.rendersnake.DocType; @@ -119,7 +119,7 @@ public void renderOn(HtmlCanvas html) throws IOException { .div(class_("btn-toolbar justify-content-end")) .div(class_("btn-group")) //TODO: integrate this with the -g option - .if_(Generators.getInstance().hasGeneratorForFile(file.first.getAbsolutePath())) + .if_(TreeGenerators.getInstance().hasGeneratorForFile(file.first.getAbsolutePath())) .a(class_("btn btn-primary btn-sm").href("/monaco-diff/" + id)).content("monaco") .a(class_("btn btn-primary btn-sm").href("/vanilla-diff/" + id)).content("classic") ._if() diff --git a/client/src/main/java/com/github/gumtreediff/client/List.java b/client/src/main/java/com/github/gumtreediff/client/List.java index fd9d69f09..304896a41 100644 --- a/client/src/main/java/com/github/gumtreediff/client/List.java +++ b/client/src/main/java/com/github/gumtreediff/client/List.java @@ -20,7 +20,7 @@ package com.github.gumtreediff.client; -import com.github.gumtreediff.gen.Generators; +import com.github.gumtreediff.gen.TreeGenerators; import com.github.gumtreediff.matchers.Matchers; import java.io.IOException; @@ -63,7 +63,7 @@ Collection list() { GENERATORS { @Override Collection list() { - return Generators.getInstance().getEntries(); + return TreeGenerators.getInstance().getEntries(); } }, PROPERTIES { diff --git a/client/src/main/java/com/github/gumtreediff/client/Run.java b/client/src/main/java/com/github/gumtreediff/client/Run.java index 2af23a4eb..8b66f863c 100644 --- a/client/src/main/java/com/github/gumtreediff/client/Run.java +++ b/client/src/main/java/com/github/gumtreediff/client/Run.java @@ -20,7 +20,7 @@ package com.github.gumtreediff.client; -import com.github.gumtreediff.gen.Generators; +import com.github.gumtreediff.gen.TreeGenerators; import com.github.gumtreediff.gen.Registry; import com.github.gumtreediff.gen.TreeGenerator; import org.atteo.classindex.ClassIndex; @@ -55,7 +55,7 @@ public static void initGenerators() { com.github.gumtreediff.gen.Register a = gen.getAnnotation(com.github.gumtreediff.gen.Register.class); if (a != null) - Generators.getInstance().install(gen, a); + TreeGenerators.getInstance().install(gen, a); }); } diff --git a/client/src/main/java/com/github/gumtreediff/client/Serializer.java b/client/src/main/java/com/github/gumtreediff/client/Serializer.java index 057c25b96..a2f2971d0 100644 --- a/client/src/main/java/com/github/gumtreediff/client/Serializer.java +++ b/client/src/main/java/com/github/gumtreediff/client/Serializer.java @@ -21,18 +21,14 @@ package com.github.gumtreediff.client; import com.github.gumtreediff.io.TreeIoUtils; -import com.github.gumtreediff.gen.Generators; -import com.github.gumtreediff.io.TreeIoUtils; -import com.github.gumtreediff.io.TreeIoUtils.TreeSerializer; +import com.github.gumtreediff.gen.TreeGenerators; import com.github.gumtreediff.tree.TreeContext; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; @Register(name = "parse", description = "Parse file and dump result") public class Serializer extends Client { @@ -141,6 +137,6 @@ public void run() throws Exception { } private TreeContext getTreeContext(String file) throws IOException { - return Generators.getInstance().getTree(file, opts.generator); + return TreeGenerators.getInstance().getTree(file, opts.generator); } } \ No newline at end of file diff --git a/core/src/main/java/com/github/gumtreediff/actions/ActionClusterFinder.java b/core/src/main/java/com/github/gumtreediff/actions/ActionClusterFinder.java index 3456d1920..5c9a07aa5 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/ActionClusterFinder.java +++ b/core/src/main/java/com/github/gumtreediff/actions/ActionClusterFinder.java @@ -20,33 +20,20 @@ package com.github.gumtreediff.actions; import com.github.gumtreediff.actions.model.*; -import com.github.gumtreediff.tree.TreeContext; import org.jgrapht.DirectedGraph; -import org.jgrapht.UndirectedGraph; import org.jgrapht.alg.ConnectivityInspector; import org.jgrapht.graph.DefaultDirectedGraph; import org.jgrapht.graph.DefaultEdge; -import org.jgrapht.graph.SimpleGraph; import java.util.List; import java.util.Set; public class ActionClusterFinder { - - private TreeContext src; - - private TreeContext dst; - - private EditScript actions; - private DirectedGraph graph; private List> clusters; - public ActionClusterFinder(TreeContext src, TreeContext dst, EditScript actions) { - this.src = src; - this.dst = dst; - this.actions = actions; + public ActionClusterFinder(EditScript actions) { graph = new DefaultDirectedGraph<>(DefaultEdge.class); for (Action a: actions) diff --git a/core/src/main/java/com/github/gumtreediff/actions/AllNodesClassifier.java b/core/src/main/java/com/github/gumtreediff/actions/AllNodesClassifier.java index ab106b8e1..6916a8cae 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/AllNodesClassifier.java +++ b/core/src/main/java/com/github/gumtreediff/actions/AllNodesClassifier.java @@ -26,6 +26,9 @@ import com.github.gumtreediff.actions.model.Update; import com.github.gumtreediff.matchers.MappingStore; +/** + * Partition all moved, inserted, updated or deleted nodes. + */ public class AllNodesClassifier extends AbstractITreeClassifier { public AllNodesClassifier(Diff diff) { super(diff); diff --git a/core/src/main/java/com/github/gumtreediff/actions/ChawatheScriptGenerator.java b/core/src/main/java/com/github/gumtreediff/actions/ChawatheScriptGenerator.java index 4fda2874d..8b47ff25e 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/ChawatheScriptGenerator.java +++ b/core/src/main/java/com/github/gumtreediff/actions/ChawatheScriptGenerator.java @@ -28,6 +28,9 @@ import java.util.*; +/** + * An edit script generator based upon Chawathe algorithm. + */ public class ChawatheScriptGenerator implements EditScriptGenerator { private ITree origSrc; @@ -90,7 +93,7 @@ public EditScript generate() { List bfsDst = TreeUtils.breadthFirst(origDst); for (ITree x: bfsDst) { - ITree w = null; + ITree w; ITree y = x.getParent(); ITree z = cpyMappings.getSrcForDst(y); diff --git a/core/src/main/java/com/github/gumtreediff/actions/Diff.java b/core/src/main/java/com/github/gumtreediff/actions/Diff.java index d9cf4b492..b45980bfc 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/Diff.java +++ b/core/src/main/java/com/github/gumtreediff/actions/Diff.java @@ -19,25 +19,41 @@ package com.github.gumtreediff.actions; +import com.github.gumtreediff.gen.TreeGenerators; import com.github.gumtreediff.matchers.MappingStore; +import com.github.gumtreediff.matchers.Matchers; import com.github.gumtreediff.tree.TreeContext; +import java.io.IOException; + public class Diff { public final TreeContext src; - public final TreeContext dst; - public final MappingStore mappings; - public final EditScript editScript; - public Diff(TreeContext src, TreeContext dst, MappingStore mappings, EditScript editScript) { + public Diff(TreeContext src, TreeContext dst, + MappingStore mappings, EditScript editScript) { this.src = src; this.dst = dst; this.mappings = mappings; this.editScript = editScript; } + public static Diff compute(String srcFile, String dstFile, + String treeGenerator, String matcher) throws IOException { + TreeContext src = TreeGenerators.getInstance().getTree(srcFile, treeGenerator); + TreeContext dst = TreeGenerators.getInstance().getTree(dstFile, treeGenerator); + MappingStore mappings = Matchers.getInstance() + .getMatcherWithFallback(matcher).match(src.getRoot(), dst.getRoot()); + EditScript editScript = new SimplifiedChawatheScriptGenerator().computeActions(mappings); + return new Diff(src, dst, mappings, editScript); + } + + public static Diff compute(String srcFile, String dstFile) throws IOException { + return compute(srcFile, dstFile, null, null); + } + public ITreeClassifier createAllNodeClassifier() { return new AllNodesClassifier(this); } diff --git a/core/src/main/java/com/github/gumtreediff/actions/EditScript.java b/core/src/main/java/com/github/gumtreediff/actions/EditScript.java index 0e484917e..de9054b58 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/EditScript.java +++ b/core/src/main/java/com/github/gumtreediff/actions/EditScript.java @@ -25,6 +25,11 @@ import java.util.Iterator; import java.util.List; +/** + * Class representing edit scripts: sequence of edit actions. + * + * @see Action + */ public class EditScript implements Iterable { private List actions; diff --git a/core/src/main/java/com/github/gumtreediff/actions/EditScriptGenerator.java b/core/src/main/java/com/github/gumtreediff/actions/EditScriptGenerator.java index 18791b046..903ec1326 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/EditScriptGenerator.java +++ b/core/src/main/java/com/github/gumtreediff/actions/EditScriptGenerator.java @@ -21,6 +21,12 @@ import com.github.gumtreediff.matchers.MappingStore; +/** + * Interface for script generators that compute edit scripts from mappings. + * + * @see MappingStore + * @see EditScript + */ public interface EditScriptGenerator { - EditScript computeActions(MappingStore ms); + EditScript computeActions(MappingStore mappings); } diff --git a/core/src/main/java/com/github/gumtreediff/actions/ITreeClassifier.java b/core/src/main/java/com/github/gumtreediff/actions/ITreeClassifier.java index f0b39d9bb..572e2a727 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/ITreeClassifier.java +++ b/core/src/main/java/com/github/gumtreediff/actions/ITreeClassifier.java @@ -23,6 +23,11 @@ import java.util.Set; +/** + * An interface to partition the nodes of a tree into sets of updated, deleted, moved, + * and updated nodes. + * @see ITree + */ public interface ITreeClassifier { Set getUpdatedSrcs(); diff --git a/core/src/main/java/com/github/gumtreediff/actions/InsertDeleteChawatheScriptGenerator.java b/core/src/main/java/com/github/gumtreediff/actions/InsertDeleteChawatheScriptGenerator.java index 0b294c0b4..1b11c3de8 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/InsertDeleteChawatheScriptGenerator.java +++ b/core/src/main/java/com/github/gumtreediff/actions/InsertDeleteChawatheScriptGenerator.java @@ -23,6 +23,12 @@ import com.github.gumtreediff.matchers.MappingStore; import com.github.gumtreediff.tree.ITree; +/** + * A script generator, based upon the simplified Chawathe script generator, + * that replaces moved and updated nodes by inserted and deleted nodes. + * + * @see SimplifiedChawatheScriptGenerator + */ public class InsertDeleteChawatheScriptGenerator implements EditScriptGenerator { private EditScript actions; private MappingStore origMappings; diff --git a/core/src/main/java/com/github/gumtreediff/actions/OnlyRootsClassifier.java b/core/src/main/java/com/github/gumtreediff/actions/OnlyRootsClassifier.java index 88e1a68cb..69b80d268 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/OnlyRootsClassifier.java +++ b/core/src/main/java/com/github/gumtreediff/actions/OnlyRootsClassifier.java @@ -22,12 +22,14 @@ import com.github.gumtreediff.actions.model.*; import com.github.gumtreediff.actions.model.Delete; -import com.github.gumtreediff.matchers.MappingStore; import com.github.gumtreediff.tree.ITree; import java.util.HashSet; import java.util.Set; +/** + * Partition only root (of a complete subtree) moved, inserted, updated or deleted nodes. + */ public class OnlyRootsClassifier extends AbstractITreeClassifier { public OnlyRootsClassifier(Diff diff) { super(diff); diff --git a/core/src/main/java/com/github/gumtreediff/actions/SimplifiedChawatheScriptGenerator.java b/core/src/main/java/com/github/gumtreediff/actions/SimplifiedChawatheScriptGenerator.java index 002aa2dfc..d1d941856 100644 --- a/core/src/main/java/com/github/gumtreediff/actions/SimplifiedChawatheScriptGenerator.java +++ b/core/src/main/java/com/github/gumtreediff/actions/SimplifiedChawatheScriptGenerator.java @@ -26,6 +26,12 @@ import java.util.HashMap; import java.util.Map; +/** + * A script generator, based upon the Chawathe algorithm, + * that makes use of deleted and inserted subtrees actions. + * + * @see ChawatheScriptGenerator + */ public class SimplifiedChawatheScriptGenerator implements EditScriptGenerator { private EditScript actions; diff --git a/core/src/main/java/com/github/gumtreediff/gen/TreeGenerator.java b/core/src/main/java/com/github/gumtreediff/gen/TreeGenerator.java index 6a2b28fce..d4440ccfc 100644 --- a/core/src/main/java/com/github/gumtreediff/gen/TreeGenerator.java +++ b/core/src/main/java/com/github/gumtreediff/gen/TreeGenerator.java @@ -29,9 +29,12 @@ import java.nio.file.Path; import java.nio.file.Paths; +/** + * An abstract class for tree generators that produce tree contexts from a input stream. + * @see TreeContext + */ @IndexSubclasses public abstract class TreeGenerator { - protected abstract TreeContext generate(Reader r) throws IOException; protected TreeContext generateTree(Reader r) throws IOException { diff --git a/core/src/main/java/com/github/gumtreediff/gen/Generators.java b/core/src/main/java/com/github/gumtreediff/gen/TreeGenerators.java similarity index 91% rename from core/src/main/java/com/github/gumtreediff/gen/Generators.java rename to core/src/main/java/com/github/gumtreediff/gen/TreeGenerators.java index fed78f973..3f7f3cfdf 100644 --- a/core/src/main/java/com/github/gumtreediff/gen/Generators.java +++ b/core/src/main/java/com/github/gumtreediff/gen/TreeGenerators.java @@ -26,16 +26,19 @@ import java.util.Arrays; import java.util.regex.Pattern; -public class Generators extends Registry { +/** + * Registry of tree generators, using a singleton pattern. + */ +public class TreeGenerators extends Registry { - private static Generators registry; + private static TreeGenerators registry; /** * Return the tree generators registry instance (singleton pattern) */ - public static final Generators getInstance() { + public static TreeGenerators getInstance() { if (registry == null) - registry = new Generators(); + registry = new TreeGenerators(); return registry; } @@ -74,11 +77,7 @@ public TreeContext getTree(String file, String generator) throws UnsupportedOper * Indicate whether or not the given file path has a related tree generator */ public boolean hasGeneratorForFile(String file) { - TreeGenerator p = get(file); - if (p == null) - return false; - else - return true; + return get(file) != null; } @Override diff --git a/core/src/main/java/com/github/gumtreediff/matchers/Mapping.java b/core/src/main/java/com/github/gumtreediff/matchers/Mapping.java index 592eb2e72..21fd9c314 100644 --- a/core/src/main/java/com/github/gumtreediff/matchers/Mapping.java +++ b/core/src/main/java/com/github/gumtreediff/matchers/Mapping.java @@ -23,10 +23,11 @@ import com.github.gumtreediff.tree.ITree; import com.github.gumtreediff.utils.Pair; +/** + * A mapping between a src and a dst tree. + */ public class Mapping extends Pair { - public Mapping(ITree a, ITree b) { super(a, b); } - } diff --git a/core/src/main/java/com/github/gumtreediff/matchers/MappingStore.java b/core/src/main/java/com/github/gumtreediff/matchers/MappingStore.java index 78dbeee4b..ad1391665 100644 --- a/core/src/main/java/com/github/gumtreediff/matchers/MappingStore.java +++ b/core/src/main/java/com/github/gumtreediff/matchers/MappingStore.java @@ -24,6 +24,9 @@ import com.github.gumtreediff.tree.ITree; +/** + * Stores the mappings between the nodes of a src and dst trees. + */ public class MappingStore implements Iterable { public final ITree src; public final ITree dst; diff --git a/core/src/main/java/com/github/gumtreediff/matchers/Matcher.java b/core/src/main/java/com/github/gumtreediff/matchers/Matcher.java index 9808f400e..e3c084f21 100644 --- a/core/src/main/java/com/github/gumtreediff/matchers/Matcher.java +++ b/core/src/main/java/com/github/gumtreediff/matchers/Matcher.java @@ -23,9 +23,13 @@ import com.github.gumtreediff.tree.ITree; import org.atteo.classindex.IndexSubclasses; +/** + * Interface for matchers that produce mappings between the nodes of a src and dst tree. + * @see MappingStore + * @see ITree + */ @IndexSubclasses public interface Matcher { - MappingStore match(ITree src, ITree dst, MappingStore mappings); default MappingStore match(ITree src, ITree dst) { diff --git a/core/src/main/java/com/github/gumtreediff/matchers/Matchers.java b/core/src/main/java/com/github/gumtreediff/matchers/Matchers.java index e4189b00b..4f877ba40 100644 --- a/core/src/main/java/com/github/gumtreediff/matchers/Matchers.java +++ b/core/src/main/java/com/github/gumtreediff/matchers/Matchers.java @@ -22,8 +22,10 @@ import com.github.gumtreediff.gen.Registry; import com.github.gumtreediff.matchers.heuristic.LcsMatcher; -import com.github.gumtreediff.tree.ITree; +/** + * Registry of matchers, using a singleton pattern. + */ public class Matchers extends Registry { private static Matchers registry;