Interface Source
- All Known Implementing Classes:
BadVDiff,CommitDiffVariationDiffSource,CompositeSource,Configure,ConfigureSpec,FileSource,GitPatch.SimpleGitPatch,GitSource,LineGraphFileSource,PatchDiff,PatchString,ProjectionSource,Search,Trace,TraceSup,VariationDiff,VariationTree,ViewSource
VariationDiff. Now you want to know
where the variation diff came from. The solution: DiffDetectice tracks the source and
transformations of important data structures like VariationDiff.getSource() and allows
you to inspect them using this interface.
Source represents a hierarchy of inputs, processing steps, and results (the distinction
between these types is not directly reflected in the API and only serve as explanation of the
interface).
- An input (e.g.,
FileSource) is aSourcethat has nochildren. Inputs are the leafs of theSourcehierarchy and contain thename of the input(e.g.,"file"or"URL") andsome arguments(e.g., the file name or URL). - A step (e.g.,
ProjectionSource) processedone or more sources, has anameand may be configurable by somearguments. Unconfigurable processing steps (or steps whose configurability should not be tracked) are most commonly represented byCompositeSource. Note that a step might also include (interim) results and might thus be considered a result too. - A result (e.g.,
VariationDiff) contains some data and thesource of that data. The contained data is not directly accessible bythis interfacebut can be obtained by looking up the subclass representing that result with<T>findFirst(org.variantsync.diffdetective.util.Source,java.lang.Class<T>)or<T>findAll(org.variantsync.diffdetective.util.Source,java.lang.Class<T>). Results are not necessary to trace the source of some data (and it might thus be omitted from theSourcehierarchy) but can help to identify a buggy processing step.
In summary, each Source in the hierarchy has a short explanation and a number of arguments. A
source may contain additional data (e.g., the diff a variation diff originated from) that is too
big to be printed by the standard formatting functions (shallowExplanation(), shortExplanation(org.variantsync.diffdetective.util.Source), fullExplanation(int,java.lang.StringBuilder)) of this interface. To access such data, or the
arguments of specific subclasses, you can use <T>findFirst(org.variantsync.diffdetective.util.Source,java.lang.Class<T>) and <T>findAll(org.variantsync.diffdetective.util.Source,java.lang.Class<T>).
For dealing with generic sources, it is recommended to use the static methods of this interface.
They provide a more readable interface (e.g., variationDiff.shallowExplanation() vs.
Source.shallowExplanation(variationDiff)) and correctly deal with null sources
(treated as Unknown).
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> voidImplementation of<T>findAll(org.variantsync.diffdetective.util.Source,java.lang.Class<T>)using anresultaccumulator.static <T> List<T> static <T> Tdefault voidfullExplanation(int level, StringBuilder result) Explainsthissource hierarchy in detail.static StringfullExplanation(Source source) CallsfullExplanation(int,java.lang.StringBuilder)onsourcebut handlesnulllikeUnknownand returns the resulting string.default StringThe same asfullExplanation(Source)but with a different formatting.default SourceReturns one representativeSourcethat identifies the initial data.Returns a list of arguments required to understand this source.Returns a short, one line explanation or identifier of this source.Returns a list of sources that influenced this source.static StringrootExplanation(Source source) default StringAn explanation of this source disregarding allchild sources.static StringshallowExplanation(Source source) static StringshortExplanation(Source source) Returns a short one line explanation ofsourceby pairingshortExplanation(org.variantsync.diffdetective.util.Source)withrootExplanation(org.variantsync.diffdetective.util.Source).
-
Field Details
-
Unknown
A placeholder for an unknown source without any explanation. Should be preferred to anullSourceto make it easily grepable.
-
-
Method Details
-
getSourceExplanation
String getSourceExplanation()Returns a short, one line explanation or identifier of this source. The result is used byshallowExplanation()and is formatted together withgetSourceArguments()like"sourceExplanation(argument1, argument2)". -
getSourceArguments
Returns a list of arguments required to understand this source. Each argument in the result list should represent astringwithout newlines and will be formatted together withgetSourceExplanation()like"sourceExplanation(argument1, argument2)"byshallowExplanation(). This method is only intended to access the arguments forprinting. In case access to the well-typed object is required, use<T>findFirst(org.variantsync.diffdetective.util.Source,java.lang.Class<T>)or<T>findAll(org.variantsync.diffdetective.util.Source,java.lang.Class<T>)and use the accessors of the underlying type.For ease of implementing
Source, the return value is a list ofObjects instead of a list ofStrings to allow code likeList.of(arg0, arg1, arg2)instead ofList.of(arg0.toString(), arg1.toString(), arg2.toString()). Users of this function should assume nothing from the returned objects except thatObject.toString()is well behaved.- Returns:
- an empty list by default
- See Also:
-
getSources
Returns 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
getRootSource().- Returns:
- an empty list by default
-
shallowExplanation
An explanation of this source disregarding allchild sources. The resulting string should not contain any newlines.- Returns:
"sourceExplanation(argument1, argument2, ...)"by default- See Also:
-
shallowExplanation
-
getRootSource
Returns one representativeSourcethat identifies the initial data. A good root source should help humans to understand at what data they are looking at. Good examples is a filename or a commit and repository combination. Note that sometimes this is an arbitrary decision (e.g., the state before or after a diff) and might depend on the problem that is currently worked on. Hence, there is might not be one correct result in all circumstances.- Returns:
- the
first childorthisif there are nochildren
-
rootExplanation
-
shortExplanation
Returns a short one line explanation ofsourceby pairingshortExplanation(org.variantsync.diffdetective.util.Source)withrootExplanation(org.variantsync.diffdetective.util.Source). -
fullExplanation
Explainsthissource hierarchy in detail. Theresultwill contain at least one line perSourcein thehierarchy(by default in theshallowExplanation()format). The state ofresultmust be in a new line before and after a call to this method.- Parameters:
level- the current indentation level (two spaces per level) that needs to be added before each lineresult- the string containing the result of this method
-
fullExplanation
CallsfullExplanation(int,java.lang.StringBuilder)onsourcebut handlesnulllikeUnknownand returns the resulting string. -
functionExplanation
The same asfullExplanation(Source)but with a different formatting. Where fullExplanation renders this tree of sources as using newlines and indentation, functionExplanation renders this tree as one large, nested function call of the form:getSourceExplanation()(args...,nested sources...). -
findAll
Uses a depth first traversal of theSourcehierarchyto find and return all instances ofclazz. This method is intended to provide access to the data contained in the source hierarchy. For example,Source.findAll(src, File.class)finds all source files. Note that arguments are not inspected. In case an implementationSourcecontains afileasargumentit is not included in the result.- See Also:
-
findAll
Implementation of<T>findAll(org.variantsync.diffdetective.util.Source,java.lang.Class<T>)using anresultaccumulator. -
findFirst
Uses a depth first traversal of theSourcehierarchyto find and return the first instances ofclazz. This method is intended to provide access to the data contained in the source hierarchy. For example,Source.findFirst(src, PatchDiff.class)finds the firstPatchDiff. This allows access to data and arguments likePatchDiff.getDiff()but it does not traverse thegetSourceArguments()directly.- See Also:
-