Skip to content

Commit 6752d12

Browse files
committed
Rename CodeType to NodeType
1 parent fd33752 commit 6752d12

23 files changed

Lines changed: 134 additions & 134 deletions

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

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* Implementation of a node in a {@link DiffTree}.
1919
*
20-
* Includes methods for creating a node by getting its code type and diff type and for getting the feature mapping of the node.
20+
* Includes methods for creating a node by getting its node type and diff type and for getting the feature mapping of the node.
2121
* @author Paul Bittner, Sören Viegener, Benjamin Moosherr
2222
*/
2323
public class DiffNode {
@@ -30,10 +30,10 @@ public class DiffNode {
3030
public final DiffType diffType;
3131

3232
/**
33-
* The code type of this node, which determines the type of the represented
33+
* The node type of this node, which determines the type of the represented
3434
* element in the diff (e.g., mapping or artifact).
3535
*/
36-
public final CodeType codeType;
36+
public final NodeType nodeType;
3737

3838
private boolean isMultilineMacro = false;
3939

@@ -73,30 +73,30 @@ public class DiffNode {
7373
/**
7474
* Creates a DiffNode with the given parameters.
7575
* @param diffType The type of change made to this node.
76-
* @param codeType The type of this node (i.e., mapping or artifact).
76+
* @param nodeType The type of this node (i.e., mapping or artifact).
7777
* @param fromLines The starting line number of the corresponding text.
7878
* @param toLines The ending line number of the corresponding text.
7979
* @param featureMapping The formula stored in this node. Should be null for code (/artifact) nodes.
8080
* @param label A text label containing information to identify the node (such as the corresponding source code).
8181
*/
82-
public DiffNode(DiffType diffType, CodeType codeType,
82+
public DiffNode(DiffType diffType, NodeType nodeType,
8383
DiffLineNumber fromLines, DiffLineNumber toLines,
8484
Node featureMapping, String label) {
85-
this(diffType, codeType, fromLines, toLines, featureMapping,
85+
this(diffType, nodeType, fromLines, toLines, featureMapping,
8686
new ArrayList<String>(Arrays.asList(StringUtils.LINEBREAK_REGEX.split(label, -1))));
8787
}
8888

8989
/**
90-
* The same as {@link DiffNode#DiffNode(DiffType, CodeType, DiffLineNumber, DiffLineNumber, Node, String)}
90+
* The same as {@link DiffNode#DiffNode(DiffType, NodeType, DiffLineNumber, DiffLineNumber, Node, String)}
9191
* but with the label separated into different lines of text instead of as a single String with newlines.
9292
*/
93-
public DiffNode(DiffType diffType, CodeType codeType,
93+
public DiffNode(DiffType diffType, NodeType nodeType,
9494
DiffLineNumber fromLines, DiffLineNumber toLines,
9595
Node featureMapping, List<String> lines) {
9696
this.childOrder = new ArrayList<>();
9797

9898
this.diffType = diffType;
99-
this.codeType = codeType;
99+
this.nodeType = nodeType;
100100
this.from.set(fromLines);
101101
this.to.set(toLines);
102102
this.featureMapping = featureMapping;
@@ -110,7 +110,7 @@ public DiffNode(DiffType diffType, CodeType codeType,
110110
public static DiffNode createRoot() {
111111
return new DiffNode(
112112
DiffType.NON,
113-
CodeType.ROOT,
113+
NodeType.ROOT,
114114
new DiffLineNumber(1, 1, 1),
115115
DiffLineNumber.Invalid(),
116116
FixTrueFalse.True,
@@ -120,19 +120,19 @@ public static DiffNode createRoot() {
120120

121121
/**
122122
* Creates an artifact node with the given parameters.
123-
* For parameter descriptions, see {@link DiffNode#DiffNode(DiffType, CodeType, DiffLineNumber, DiffLineNumber, Node, String)}.
123+
* For parameter descriptions, see {@link DiffNode#DiffNode(DiffType, NodeType, DiffLineNumber, DiffLineNumber, Node, String)}.
124124
* The <code>code</code> parameter will be set as the node's label.
125125
*/
126126
public static DiffNode createCode(DiffType diffType, DiffLineNumber fromLines, DiffLineNumber toLines, String code) {
127-
return new DiffNode(diffType, CodeType.CODE, fromLines, toLines, null, code);
127+
return new DiffNode(diffType, NodeType.CODE, fromLines, toLines, null, code);
128128
}
129129

130130
/**
131131
* The same as {@link DiffNode#createCode(DiffType, DiffLineNumber, DiffLineNumber, String)} but with the code for the label
132132
* given as a list of individual lines instead of a single String with linebreaks to identify newlines.
133133
*/
134134
public static DiffNode createCode(DiffType diffType, DiffLineNumber fromLines, DiffLineNumber toLines, List<String> lines) {
135-
return new DiffNode(diffType, CodeType.CODE, fromLines, toLines, null, lines);
135+
return new DiffNode(diffType, NodeType.CODE, fromLines, toLines, null, lines);
136136
}
137137

138138
/**
@@ -651,9 +651,9 @@ public Lines getLinesAfterEdit() {
651651

652652
/**
653653
* Returns the formula that is stored in this node.
654-
* The formula is null for artifact nodes (i.e., {@link CodeType#CODE}).
654+
* The formula is null for artifact nodes (i.e., {@link NodeType#CODE}).
655655
* The formula is not null for mapping nodes
656-
* @see CodeType#isMacro
656+
* @see NodeType#isMacro
657657
*/
658658
public Node getDirectFeatureMapping() {
659659
return featureMapping;
@@ -691,9 +691,9 @@ public boolean isMultilineMacro() {
691691

692692
/**
693693
* Returns the full feature mapping formula of this node.
694-
* The feature mapping of an {@link CodeType#IF} node is its {@link DiffNode#getDirectFeatureMapping direct feature mapping}.
695-
* The feature mapping of {@link CodeType#ELSE} and {@link CodeType#ELIF} nodes is determined by all formulas in the respective if-elif-else chain.
696-
* The feature mapping of an {@link CodeType#CODE artifact} node is the feature mapping of its parent.
694+
* The feature mapping of an {@link NodeType#IF} node is its {@link DiffNode#getDirectFeatureMapping direct feature mapping}.
695+
* The feature mapping of {@link NodeType#ELSE} and {@link NodeType#ELIF} nodes is determined by all formulas in the respective if-elif-else chain.
696+
* The feature mapping of an {@link NodeType#CODE artifact} node is the feature mapping of its parent.
697697
* See Equation (1) in our paper (+ its extension to time for variation tree diffs described in Section 3.1).
698698
* @param parentOf Function that returns the parent of a node.
699699
* This function decides whether the before or after parent should be visited.
@@ -717,7 +717,7 @@ private List<Node> getFeatureMappingClauses(final Function<DiffNode, DiffNode> p
717717
if (ancestor.isElif()) {
718718
and.add(negate(ancestor.getDirectFeatureMapping()));
719719
} else {
720-
throw new RuntimeException("Expected If or Elif above Else or Elif but got " + ancestor.codeType + " from " + ancestor);
720+
throw new RuntimeException("Expected If or Elif above Else or Elif but got " + ancestor.nodeType + " from " + ancestor);
721721
// Assert.assertTrue(ancestor.isCode());
722722
}
723723
ancestor = parentOf.apply(ancestor);
@@ -745,9 +745,9 @@ private Node getFeatureMapping(Function<DiffNode, DiffNode> parentOf) {
745745

746746
/**
747747
* Returns the full feature mapping formula of this node before the edit.
748-
* The feature mapping of an {@link CodeType#IF} node is its {@link DiffNode#getDirectFeatureMapping direct feature mapping}.
749-
* The feature mapping of {@link CodeType#ELSE} and {@link CodeType#ELIF} nodes is determined by all formulas in the respective if-elif-else chain.
750-
* The feature mapping of an {@link CodeType#CODE artifact} node is the feature mapping of its parent.
748+
* The feature mapping of an {@link NodeType#IF} node is its {@link DiffNode#getDirectFeatureMapping direct feature mapping}.
749+
* The feature mapping of {@link NodeType#ELSE} and {@link NodeType#ELIF} nodes is determined by all formulas in the respective if-elif-else chain.
750+
* The feature mapping of an {@link NodeType#CODE artifact} node is the feature mapping of its parent.
751751
* See Equation (1) in our paper (+ its extension to time for variation tree diffs described in Section 3.1).
752752
* @return The feature mapping of this node for the given parent edges.
753753
*/
@@ -757,9 +757,9 @@ public Node getBeforeFeatureMapping() {
757757

758758
/**
759759
* Returns the full feature mapping formula of this node after the edit.
760-
* The feature mapping of an {@link CodeType#IF} node is its {@link DiffNode#getDirectFeatureMapping direct feature mapping}.
761-
* The feature mapping of {@link CodeType#ELSE} and {@link CodeType#ELIF} nodes is determined by all formulas in the respective if-elif-else chain.
762-
* The feature mapping of an {@link CodeType#CODE artifact} node is the feature mapping of its parent.
760+
* The feature mapping of an {@link NodeType#IF} node is its {@link DiffNode#getDirectFeatureMapping direct feature mapping}.
761+
* The feature mapping of {@link NodeType#ELSE} and {@link NodeType#ELIF} nodes is determined by all formulas in the respective if-elif-else chain.
762+
* The feature mapping of an {@link NodeType#CODE artifact} node is the feature mapping of its parent.
763763
* See Equation (1) in our paper (+ its extension to time for variation tree diffs described in Section 3.1).
764764
* @return The feature mapping of this node for the given parent edges.
765765
*/
@@ -928,57 +928,57 @@ public DiffType getDiffType() {
928928

929929
/**
930930
* Returns true if this node represents an ELIF macro.
931-
* @see CodeType#ELIF
931+
* @see NodeType#ELIF
932932
*/
933933
public boolean isElif() {
934-
return this.codeType.equals(CodeType.ELIF);
934+
return this.nodeType.equals(NodeType.ELIF);
935935
}
936936

937937
/**
938938
* Returns true if this node represents a conditional annotation.
939-
* @see CodeType#IF
939+
* @see NodeType#IF
940940
*/
941941
public boolean isIf() {
942-
return this.codeType.equals(CodeType.IF);
942+
return this.nodeType.equals(NodeType.IF);
943943
}
944944

945945
/**
946946
* Returns true if this node is an artifact node.
947-
* @see CodeType#CODE
947+
* @see NodeType#CODE
948948
*/
949949
public boolean isCode() {
950-
return this.codeType.equals(CodeType.CODE);
950+
return this.nodeType.equals(NodeType.CODE);
951951
}
952952

953953
/**
954954
* Returns true if this node represents the end of an annotation block.
955955
* Such a node should not be part of any {@link DiffTree}.
956-
* @see CodeType#ENDIF
956+
* @see NodeType#ENDIF
957957
*/
958958
public boolean isEndif() {
959-
return this.codeType.equals(CodeType.ENDIF);
959+
return this.nodeType.equals(NodeType.ENDIF);
960960
}
961961

962962
/**
963963
* Returns true if this node represents an ELSE macro.
964-
* @see CodeType#ELSE
964+
* @see NodeType#ELSE
965965
*/
966966
public boolean isElse() {
967-
return this.codeType.equals(CodeType.ELSE);
967+
return this.nodeType.equals(NodeType.ELSE);
968968
}
969969

970970
/**
971-
* Returns true if this node is a root node (i.e., it has {@link CodeType#ROOT}.
971+
* Returns true if this node is a root node (i.e., it has {@link NodeType#ROOT}.
972972
*/
973973
public boolean isRoot() {
974-
return this.codeType.equals(CodeType.ROOT);
974+
return this.nodeType.equals(NodeType.ROOT);
975975
}
976976

977977
/**
978-
* Returns {@link CodeType#isMacro()} for this node's {@link DiffNode#codeType}.
978+
* Returns {@link NodeType#isMacro()} for this node's {@link DiffNode#nodeType}.
979979
*/
980980
public boolean isMacro() {
981-
return this.codeType.isMacro();
981+
return this.nodeType.isMacro();
982982
}
983983

984984
/**
@@ -999,13 +999,13 @@ public int getID() {
999999
id <<= ID_OFFSET;
10001000
id += diffType.ordinal();
10011001
id <<= ID_OFFSET;
1002-
id += codeType.ordinal();
1002+
id += nodeType.ordinal();
10031003
return id;
10041004
}
10051005

10061006
/**
10071007
* Reconstructs a node from the given id and sets the given label.
1008-
* An id uniquely determines a node's {@link DiffNode#codeType}, {@link DiffNode#diffType}, and {@link DiffLineNumber#inDiff line number in the diff}.
1008+
* An id uniquely determines a node's {@link DiffNode#nodeType}, {@link DiffNode#diffType}, and {@link DiffLineNumber#inDiff line number in the diff}.
10091009
* The almost-inverse function is {@link DiffNode#getID()} but the conversion is not lossless.
10101010
* @param id The id from which to reconstruct the node.
10111011
* @param label The label the node should have.
@@ -1014,13 +1014,13 @@ public int getID() {
10141014
public static DiffNode fromID(final int id, String label) {
10151015
final int lowestBitsMask = (1 << ID_OFFSET) - 1;
10161016

1017-
final int codeTypeOrdinal = id & lowestBitsMask;
1017+
final int nodeTypeOrdinal = id & lowestBitsMask;
10181018
final int diffTypeOrdinal = (id >> ID_OFFSET) & lowestBitsMask;
10191019
final int fromInDiff = (id >> (2*ID_OFFSET)) - 1;
10201020

10211021
return new DiffNode(
10221022
DiffType.values()[diffTypeOrdinal],
1023-
CodeType.values()[codeTypeOrdinal],
1023+
NodeType.values()[nodeTypeOrdinal],
10241024
new DiffLineNumber(fromInDiff, DiffLineNumber.InvalidLineNumber, DiffLineNumber.InvalidLineNumber),
10251025
DiffLineNumber.Invalid(),
10261026
null,
@@ -1117,7 +1117,7 @@ public String toTextDiff() {
11171117
// Add endif after macro
11181118
if (isMacro()) {
11191119
diff
1120-
.append(toTextDiffLine(this.diffType, List.of(CodeType.ENDIF.asMacroText())))
1120+
.append(toTextDiffLine(this.diffType, List.of(NodeType.ENDIF.asMacroText())))
11211121
.append(StringUtils.LINEBREAK);
11221122
}
11231123

@@ -1128,11 +1128,11 @@ public String toTextDiff() {
11281128
public String toString() {
11291129
String s;
11301130
if (isCode()) {
1131-
s = String.format("%s_%s from %d to %d", diffType, codeType, from.inDiff, to.inDiff);
1131+
s = String.format("%s_%s from %d to %d", diffType, nodeType, from.inDiff, to.inDiff);
11321132
} else if (isRoot()) {
11331133
s = "ROOT";
11341134
} else {
1135-
s = String.format("%s_%s from %d to %d with \"%s\"", diffType, codeType,
1135+
s = String.format("%s_%s from %d to %d with \"%s\"", diffType, nodeType,
11361136
from.inDiff, to.inDiff, featureMapping);
11371137
}
11381138
return s;
@@ -1143,7 +1143,7 @@ public boolean equals(Object o) {
11431143
if (this == o) return true;
11441144
if (o == null || getClass() != o.getClass()) return false;
11451145
DiffNode diffNode = (DiffNode) o;
1146-
return isMultilineMacro == diffNode.isMultilineMacro && diffType == diffNode.diffType && codeType == diffNode.codeType && from.equals(diffNode.from) && to.equals(diffNode.to) && Objects.equals(featureMapping, diffNode.featureMapping) && lines.equals(diffNode.lines);
1146+
return isMultilineMacro == diffNode.isMultilineMacro && diffType == diffNode.diffType && nodeType == diffNode.nodeType && from.equals(diffNode.from) && to.equals(diffNode.to) && Objects.equals(featureMapping, diffNode.featureMapping) && lines.equals(diffNode.lines);
11471147
}
11481148

11491149
/**
@@ -1156,6 +1156,6 @@ public boolean equals(Object o) {
11561156
*/
11571157
@Override
11581158
public int hashCode() {
1159-
return Objects.hash(diffType, codeType, isMultilineMacro, from, to, featureMapping, lines);
1159+
return Objects.hash(diffType, nodeType, isMultilineMacro, from, to, featureMapping, lines);
11601160
}
11611161
}

src/main/java/org/variantsync/diffdetective/diff/difftree/DiffTree.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static DiffResult<DiffTree> fromDiff(final String diff, boolean collapseM
7373
* So just lines preceded by "+", "-", or " " are expected.
7474
* @param p Path to a diff file.
7575
* @param collapseMultipleCodeLines Set to true if subsequent lines of source code with
76-
* the same {@link CodeType type of change} should be
76+
* the same {@link NodeType type of change} should be
7777
* collapsed into a single source code node representing
7878
* all lines at once.
7979
* @param ignoreEmptyLines Set to true if empty lines should not be included in the DiffTree.
@@ -95,7 +95,7 @@ public static DiffResult<DiffTree> fromFile(final Path p, boolean collapseMultip
9595
* So just lines preceded by "+", "-", or " " are expected.
9696
* @param diff The diff as text. Lines should be separated by a newline character. Each line should be preceded by either "+", "-", or " ".
9797
* @param collapseMultipleCodeLines Set to true if subsequent lines of source code with
98-
* the same {@link CodeType type of change} should be
98+
* the same {@link NodeType type of change} should be
9999
* collapsed into a single source code node representing
100100
* all lines at once.
101101
* @param ignoreEmptyLines Set to true if empty lines should not be included in the DiffTree.

src/main/java/org/variantsync/diffdetective/diff/difftree/CodeType.java renamed to src/main/java/org/variantsync/diffdetective/diff/difftree/NodeType.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* The type of nodes in a {@link DiffTree}.
88
* Corresponds to the tau function from our paper.
99
*/
10-
public enum CodeType {
10+
public enum NodeType {
1111
// Mapping types
1212
IF("if"),
1313
ENDIF("endif"),
@@ -21,32 +21,32 @@ public enum CodeType {
2121
ROOT("ROOT");
2222

2323
public final String name;
24-
CodeType(String name) {
24+
NodeType(String name) {
2525
this.name = name;
2626
}
2727

2828
/**
29-
* Returns true iff this code type represents a conditional feature annotation (i.e., if or elif).
29+
* Returns true iff this node type represents a conditional feature annotation (i.e., if or elif).
3030
*/
3131
public boolean isConditionalMacro() {
3232
return this == IF || this == ELIF;
3333
}
3434

3535
/**
36-
* Returns true iff this code type represents a feature mapping.
36+
* Returns true iff this node type represents a feature mapping.
3737
*/
38-
public boolean isMacro() {
38+
public boolean isAnnotation() {
3939
return this != ROOT && this != CODE;
4040
}
4141

4242
final static Pattern annotationRegex = Pattern.compile("^[+-]?\\s*#\\s*(if|endif|else|elif)");
4343

4444
/**
45-
* Parses the code type from a line taken from a text-based diff.
45+
* Parses the node type from a line taken from a text-based diff.
4646
* @param line A line in a patch.
4747
* @return The type of edit of <code>line</code>.
4848
*/
49-
public static CodeType ofDiffLine(String line) {
49+
public static NodeType ofDiffLine(String line) {
5050
Matcher matcher = annotationRegex.matcher(line);
5151
if (matcher.find()) {
5252
String id = matcher.group(1);
@@ -65,19 +65,19 @@ public static CodeType ofDiffLine(String line) {
6565
}
6666

6767
/**
68-
* Creates a CodeType from its value names.
68+
* Creates a NodeType from its value names.
6969
* @see Enum#name()
7070
* @param name a string that equals the name of one value of this enum (ignoring case)
71-
* @return The CodeType that has the given name
71+
* @return The NodeType that has the given name
7272
*/
73-
public static CodeType fromName(final String name) {
74-
for (CodeType candidate : values()) {
73+
public static NodeType fromName(final String name) {
74+
for (NodeType candidate : values()) {
7575
if (candidate.toString().equalsIgnoreCase(name)) {
7676
return candidate;
7777
}
7878
}
7979

80-
throw new IllegalArgumentException("Given string \"" + name + "\" is not the name of a CodeType.");
80+
throw new IllegalArgumentException("Given string \"" + name + "\" is not the name of a NodeType.");
8181
}
8282

8383
/**

0 commit comments

Comments
 (0)