Skip to content

Commit 9a04f36

Browse files
refactor: rename EccoNode to ASTNode
1 parent a770e4f commit 9a04f36

10 files changed

Lines changed: 269 additions & 144 deletions

File tree

src/main/java/de/hub/mse/variantsync/boosting/TraceBoosting.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import de.hub.mse.variantsync.boosting.ecco.*;
66
import de.hub.mse.variantsync.boosting.ecco.Module;
77
import de.hub.mse.variantsync.boosting.parsing.*;
8-
import de.hub.mse.variantsync.boosting.position.*;
98
import de.hub.mse.variantsync.boosting.product.*;
109

1110
import org.logicng.formulas.FType;
@@ -387,10 +386,10 @@ private static void sortOutputFiles(final String outputFolder) {
387386
* which the node
388387
* appears does not have the same mapping)
389388
*/
390-
private static String getTrace(final EccoNode astNode, final Formula mapping) {
389+
private static String getTrace(final ASTNode astNode, final Formula mapping) {
391390
final String result;
392-
if (astNode.getType() != EccoNode.NODE_TYPE.CLASS_OR_INTERFACE_DECLARATION
393-
&& astNode.getType() != EccoNode.NODE_TYPE.METHOD_DECLARATION) {
391+
if (astNode.getType() != ASTNode.NODE_TYPE.CLASS_OR_INTERFACE_DECLARATION
392+
&& astNode.getType() != ASTNode.NODE_TYPE.METHOD_DECLARATION) {
394393
// node could possibly be a refinement
395394
result = getName(" Refinement", astNode, false, mapping);
396395
} else {
@@ -399,7 +398,7 @@ private static String getTrace(final EccoNode astNode, final Formula mapping) {
399398
return result;
400399
}
401400

402-
private static String getName(String suffix, final EccoNode astNode, boolean insideClass,
401+
private static String getName(String suffix, final ASTNode astNode, boolean insideClass,
403402
final Formula mapping) {
404403
if (astNode.getParent() != null) {
405404
String missing_blank_space = "";
@@ -442,7 +441,7 @@ private static String getName(String suffix, final EccoNode astNode, boolean ins
442441
public void evaluate(final AbstractAST mainTree, final String outputFolder) {
443442
Logger.info("start evaluation");
444443
final Map<String, List<String>> fileToTraceMap = new HashMap<>();
445-
for (final EccoNode astNode : mainTree.getAstNodes()) {
444+
for (final ASTNode astNode : mainTree.getAstNodes()) {
446445
final EccoSet<Formula> mappings = astNode.getMappings();
447446
for (final Formula mapping : mappings) {
448447
// if the mapping is "TRUE"
@@ -508,7 +507,7 @@ public MainTree computeEcco() {
508507
}
509508

510509
// now put mappings from associations back on individual nodes
511-
for (final EccoNode node : association.getAstNodes()) {
510+
for (final ASTNode node : association.getAstNodes()) {
512511
if (node.getMapping() == null) {
513512
node.setMapping(association.getMapping());
514513
}
@@ -527,7 +526,7 @@ private void assignProactiveTraces(EccoSet<Association> associations) {
527526
// Formula does not implement equals and hashCode; we have to use Strings to
528527
// store them :(
529528
Map<String, Formula> existingMappings = new HashMap<>();
530-
for (EccoNode node : assoc.getAstNodes()) {
529+
for (ASTNode node : assoc.getAstNodes()) {
531530
var mapping = node.getMapping();
532531
if (mapping != null) {
533532
existingMappings.putIfAbsent(mapping.toString(), mapping);
@@ -721,7 +720,7 @@ public EccoSet<Association> traceExtractionAlgorithm(final MainTree mainTree) {
721720
association.getAstNodes());
722721

723722
// Intersect ASTs
724-
final EccoSet<EccoNode> intNodes = updatedAssociation.getAstNodes().intersect(aNew.getAstNodes());
723+
final EccoSet<ASTNode> intNodes = updatedAssociation.getAstNodes().intersect(aNew.getAstNodes());
725724

726725
// compute intersection
727726
final Association aInt = new Association(

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

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

14-
public class EccoNode implements Serializable {
14+
public class ASTNode implements Serializable {
1515

1616
public enum NODE_TYPE {
1717
ROOT, FOLDER, FILE, LINE, DEFAULT,
@@ -22,15 +22,15 @@ public enum NODE_TYPE {
2222
}
2323

2424
private final String code;
25-
private EccoNode parent;
26-
private final EccoSet<EccoNode> children;
25+
private ASTNode parent;
26+
private final EccoSet<ASTNode> children;
2727
private final NODE_TYPE type;
2828
private transient Position startPosition;
2929
private transient Formula mapping;
30-
private EccoNode productEquivalent;
30+
private ASTNode productEquivalent;
3131
private int sequenceNumber = 0;
3232

33-
public EccoNode(final EccoNode parent, final String code, final Position position, final NODE_TYPE type,
33+
public ASTNode(final ASTNode parent, final String code, final Position position, final NODE_TYPE type,
3434
final Formula mapping) {
3535
this.parent = parent;
3636
this.code = code;
@@ -50,21 +50,21 @@ public EccoNode(final EccoNode parent, final String code, final Position positio
5050
* Correct matching of the sequence numbers would require further investigation
5151
* of the nodes' children and was omitted here.
5252
*/
53-
public void addChild(final EccoNode child) {
53+
public void addChild(final ASTNode child) {
5454
while (!children.add(child)) {
5555
child.sequenceNumber += 1;
5656
}
5757
}
5858

59-
public void setProductEquivalent(final EccoNode productEquivalent) {
59+
public void setProductEquivalent(final ASTNode productEquivalent) {
6060
this.productEquivalent = productEquivalent;
6161
}
6262

63-
public EccoNode getProductEquivalent() {
63+
public ASTNode getProductEquivalent() {
6464
return this.productEquivalent;
6565
}
6666

67-
public boolean isSimilar(final EccoNode eccoNode) {
67+
public boolean isSimilar(final ASTNode eccoNode) {
6868
if (this == eccoNode)
6969
return true;
7070
if (eccoNode == null || getClass() != eccoNode.getClass())
@@ -91,7 +91,7 @@ private String getAncestorCode() {
9191
}
9292
}
9393

94-
private boolean similarParent(final EccoNode other) {
94+
private boolean similarParent(final ASTNode other) {
9595
if (this.parent == other.parent)
9696
return true;
9797
if (this.parent == null || this.parent.getClass() != other.parent.getClass())
@@ -101,15 +101,15 @@ private boolean similarParent(final EccoNode other) {
101101
this.parent.sequenceNumber == other.parent.sequenceNumber;
102102
}
103103

104-
public EccoNode getParent() {
104+
public ASTNode getParent() {
105105
return parent;
106106
}
107107

108-
public void setParent(final EccoNode parent) {
108+
public void setParent(final ASTNode parent) {
109109
this.parent = parent;
110110
}
111111

112-
public EccoSet<EccoNode> getChildren() {
112+
public EccoSet<ASTNode> getChildren() {
113113
return children;
114114
}
115115

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

Lines changed: 130 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,32 @@
44

55
import java.util.*;
66

7+
/**
8+
* Represents an association between modules and AST nodes.
9+
* An association consists of the following components:
10+
* - A set of AST nodes (astNodes) representing the code elements involved in
11+
* the association
12+
* - Three sets of modules (min, all, max) representing the minimum, all, and
13+
* maximum products in which the association appears
14+
* - A set of modules (not) representing the products in which the association
15+
* does not appear
16+
* - A boolean flag (isBasic) indicating whether the association appears in all
17+
* products
18+
* - A formula (mapping) representing the mapping between the modules and AST
19+
* nodes
20+
*
21+
* This class provides methods for accessing and modifying the components of the
22+
* association, such as:
23+
* - Getting and setting the AST nodes, modules, and mapping
24+
* - Removing specific AST nodes from the association
25+
* - Getting the smallest modules in the association based on their size
26+
* - Checking if the association is basic
27+
*
28+
* The equals and hashCode methods are overridden to ensure proper comparison of
29+
* association objects based on their components.
30+
*/
731
public class Association {
8-
private EccoSet<EccoNode> astNodes;
32+
private EccoSet<ASTNode> astNodes;
933
private EccoSet<Module> min;
1034
private EccoSet<Module> all;
1135
private EccoSet<Module> max;
@@ -14,8 +38,18 @@ public class Association {
1438
// isBasic tells whether the code of the association appears in all products
1539
private boolean isBasic;
1640

41+
/**
42+
* Constructs a new Association with the specified sets of modules and AST
43+
* nodes.
44+
*
45+
* @param min the minimum set of modules
46+
* @param all the set of all modules
47+
* @param max the maximum set of modules
48+
* @param not the set of modules that are not in the association
49+
* @param astNodes the set of AST nodes associated with the modules
50+
*/
1751
public Association(final EccoSet<Module> min, final EccoSet<Module> all, final EccoSet<Module> max,
18-
final EccoSet<Module> not, final EccoSet<EccoNode> astNodes) {
52+
final EccoSet<Module> not, final EccoSet<ASTNode> astNodes) {
1953
this.min = new EccoSet<>(min);
2054
this.all = new EccoSet<>(all);
2155
this.max = new EccoSet<>(max);
@@ -44,46 +78,110 @@ public int hashCode() {
4478
return Objects.hash(astNodes, min, all, max, not);
4579
}
4680

47-
public EccoSet<EccoNode> getAstNodes() {
81+
/**
82+
* Returns the set of AST nodes contained in this EccoSet.
83+
*
84+
* @return EccoSet<EccoNode> - a set of EccoNode objects representing the AST
85+
* nodes
86+
*/
87+
public EccoSet<ASTNode> getAstNodes() {
4888
return astNodes;
4989
}
5090

51-
public void removeNodes(final EccoSet<EccoNode> toRemove) {
91+
/**
92+
* Removes the specified nodes from the current set of AST nodes.
93+
*
94+
* @param toRemove The set of nodes to be removed from the current set of AST
95+
* nodes.
96+
* @throws NullPointerException if the specified set of nodes to be removed is
97+
* null.
98+
*/
99+
public void removeNodes(final EccoSet<ASTNode> toRemove) {
100+
if (toRemove == null) {
101+
throw new NullPointerException("The specified set of nodes to be removed cannot be null.");
102+
}
103+
52104
astNodes = astNodes.without(toRemove);
53105
}
54106

107+
/**
108+
* Returns the feature mapping formula associated with this object.
109+
*
110+
* @return the mapping formula
111+
*/
55112
public Formula getMapping() {
56113
return mapping;
57114
}
58115

116+
/**
117+
* Sets the feature mapping for the association.
118+
*
119+
* @param mapping the formula to set as the mapping
120+
*/
59121
public void setMapping(final Formula mapping) {
60122
this.mapping = mapping;
61123
}
62124

125+
/**
126+
* Returns the set of min modules.
127+
*
128+
* @return the min modules
129+
*/
63130
public EccoSet<Module> getMin() {
64131
return min;
65132
}
66133

134+
/**
135+
* Returns the set off all modules.
136+
*
137+
* @return the all modules
138+
*/
67139
public EccoSet<Module> getAll() {
68140
return all;
69141
}
70142

143+
/**
144+
* Returns the set of max module.
145+
*
146+
* @return the max modules
147+
*/
71148
public EccoSet<Module> getMax() {
72149
return max;
73150
}
74151

152+
/**
153+
* Returns the set of not modules.
154+
*
155+
* @return the not modules
156+
*/
75157
public EccoSet<Module> getNot() {
76158
return not;
77159
}
78160

161+
/**
162+
* Returns a list of the smallest min modules.
163+
*
164+
* @return List<Module> The list of smallest min modules
165+
*/
79166
public List<Module> getSmallestMinModules() {
80167
return getSmallestModules(this.min);
81168
}
82169

170+
/**
171+
* Returns a list of the smallest max modules.
172+
*
173+
* @return List<Module> The list of smallest max modules
174+
*/
83175
public List<Module> getSmallestMaxModules() {
84176
return getSmallestModules(this.max);
85177
}
86178

179+
/**
180+
* Returns a list of the smallest modules from the given EccoSet of modules.
181+
*
182+
* @param modules the EccoSet of modules to search for the smallest ones
183+
* @return a list of the smallest modules from the given EccoSet
184+
*/
87185
private List<Module> getSmallestModules(final EccoSet<Module> modules) {
88186
final List<Module> result = new LinkedList<>();
89187
int size = Integer.MAX_VALUE;
@@ -101,27 +199,55 @@ private List<Module> getSmallestModules(final EccoSet<Module> modules) {
101199
return result;
102200
}
103201

202+
/**
203+
* Sets the min modules.
204+
*
205+
* @param min a set of min modules
206+
*/
104207
public void setMin(final EccoSet<Module> min) {
105208
this.min = min;
106209
}
107210

211+
/**
212+
* Sets the all modules.
213+
*
214+
* @param all a set of all modules
215+
*/
108216
public void setAll(final EccoSet<Module> all) {
109217
this.all = all;
110218
}
111219

220+
/**
221+
* Sets the max modules.
222+
*
223+
* @param max a set of max modules
224+
*/
112225
public void setMax(final EccoSet<Module> max) {
113226
this.max = max;
114227
}
115228

229+
/**
230+
* Sets the not modules.
231+
*
232+
* @param not a set of not modules
233+
*/
116234
public void setNot(final EccoSet<Module> not) {
117235
this.not = not;
118236
}
119237

238+
/**
239+
* Define this association as tracking base code.
240+
*/
120241
public void setBasic(final Boolean basicCode) {
121242
this.isBasic = basicCode;
122243
}
123244

245+
/**
246+
* Returns whether the association tracks base code.
247+
*
248+
*/
124249
public boolean isBasic() {
125250
return isBasic;
126251
}
252+
127253
}

0 commit comments

Comments
 (0)