Skip to content

Commit b278870

Browse files
docs: add JavaDocs for ecco-related classes
1 parent 9a04f36 commit b278870

5 files changed

Lines changed: 173 additions & 6 deletions

File tree

src/main/java/de/hub/mse/variantsync/boosting/ecco/ASTNode.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
import java.io.*;
1212
import java.util.Objects;
1313

14+
/**
15+
* Represents a node in an Abstract Syntax Tree (AST).
16+
*
17+
* Each ASTNode contains information about a specific code element, such as a
18+
* class, method, or statement.
19+
*
20+
*/
1421
public class ASTNode implements Serializable {
1522

1623
public enum NODE_TYPE {
@@ -30,6 +37,16 @@ public enum NODE_TYPE {
3037
private ASTNode productEquivalent;
3138
private int sequenceNumber = 0;
3239

40+
/**
41+
* Constructs a new ASTNode with the specified parameters.
42+
*
43+
* @param parent The parent ASTNode of this node. Can be null if this node is
44+
* the root of the AST.
45+
* @param code The code snippet represented by this node.
46+
* @param position The position of the code snippet in the source file.
47+
* @param type The type of the code element represented by this node.
48+
* @param mapping The formula mapping associated with this node.
49+
*/
3350
public ASTNode(final ASTNode parent, final String code, final Position position, final NODE_TYPE type,
3451
final Formula mapping) {
3552
this.parent = parent;
@@ -56,14 +73,27 @@ public void addChild(final ASTNode child) {
5673
}
5774
}
5875

76+
/**
77+
* Sets the equivalent node of this node.
78+
*
79+
* @param productEquivalent the equivalent AST node
80+
*/
5981
public void setProductEquivalent(final ASTNode productEquivalent) {
6082
this.productEquivalent = productEquivalent;
6183
}
6284

85+
/**
86+
* Gets the equivalent node of this node.
87+
*/
6388
public ASTNode getProductEquivalent() {
6489
return this.productEquivalent;
6590
}
6691

92+
/**
93+
* Checks whether the given ASTNode is similar to this one.
94+
*
95+
* @param eccoNode another ASTNode object
96+
*/
6797
public boolean isSimilar(final ASTNode eccoNode) {
6898
if (this == eccoNode)
6999
return true;
@@ -75,6 +105,9 @@ public boolean isSimilar(final ASTNode eccoNode) {
75105
sequenceNumber == eccoNode.sequenceNumber;
76106
}
77107

108+
/**
109+
* @return the code associated with this ASTNode
110+
*/
78111
public String getCode() {
79112
return code;
80113
}
@@ -101,18 +134,30 @@ private boolean similarParent(final ASTNode other) {
101134
this.parent.sequenceNumber == other.parent.sequenceNumber;
102135
}
103136

137+
/**
138+
* @return the parent of this ASTNode
139+
*/
104140
public ASTNode getParent() {
105141
return parent;
106142
}
107143

144+
/**
145+
* Sets the parent of this ASTNode in the AST.
146+
*/
108147
public void setParent(final ASTNode parent) {
109148
this.parent = parent;
110149
}
111150

151+
/**
152+
* Returns a set of this node's child nodes.
153+
*/
112154
public EccoSet<ASTNode> getChildren() {
113155
return children;
114156
}
115157

158+
/**
159+
* Return the position (file, line) where the content of this node starts.
160+
*/
116161
public Position getStartPosition() {
117162
if (productEquivalent != null) {
118163
return productEquivalent.startPosition;
@@ -121,8 +166,10 @@ public Position getStartPosition() {
121166
}
122167
}
123168

124-
// return set of all possible mappings (if the mapping is a DNF formula, each
125-
// clause is a possible mapping on its own)
169+
/**
170+
* Returns set set of all possible mappings (if the mapping is a DNF formula,
171+
* each clause is a possible mapping on its own) for this node.
172+
*/
126173
public EccoSet<Formula> getMappings() {
127174
final EccoSet<Formula> mappings = new EccoSet<>();
128175
if (mapping.type() == FType.OR) {
@@ -135,15 +182,17 @@ public EccoSet<Formula> getMappings() {
135182
return mappings;
136183
}
137184

138-
// return whole mapping as a formula
185+
/** Returns the best mapping as a formula */
139186
public Formula getMapping() {
140187
return mapping;
141188
}
142189

190+
/** Sets a specific mapping for this node */
143191
public void setMapping(final Formula mapping) {
144192
this.mapping = mapping;
145193
}
146194

195+
/** Gets the type of this node */
147196
public NODE_TYPE getType() {
148197
return type;
149198
}

src/main/java/de/hub/mse/variantsync/boosting/ecco/EccoSet.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,31 @@
33
import java.util.Collection;
44
import java.util.HashSet;
55

6+
/**
7+
* A custom set implementation to handle sets similar to how they are defined by
8+
* ECCO.
9+
*/
610
public class EccoSet<E> extends HashSet<E> {
711

12+
/**
13+
* Constructs a new EccoSet with no elements.
14+
*/
815
public EccoSet() {
916
super();
1017
}
1118

19+
/**
20+
* Constructs a new EccoSet with the elements from the specified collection.
21+
*
22+
* @param elements the collection of elements to initialize the set with
23+
* @throws NullPointerException if the specified collection is null
24+
*/
1225
public EccoSet(final Collection<E> elements) {
1326
super(elements);
1427
}
1528

1629
/**
17-
* replaces an equivalent element in the set with a new version of it
30+
* Replaces an equivalent element in the set with a new version of it
1831
*/
1932
public void overwrite(final E element) {
2033
this.remove(element);
@@ -108,6 +121,9 @@ public boolean equals(final Object o) {
108121
return super.equals(o);
109122
}
110123

124+
/**
125+
* Returns the power set of this set.
126+
*/
111127
public EccoSet<EccoSet<E>> powerSet() {
112128
return powerSet(this);
113129
}

src/main/java/de/hub/mse/variantsync/boosting/ecco/Feature.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,42 @@
33
import java.io.Serializable;
44
import java.util.Objects;
55

6+
/**
7+
* Represents a feature with a name.
8+
*
9+
* This class implements the Comparable interface to allow for comparison of
10+
* Feature objects based on their names.
11+
*
12+
* @param name the name of the feature
13+
*/
614
public class Feature implements Comparable<Feature>, Serializable {
715

816
private final String name;
917

18+
/**
19+
* Constructs a new Feature object with the given name.
20+
*
21+
* @param name the name of the feature
22+
*/
1023
public Feature(final String name) {
1124
this.name = name;
1225
}
1326

27+
/**
28+
* Returns the name of the feature.
29+
*
30+
* @return the name of the feature
31+
*/
1432
public String getName() {
1533
return name;
1634
}
1735

36+
/**
37+
* Compares this Feature object with the specified object for equality.
38+
*
39+
* @param o the object to compare with
40+
* @return true if the objects are equal, false otherwise
41+
*/
1842
@Override
1943
public boolean equals(final Object o) {
2044
if (this == o)
@@ -25,11 +49,23 @@ public boolean equals(final Object o) {
2549
return name.equals(feature.name);
2650
}
2751

52+
/**
53+
* Returns a hash code value for the Feature object.
54+
*
55+
* @return the hash code value for the object
56+
*/
2857
@Override
2958
public int hashCode() {
3059
return Objects.hash(name);
3160
}
3261

62+
/**
63+
* Compares this Feature object with the specified Feature object for order.
64+
*
65+
* @param other the Feature object to compare with
66+
* @return a negative integer, zero, or a positive integer as this object is
67+
* less than, equal to, or greater than the specified object
68+
*/
3369
public int compareTo(final Feature other) {
3470
return name.compareTo(other.name);
3571
}

src/main/java/de/hub/mse/variantsync/boosting/ecco/MainTree.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,35 @@
1111
import java.io.Serializable;
1212
import java.util.*;
1313

14+
/**
15+
* Represents the merged AST of several product ASTs.
16+
*/
1417
public class MainTree implements Serializable {
1518

1619
private final AbstractAST tree;
1720
private final Map<ASTNode, Set<ProductPosition>> positionMap;
1821
private Map<ProductPosition, ASTNode> inversePositionMap;
1922

23+
/**
24+
* Constructs a MainTree object with the given AbstractAST tree.
25+
*
26+
* @param tree the AbstractAST tree to be set for this MainTree
27+
*/
2028
public MainTree(final AbstractAST tree) {
2129
this.tree = tree;
2230
positionMap = new HashMap<>();
2331
inversePositionMap = null;
2432
}
2533

26-
// merge this AST into another AST (main tree) and return the set of all nodes
27-
// in the resulting main tree corresponding to the nodes of this AST
34+
/**
35+
* Merge this Abstract Syntax Tree (AST) into another AST (main tree) and return
36+
* the set of all nodes
37+
* in the resulting main tree corresponding to the nodes of this AST.
38+
*
39+
* @param product The product containing the main tree to merge this AST into.
40+
* @return The set of all nodes in the resulting main tree corresponding to the
41+
* nodes of this AST.
42+
*/
2843
public EccoSet<ASTNode> unite(final Product product) {
2944
final EccoSet<ASTNode> result = new EccoSet<>();
3045
uniteChildren(result, product.getProductAst().getRoot(), tree.getRoot(), product);
@@ -104,6 +119,14 @@ private void addAllSubNodes(final EccoSet<ASTNode> result, final ASTNode mainTre
104119
}
105120
}
106121

122+
/**
123+
* Retrieves the mapping formula associated with a given product position.
124+
*
125+
* @param position The product position for which to retrieve the mapping
126+
* formula
127+
* @return The mapping formula associated with the given product position
128+
* @throws NullPointerException if the inversePositionMap is not initialized
129+
*/
107130
public Formula getMapping(final ProductPosition position) {
108131
if (inversePositionMap == null) {
109132
initializeInversePositionMap();
@@ -120,10 +143,21 @@ private void initializeInversePositionMap() {
120143
}
121144
}
122145

146+
/**
147+
* Retrieves the set of ProductPositions associated with the given ASTNode.
148+
*
149+
* @param node the ASTNode for which to retrieve the ProductPositions
150+
* @return a Set of ProductPositions associated with the given ASTNode
151+
*/
123152
public Set<ProductPosition> getProductPositions(final ASTNode node) {
124153
return positionMap.get(node);
125154
}
126155

156+
/**
157+
* Retrieves the AbstractAST tree associated with this MainTree.
158+
*
159+
* @return the AbstractAST tree associated with this object
160+
*/
127161
public AbstractAST getTree() {
128162
return this.tree;
129163
}

src/main/java/de/hub/mse/variantsync/boosting/ecco/Module.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,30 @@
44

55
import java.util.Objects;
66

7+
/**
8+
* A class representing a module in ECCO.
9+
*
10+
* This class encapsulates a set of literals and provides methods for comparing
11+
* modules and retrieving information about the literals it contains.
12+
*/
713
public class Module {
814
private final EccoSet<Literal> literals;
915

16+
/**
17+
* Constructs a new Module with the given set of literals.
18+
*
19+
* @param literals The set of literals to be contained in the module
20+
*/
1021
public Module(final EccoSet<Literal> literals) {
1122
this.literals = literals;
1223
}
1324

25+
/**
26+
* Compares this Module with the specified object for equality.
27+
*
28+
* @param o The object to compare this Module with
29+
* @return true if the specified object is equal to this Module, false otherwise
30+
*/
1431
@Override
1532
public boolean equals(final Object o) {
1633
if (this == o)
@@ -21,15 +38,30 @@ public boolean equals(final Object o) {
2138
return Objects.equals(literals, module.literals);
2239
}
2340

41+
/**
42+
* Returns a hash code value for the Module.
43+
*
44+
* @return A hash code value for this Module
45+
*/
2446
@Override
2547
public int hashCode() {
2648
return Objects.hash(literals);
2749
}
2850

51+
/**
52+
* Returns the set of literals contained in this Module.
53+
*
54+
* @return The set of literals contained in this Module
55+
*/
2956
public EccoSet<Literal> getLiterals() {
3057
return literals;
3158
}
3259

60+
/**
61+
* Returns the number of literals in this Module.
62+
*
63+
* @return The number of literals in this Module
64+
*/
3365
public int size() {
3466
return literals.size();
3567
}

0 commit comments

Comments
 (0)