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.
- All Implemented Interfaces:
Source
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 Source 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
Nested ClassesModifier and TypeClassDescriptionprivate static classHelper class to check for cycles in VariationDiffs. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVariationDiff(DiffNode<L> root) Creates a VariationDiff that only consists of the single given root node.VariationDiff(DiffNode<L> root, Source source) Creates a VariationDiff that only consists of the single given root node. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether all nodes in this tree satisfy the given condition.booleanChecks whether any node in this tree satisfies the given condition.voidChecks whether this VariationDiff is consistent.Returns all variable names occurring in annotations (i.e., formulas of mapping nodes) in this variation diff.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.intReturns the number of nodes in this VariationDiff.intReturns 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, Source source, 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, Source beforeSource, Source afterSource, 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).Returns a short, one line explanation or identifier of this source.Returns a list of sources that influenced this source.Checks whether this VariationDiff is consistent.booleanisEmpty()Returns true iff this tree is empty.booleanisSameAs(VariationDiff<L> b) booleanbooleanChecks whether no node in this tree satisfies the given condition.Creates the projection of this variation diff at the given time.voidremoveNode(DiffNode<L> node) Removes the given node from the VariationDiff but keeps its children.voidSets the source of this VariationDiff.toString()traverse(VariationDiffVisitor<L> visitor) Traverse this VariationDiff with the given visitor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.variantsync.diffdetective.util.Source
fullExplanation, functionExplanation, getRootSource, getSourceArguments, shallowExplanation
-
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-VariationDiffParseOptionsfor 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, Source source, 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 " ".source- theSourceofdiffparseOptions-VariationDiffParseOptionsfor the parsing process.- Returns:
- A result either containing the parsed VariationDiff or an error message in case of failure.
- Throws:
DiffParseException- ifdiffcouldn'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
VariationDiffrepresenting 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.- Throws:
IOExceptionDiffParseException- See Also:
-
fromLines
public static VariationDiff<DiffLinesLabel> fromLines(String before, String after, Source beforeSource, Source afterSource, 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:- Throws:
IOExceptionDiffParseException- See Also:
-
fromTrees
public static <L extends Label> VariationDiff<L> fromTrees(VariationTree<L> before, VariationTree<L> after) - See Also:
-
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 tree'sroot.- 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.- See Also:
-
computeAnnotationNodes
Returns all mapping nodes of this VariationDiff.- See Also:
-
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.
-
computeAllFeatureNames
Returns all variable names occurring in annotations (i.e., formulas of mapping nodes) in this variation diff. This method is deterministic: It will return the feature names always in the same order, assuming the variation diff is not changed inbetween.- Returns:
- A set of every occuring feature name.
-
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:
-
getSources
Description copied from interface:SourceReturns a list of sources that influenced this source. Noteworthy processing steps and incorporation of multiple sources are implemented as a tree of sources. This functions returns the children of this source.By default, the first child source is treated specially in
Source.getRootSource().- Specified by:
getSourcesin interfaceSource- Returns:
- an empty list by default
-
getSourceExplanation
Description copied from interface:SourceReturns a short, one line explanation or identifier of this source. The result is used bySource.shallowExplanation()and is formatted together withSource.getSourceArguments()like"sourceExplanation(argument1, argument2)".- Specified by:
getSourceExplanationin interfaceSource
-
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
- See Also:
-
isSameAsIgnoringLineNumbers
- See Also:
-
toString
-
deepCopy
-