Class VariationDiff<L extends Label>
java.lang.Object
org.variantsync.diffdetective.variation.diff.VariationDiff<L>
- Type Parameters:
L
- The type of label stored in this tree.
Implementation of variation tree diffs from our ESEC/FSE'22 paper.
An instance of this class represents a variation tree diff. It stores the root of the graph as a
DiffNode
.
It optionally holds a VariationDiffSource
that describes how the variation tree diff was obtained.
The graph structure is implemented by the DiffNode
class.- Author:
- Paul Bittner, Sören Viegener
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
Helper class to check for cycles in VariationDiffs. -
Field Summary
-
Constructor Summary
ConstructorDescriptionVariationDiff
(DiffNode<L> root) Creates a VariationDiff that only consists of the single given root node.VariationDiff
(DiffNode<L> root, VariationDiffSource source) Creates a VariationDiff that only consists of the single given root node. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks whether all nodes in this tree satisfy the given condition.boolean
Checks whether any node in this tree satisfies the given condition.void
Checks whether this VariationDiff is consistent.Returns all nodes in this VariationDiff.computeAllNodesThat
(Predicate<DiffNode<L>> property) Returns all nodes that satisfy the given predicate.Returns all mapping nodes of this VariationDiff.Returns all artifact nodes of this VariationDiff.int
Returns the number of nodes in this VariationDiff.int
Returns the number of nodes in this tree that satisfy the given condition.deepCopy()
Invokes the given callback for each node in this VariationDiff.static VariationDiff<DiffLinesLabel>
fromDiff
(String diff, VariationDiffParseOptions parseOptions) Parses a VariationDiff from the given unix diff.static VariationDiff<DiffLinesLabel>
fromFile
(Path p, VariationDiffParseOptions parseOptions) Parses a VariationDiff from the given file.static VariationDiff<DiffLinesLabel>
fromFiles
(Path beforeFile, Path afterFile, org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm algorithm, VariationDiffParseOptions options) Create a VariationDiff from two given text files.static VariationDiff<DiffLinesLabel>
fromLines
(String before, String after, org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm algorithm, VariationDiffParseOptions options) Creates a variation diff from to line-based text inputs.static org.variantsync.functjonal.Result<VariationDiff<DiffLinesLabel>,
List<DiffError>> fromPatch
(PatchReference patchReference, Repository repository) Parses a patch of a Git repository.static <L extends Label>
VariationDiff<L>fromTrees
(VariationTree<L> before, VariationTree<L> after) getNodeWithID
(int id) Obtain the DiffNode with the given id in this VariationDiff.getRoot()
Returns the root node of this tree.Returns the source of this VariationDiff (i.e., the data this VariationDiff was created from).Checks whether this VariationDiff is consistent.boolean
isEmpty()
Returns true iff this tree is empty.boolean
isSameAs
(VariationDiff<L> b) boolean
Checks whether no node in this tree satisfies the given condition.Creates the projection of this variation diff at the given time.void
removeNode
(DiffNode<L> node) Removes the given node from the VariationDiff but keeps its children.void
setSource
(VariationDiffSource source) Sets the source of this VariationDiff.toString()
traverse
(VariationDiffVisitor<L> visitor) Traverse this VariationDiff with the given visitor.
-
Field Details
-
root
-
source
-
-
Constructor Details
-
VariationDiff
Creates a VariationDiff that only consists of the single given root node.- Parameters:
root
- The root of this tree.
-
VariationDiff
Creates a VariationDiff that only consists of the single given root node. Remembers the given source as the tree's source of creation.- Parameters:
root
- The root of this tree.source
- The data from which the VariationDiff was created.
-
-
Method Details
-
fromFile
public static VariationDiff<DiffLinesLabel> fromFile(Path p, VariationDiffParseOptions parseOptions) throws IOException, DiffParseException Parses a VariationDiff from the given file. The file should contain a text-based diff without any meta information. So just lines preceded by "+", "-", or " " are expected.- Parameters:
p
- Path to a diff file.parseOptions
-VariationDiffParseOptions
for the parsing process.- Returns:
- A result either containing the parsed VariationDiff or an error message in case of failure.
- Throws:
IOException
- when the given file could not be read for some reason.DiffParseException
-
fromDiff
public static VariationDiff<DiffLinesLabel> fromDiff(String diff, VariationDiffParseOptions parseOptions) throws DiffParseException Parses a VariationDiff from the given unix diff. The file should contain a text-based diff without any meta information. So just lines preceded by "+", "-", or " " are expected.- Parameters:
diff
- The diff as text. Lines should be separated by a newline character. Each line should be preceded by either "+", "-", or " ".parseOptions
-VariationDiffParseOptions
for the parsing process.- Returns:
- A result either containing the parsed VariationDiff or an error message in case of failure.
- Throws:
DiffParseException
- ifdiff
couldn't be parsed
-
fromPatch
public static org.variantsync.functjonal.Result<VariationDiff<DiffLinesLabel>,List<DiffError>> fromPatch(PatchReference patchReference, Repository repository) throws IOException Parses a patch of a Git repository. Warning: The current implementation ignorespatchReference.getParentCommitHash
. It assumes that it's equal to the first parent ofpatchReference.getCommitHash
, so it cannot parse patches across multiple commits.- Parameters:
patchReference
- the patch to be parsedrepository
- the repository which contains the pathpatchReference
- Returns:
- a
VariationDiff
representing the referenced patch, or a list of errors encountered while trying to parse theVariationDiff
- Throws:
IOException
-
fromFiles
public static VariationDiff<DiffLinesLabel> fromFiles(Path beforeFile, Path afterFile, org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm algorithm, VariationDiffParseOptions options) throws IOException, DiffParseException Create a VariationDiff from two given text files. -
fromLines
public static VariationDiff<DiffLinesLabel> fromLines(String before, String after, org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm algorithm, VariationDiffParseOptions options) throws IOException, DiffParseException Creates a variation diff from to line-based text inputs. This method just forwards to: -
fromTrees
public static <L extends Label> VariationDiff<L> fromTrees(VariationTree<L> before, VariationTree<L> after) -
project
Creates the projection of this variation diff at the given time. The returned value is a deep copy of the variation tree within this diff at the given time. If you instead wish to only have a view on the tree at the given diff have a look atDiffNode.projection(Time)
for this treesroot
.- Parameters:
t
- The time for which to project the variation tree.
-
forAll
Invokes the given callback for each node in this VariationDiff.- Parameters:
procedure
- callback- Returns:
- this
-
traverse
Traverse this VariationDiff with the given visitor. When visiting a node, the visitor decides how to proceed.- Parameters:
visitor
- visitor that is invoked on the root first and then decides how to proceed the traversal.- Returns:
- this
-
allMatch
Checks whether all nodes in this tree satisfy the given condition. The condition might not be invoked on every node in case it is not necessary.- Parameters:
condition
- A condition to check on each node.- Returns:
- True iff the given condition returns true for all nodes in this tree.
-
anyMatch
Checks whether any node in this tree satisfies the given condition. The condition might not be invoked on every node in case a node is found.- Parameters:
condition
- A condition to check on each node.- Returns:
- True iff the given condition returns true for at least one node in this tree.
-
noneMatch
Checks whether no node in this tree satisfies the given condition. The condition might not be invoked on every node.- Parameters:
condition
- A condition to check on each node.- Returns:
- True iff the given condition returns false for every node in this tree.
-
getRoot
Returns the root node of this tree. -
getNodeWithID
Obtain the DiffNode with the given id in this VariationDiff.- Parameters:
id
- The id of the node to search.- Returns:
- The node with the given id if existing, null otherwise.
-
computeAllNodesThat
Returns all nodes that satisfy the given predicate. Traverses the VariationDiff once.- Parameters:
property
- Filter for nodes. Should return true if a node should be included.- Returns:
- A List of all nodes satisfying the given predicate.
-
computeArtifactNodes
Returns all artifact nodes of this VariationDiff. -
computeAnnotationNodes
Returns all mapping nodes of this VariationDiff. -
computeAllNodes
Returns all nodes in this VariationDiff. Traverses the VariationDiff once. -
count
Returns the number of nodes in this tree that satisfy the given condition.- Parameters:
nodesToCount
- A condition that returns true for each node that should be counted.- Returns:
- The number of nodes in this tree that satisfy the given condition.
-
setSource
Sets the source of this VariationDiff.- See Also:
-
getSource
Returns the source of this VariationDiff (i.e., the data this VariationDiff was created from).- See Also:
-
computeSize
public int computeSize()Returns the number of nodes in this VariationDiff. -
isEmpty
public boolean isEmpty()Returns true iff this tree is empty. The tree is considered empty if it only has a root or if it has no nodes at all. -
removeNode
Removes the given node from the VariationDiff but keeps its children. The children are moved up, meaning that they are located below the parent of the given node afterwards.- Parameters:
node
- The node to remove. Cannot be the root.
-
assertConsistency
public void assertConsistency()Checks whether this VariationDiff is consistent. Throws an error when this VariationDiff is inconsistent (e.g., if it has cycles or an invalid internal state). Has no side-effects otherwise.- See Also:
-
isConsistent
Checks whether this VariationDiff is consistent.- Returns:
- A result that indicates either consistency or inconsistency.
-
isSameAs
-
toString
-
deepCopy
-