java.lang.Object
org.variantsync.diffdetective.variation.diff.construction.GumTreeDiff

public class GumTreeDiff extends Object
  • Constructor Details

    • GumTreeDiff

      public GumTreeDiff()
  • Method Details

    • diffUsingMatching

      public static <L extends Label> VariationDiff<L> diffUsingMatching(VariationTree<L> before, VariationTree<L> after)
      Create a VariationDiff by matching nodes between before and after with the default GumTree matcher.
      See Also:
    • diffUsingMatching

      public static <A extends VariationNode<A, L>, B extends VariationNode<B, L>, L extends Label> DiffNode<L> diffUsingMatching(VariationNode<A,L> before, VariationNode<B,L> after, com.github.gumtreediff.matchers.Matcher matcher)
      Create a DiffNode by matching nodes between before and after with matcher. The arguments of this function aren't modified (note the overload which modifies before in-place.
      Parameters:
      before - the variation tree before an edit
      after - the variation tree after an edit
      See Also:
    • diffUsingMatching

      public static <B extends VariationNode<B, L>, L extends Label> DiffNode<L> diffUsingMatching(DiffNode<L> before, VariationNode<B,L> after, com.github.gumtreediff.matchers.Matcher matcher)
      Create a DiffNode by matching nodes between before and after with matcher. The result of this function is before which is modified in-place. In contrast, after is kept in tact. Warning: Modifications to before shouldn't concurrently modify after. Note: There are currently no guarantees about the line numbers. But it is guaranteed that DiffNode.getID() is unique.
      Parameters:
      before - the variation tree before an edit
      after - the variation tree after an edit
      See Also:
      • "Constructing Variation Diffs Using Tree Diffing Algorithms"
    • removeUnmapped

      private static <L extends Label> void removeUnmapped(com.github.gumtreediff.matchers.MappingStore mappings, VariationDiffAdapter<L> root)
      Remove all nodes from the BEFORE projection which aren't part of a mapping.
      Parameters:
      mappings - the matching between the BEFORE projection of root some variation tree
      root - the variation diff whose before projection is modified
    • addUnmapped

      private static <L extends Label> void addUnmapped(com.github.gumtreediff.matchers.MappingStore mappings, DiffNode<L> parent, VariationTreeAdapter<L> afterNode)
      Recursively adds afterNode to parent reusing matched nodes. The variation diff parent is modified in-place such that its AFTER projection contains a child equivalent to afterNode which shares matched nodes with the BEFORE projection of parent.
      Parameters:
      mappings - the matching between the BEFORE projection of root and a variation tree containing afterNode
      parent - the variation diff whose AFTER projection is modified
      afterNode - a desired child of parent's AFTER projection
    • improveMatching

      public static <L extends Label> DiffNode<L> improveMatching(DiffNode<L> tree, com.github.gumtreediff.matchers.Matcher matcher)
      Run matcher on the matching extracted from tree and modify tree in-place to reflect the new matching. This is equivalent to diffUsingMatching except that the existing implicit matching is extracted and used as basis for the new matching. Hence, this method is mostly an optimisation to avoid a copy of the AFTER projection of tree.
      See Also:
      • "Constructing Variation Diffs Using Tree Diffing Algorithms"
    • splitNode

      private static <L extends Label> DiffNode<L> splitNode(DiffNode<L> beforeNode)
      Removes the implicit matching between the BEFORE and AFTER projection of beforeNode. This is achieved by copying beforeNode and reconnecting all necessary edges such that the new node exists only after and beforeNode only exists before the edit. This method doesn't change the BEFORE and AFTER projection of beforeNode.
      Parameters:
      beforeNode - the node to be split
      Returns:
      a copy of beforeNode existing only after the edit.
    • joinNode

      private static <L extends Label> void joinNode(DiffNode<L> beforeNode, DiffNode<L> afterNode)
      Merges afterNode into beforeNode such that beforeNode.isNon() == true. Essentially, an implicit matching is inserted between beforeNode and afterNode. This method doesn't change the BEFORE and AFTER projection of beforeNode.
      Parameters:
      beforeNode - the node which is will exist BEFORE and AFTER the edit
      afterNode - the node which is discarded
    • extractMatching

      private static <L extends Label> void extractMatching(VariationDiffAdapter<L> src, VariationDiffAdapter<L> dst, com.github.gumtreediff.matchers.MappingStore result)
      Makes the implicit matching of a VariationDiff explicit.
      Parameters:
      src - the source nodes of the matching, must be of the same VariationDiff as dst.
      dst - the destination nodes of the matching, must be of the same VariationDiff as src
      result - the destination where the matching between src and is added.