Class VariationTree<L extends Label>
java.lang.Object
org.variantsync.diffdetective.variation.tree.VariationTree<L>
- Type Parameters:
L- The type of label stored in this tree.
- All Implemented Interfaces:
Source
Representation of a concrete variation tree with source information.
- Author:
- Benjamin Moosherr
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVariationTree(VariationTreeNode<L> root) Creates aVariationTreewith the given root and anunknownsource.VariationTree(VariationTreeNode<L> root, Source source) Creates aVariationTreewith the given root and source. -
Method Summary
Modifier and TypeMethodDescriptionbooleananyMatch(Predicate<VariationTreeNode<L>> condition) Checks whether any node in this tree satisfies the given condition.voidChecks whether thisVariationTreeis consistent.intReturns the number of nodes in this Variation Tree.booleancontains(VariationTreeNode<L> node) Returns true iff this tree contains the given node.deepCopy()deepCopy(Map<VariationTreeNode<L>, VariationTreeNode<L>> oldToNew) Creates a deep copy of this variation tree.forAllPostorder(Consumer<VariationTreeNode<L>> action) Invokes the given callback for each node in this Variation Tree in post-order.forAllPreorder(Consumer<VariationTreeNode<L>> action) Invokes the given callback for each node in this Variation Tree in pre-order.static VariationTree<DiffLinesLabel> fromFile(BufferedReader input, Source source, VariationDiffParseOptions parseOptions) Parses aVariationTreefrom source code with C preprocessor annotations.static VariationTree<DiffLinesLabel> Same asfromFile(Path, VariationDiffParseOptions)but withVariationDiffParseOptions.Defaultparse options.static VariationTree<DiffLinesLabel> fromFile(Path path, VariationDiffParseOptions parseOptions) Same asfromFile(BufferedReader, Source, VariationDiffParseOptions)but registerspathas source.static <L extends Label>
VariationTree<L> fromProjection(Projection<L> projection, Source source) static VariationTree<DiffLinesLabel> fromText(String input, Source source, VariationDiffParseOptions parseOptions) Parses aVariationTreefrom source code with C preprocessor annotations.static <T extends VariationNode<T,L>, L extends Label>
VariationTree<L> fromVariationNode(VariationNode<T, L> node, Source source) getRoot()Returns the source of this VariationTree (i.e., the data this VariationTree was created from).Returns a short, one line explanation or identifier of this source.Returns a list of sources that influenced this source.voidSets the source of this VariationTree.toString()toVariationDiff(Function<VariationTreeNode<L>, DiffNode<L>> nodeConverter) unparse()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
-
VariationTree
Creates aVariationTreewith the given root and anunknownsource. -
VariationTree
Creates aVariationTreewith the given root and source.
-
-
Method Details
-
fromFile
public static VariationTree<DiffLinesLabel> fromFile(Path path) throws IOException, DiffParseException Same asfromFile(Path, VariationDiffParseOptions)but withVariationDiffParseOptions.Defaultparse options.- Throws:
IOExceptionDiffParseException
-
fromFile
public static VariationTree<DiffLinesLabel> fromFile(Path path, VariationDiffParseOptions parseOptions) throws IOException, DiffParseException Same asfromFile(BufferedReader, Source, VariationDiffParseOptions)but registerspathas source.- Throws:
IOExceptionDiffParseException
-
fromFile
public static VariationTree<DiffLinesLabel> fromFile(BufferedReader input, Source source, VariationDiffParseOptions parseOptions) throws IOException, DiffParseException Parses aVariationTreefrom source code with C preprocessor annotations.- Parameters:
input- the source code to be parsedsource- from where the variation tree was obtainedparseOptions-PatchDiffParseOptionsfor the parsing process.- Returns:
- a new
VariationTreerepresentinginput - Throws:
IOException- ifinputthrowsIOExceptionDiffParseException- if some preprocessor annotations can't be parsed
-
fromText
public static VariationTree<DiffLinesLabel> fromText(String input, Source source, VariationDiffParseOptions parseOptions) throws DiffParseException Parses aVariationTreefrom source code with C preprocessor annotations.- Parameters:
input- the source code to be parsedsource- from where the variation tree was obtainedparseOptions-PatchDiffParseOptionsfor the parsing process.- Returns:
- a new
VariationTreerepresentinginput - Throws:
DiffParseException- if some preprocessor annotations can't be parsed
-
fromProjection
public static <L extends Label> VariationTree<L> fromProjection(Projection<L> projection, Source source) -
fromVariationNode
public static <T extends VariationNode<T,L>, VariationTree<L> fromVariationNodeL extends Label> (VariationNode<T, L> node, Source source) -
toVariationDiff
-
toCompletelyUnchangedVariationDiff
-
forAllPreorder
Invokes the given callback for each node in this Variation Tree in pre-order.- Parameters:
action- callback- Returns:
- this
-
forAllPostorder
Invokes the given callback for each node in this Variation Tree in post-order.- Parameters:
action- callback- Returns:
- this
-
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.
-
contains
Returns true iff this tree contains the given node. Containment check is done on referential and not on textual equality (i.e., nodes are compared using ==).- Parameters:
node- The node to check for containment.
-
computeSize
public int computeSize()Returns the number of nodes in this Variation Tree. -
deepCopy
-
deepCopy
Creates a deep copy of this variation tree.The map
oldToNewshould be empty as it will be filled by this method. After the method call, the map keys will contain all nodes in this tree. The corresponding values will be the nodes in the returned tree, where each pair (k, v) denotes that v was cloned from k.- Parameters:
oldToNew- A map that memorizes the translation of individual nodes.- Returns:
- A deep copy of this tree.
-
unparse
-
assertConsistency
public void assertConsistency()Checks whether thisVariationTreeis consistent. Throws an error if thisVariationTreeis inconsistent (e.g., if there are multipleNodeType.ELSEnodes). Has no side-effects otherwise.- See Also:
-
getRoot
-
setSource
Sets the source of this VariationTree.- See Also:
-
getSource
Returns the source of this VariationTree (i.e., the data this VariationTree 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
-
toString
-