Skip to content

Commit 9c91b08

Browse files
committed
docs: improve some JavaDoc comments related to unparsing
1 parent 0db0fdd commit 9c91b08

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

src/main/java/org/variantsync/diffdetective/variation/VariationUnparser.java

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313

1414
public class VariationUnparser {
1515
/**
16-
* Unparse VariationTrees to Text/String
16+
* Unparse {@link VariationTree}s into a {@link String}.
1717
*
18-
* @param tree VariationTree, that be unparsed
19-
* @param linesToLabel Function, that return list of String and has a Class T
20-
* @return String, the result of unparsing
21-
* @param <T> that implements Label
18+
* @param tree that is unparsed
19+
* @param linesToLabel a function that converts lists of lines into labels
20+
* @return the unparsed variation tree
21+
* @param <L> the type of labels of the tree
2222
*/
23-
public static <T extends Label> String variationTreeUnparser(VariationTree<T> tree, Function<List<String>, T> linesToLabel) {
23+
public static <L extends Label> String variationTreeUnparser(VariationTree<L> tree, Function<List<String>, L> linesToLabel) {
2424
if (!tree.root().getChildren().isEmpty()) {
2525
StringBuilder result = new StringBuilder();
26-
Stack<VariationTreeNode<T>> stack = new Stack<>();
26+
Stack<VariationTreeNode<L>> stack = new Stack<>();
2727
for (int i = tree.root().getChildren().size() - 1; i >= 0; i--) {
2828
stack.push(tree.root().getChildren().get(i));
2929
}
3030
while (!stack.empty()) {
31-
VariationTreeNode<T> node = stack.pop();
31+
VariationTreeNode<L> node = stack.pop();
3232
if (node.isIf()) {
3333
stack.push(new VariationTreeNode<>(NodeType.ARTIFACT, null, null,
3434
linesToLabel.apply(node.getEndIf())));
@@ -48,47 +48,55 @@ public static <T extends Label> String variationTreeUnparser(VariationTree<T> tr
4848
}
4949

5050
/**
51-
* Unparse VariationTrees to Text/String
51+
* Unparse {@link VariationTree}s into a {@link String}.
5252
*
53-
* @param tree VariationTree, that be unparsed
54-
* @return String, the result of unparsing
53+
* @param tree that is unparsed
54+
* @param linesToLabel a function that converts lists of lines into labels
55+
* @return the unparsed variation tree
5556
*/
5657
public static String variationTreeUnparser(VariationTree<DiffLinesLabel> tree) {
5758
return variationTreeUnparser(tree, DiffLinesLabel::withInvalidLineNumbers);
5859
}
5960

6061
/**
61-
* Unparse VariationDiffs to Text/String
62+
* Unparse {@link VariationDiff}s into a {@link String}.
6263
*
63-
* @param diff VariationDiff, that be unparsed
64-
* @param linesToLabel Function, that return list of String and has a Class T
65-
* @return String, the result of unparsing
66-
* @param <T> that implements Label
64+
* @param diff that is unparsed
65+
* @param linesToLabel a function that converts lists of lines into labels
66+
* @return the unparsed variation diff
67+
* @param <L> the type of labels of the tree
6768
* @throws IOException
6869
*/
69-
public static <T extends Label> String variationDiffUnparser(VariationDiff<T> diff, Function<List<String>, T> linesToLabel) throws IOException {
70+
public static <L extends Label> String variationDiffUnparser(VariationDiff<L> diff, Function<List<String>, L> linesToLabel) throws IOException {
7071
String tree1 = variationTreeUnparser(diff.project(Time.BEFORE), linesToLabel);
7172
String tree2 = variationTreeUnparser(diff.project(Time.AFTER), linesToLabel);
7273
return JGitDiff.textDiff(tree1, tree2, SupportedAlgorithm.MYERS);
7374
}
7475

7576
/**
76-
* Unparse VariationDiffs to Text/String
77+
* Unparse {@link VariationDiff}s into a {@link String}.
7778
*
78-
* @param diff VariationDiff, that be unparsed
79-
* @return String, the result of unparsing
79+
* @param diff that is unparsed
80+
* @return the unparsed variation diff
8081
* @throws IOException
8182
*/
8283
public static String variationDiffUnparser(VariationDiff<DiffLinesLabel> diff) throws IOException {
8384
return variationDiffUnparser(diff, DiffLinesLabel::withInvalidLineNumbers);
8485
}
8586

86-
public static String undiff(String text, Time time) {
87-
if (text.isEmpty()) {
87+
/**
88+
* Extract the state of the diffed text before or after {@code diff}.
89+
*
90+
* @param diff the diff from which the state is extracted
91+
* @param time that the returned state represents
92+
* @return the state before or after the diff
93+
*/
94+
public static String undiff(String diff, Time time) {
95+
if (diff.isEmpty()) {
8896
return "";
8997
} else {
9098
StringBuilder result = new StringBuilder();
91-
String[] textSplit = text.split("\n");
99+
String[] textSplit = diff.split("\n");
92100
char zeichen;
93101
if (Time.AFTER == time) {
94102
zeichen = '-';

src/main/java/org/variantsync/diffdetective/variation/diff/DiffNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ public static <L extends Label> DiffNode<L> createArtifact(DiffType diffType, Di
135135

136136
/**
137137
* Returns the lines in the diff that are represented by this DiffNode as a single text.
138+
*
139+
* @see getEndIf
138140
*/
139141
public L getLabel() {
140142
return label.getInnerLabel();

src/main/java/org/variantsync/diffdetective/variation/tree/VariationNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public VariationNode<T, L> downCast() {
7272
* Otherwise it may represent the preprocessor expression which was parsed to obtain
7373
* {@link #getFormula()}. In either case, this label may be an arbitrary value,
7474
* selected according to the needs of the user of this class.
75+
*
76+
* @see getEndIf
7577
*/
7678
public abstract L getLabel();
7779

src/main/java/org/variantsync/diffdetective/variation/tree/VariationTree.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public static VariationTree<DiffLinesLabel> fromFile(
8585
* Parses a {@code VariationTree} from source code with C preprocessor annotations.
8686
*
8787
* @param input the source code to be parsed
88+
* @param source from where the variation tree was obtained
8889
* @param parseOptions {@link PatchDiffParseOptions} for the parsing process.
8990
* @return a new {@code VariationTree} representing {@code input}
9091
* @throws IOException if {@code input} throws {@code IOException}
@@ -109,6 +110,7 @@ public static VariationTree<DiffLinesLabel> fromFile(
109110
* Parses a {@code VariationTree} from source code with C preprocessor annotations.
110111
*
111112
* @param input the source code to be parsed
113+
* @param source from where the variation tree was obtained
112114
* @param parseOptions {@link PatchDiffParseOptions} for the parsing process.
113115
* @return a new {@code VariationTree} representing {@code input}
114116
* @throws DiffParseException if some preprocessor annotations can't be parsed

0 commit comments

Comments
 (0)