Skip to content

Commit d2176a4

Browse files
feat: extract the type of each line (e.g., artifact, if, else, endif)
1 parent c92a438 commit d2176a4

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

src/main/java/org/variantsync/vevos/extraction/analysis/VariabilityAnalysis.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,20 @@ static void analyzeNode(FileGT.Mutable fileGT, DiffNode<DiffLinesLabel> node, Ti
7171
}
7272

7373
for (int lineNumber = fromLine; lineNumber < toLine; lineNumber++) {
74-
LineAnnotation existingAnnotation = fileGT.get(lineNumber - 1);
74+
LineAnnotation existingAnnotation = fileGT.get(lineNumber);
7575
if (existingAnnotation != null && existingAnnotation.nodeType().equals("artifact") && node.isAnnotation()) {
7676
// Never overwrite artifact pcs with annotation pcs
7777
continue;
7878
}
79-
LineAnnotation annotation;
80-
if (node.isAnnotation() && ignorePCChanges) {
81-
// We set the PC and Mapping of all macro lines to '0', i.e., 'false
82-
annotation = new LineAnnotation(lineNumber,
83-
new FeatureMapping("0"), new PresenceCondition("0"),
84-
node.getNodeType().name, presenceCondition.getUniqueContainedFeatures());
85-
} else {
86-
annotation = new LineAnnotation(lineNumber,
87-
new FeatureMapping(featureMapping.toString()), new PresenceCondition(presenceCondition.toString()),
88-
node.getNodeType().name, presenceCondition.getUniqueContainedFeatures());
79+
String nodeType = node.getNodeType().name;
80+
if (node.isAnnotation() && lineNumber == toLine - 1) {
81+
// The last line of any annotation is the 'endif'
82+
// If it is an else, or elif, it will be overwritten by the next node
83+
nodeType = "endif";
8984
}
85+
LineAnnotation annotation = new LineAnnotation(lineNumber,
86+
new FeatureMapping(featureMapping.toString()), new PresenceCondition(presenceCondition.toString()),
87+
nodeType, presenceCondition.getUniqueContainedFeatures());
9088
fileGT.insert(annotation);
9189
}
9290
}

src/main/java/org/variantsync/vevos/extraction/gt/BlockAnnotation.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ public final class BlockAnnotation implements Serializable {
2323
private final PresenceCondition presenceCondition;
2424
private int lineStartInclusive;
2525
private int lineEndInclusive;
26+
private String nodeType;
2627

2728
public BlockAnnotation(int lineStartInclusive, int lineEndInclusive,
28-
FeatureMapping featureMapping, PresenceCondition presenceCondition) {
29+
FeatureMapping featureMapping, PresenceCondition presenceCondition,
30+
String nodeType) {
2931
this.lineStartInclusive = lineStartInclusive;
3032
this.lineEndInclusive = lineEndInclusive;
3133
this.featureMapping = featureMapping;
3234
this.presenceCondition = presenceCondition;
35+
this.nodeType = nodeType;
3336
}
3437

3538
public void setLineStartInclusive(int lineStartInclusive) {
@@ -48,6 +51,8 @@ public int lineEndExclusive() {
4851
return lineEndInclusive;
4952
}
5053

54+
public String nodeType() {return nodeType;}
55+
5156
@Override
5257
public boolean equals(Object o) {
5358
if (this == o) return true;
@@ -56,36 +61,41 @@ public boolean equals(Object o) {
5661
return lineStartInclusive == that.lineStartInclusive
5762
&& lineEndInclusive == that.lineEndInclusive
5863
&& Objects.equals(featureMapping, that.featureMapping)
59-
&& Objects.equals(presenceCondition, that.presenceCondition);
64+
&& Objects.equals(presenceCondition, that.presenceCondition)
65+
&& Objects.equals(nodeType, that.nodeType);
6066
}
6167

6268
@Override
6369
public int hashCode() {
64-
return Objects.hash(featureMapping, presenceCondition, lineStartInclusive, lineEndInclusive);
70+
return Objects.hash(featureMapping, presenceCondition, lineStartInclusive, lineEndInclusive, nodeType);
6571
}
6672

6773
public boolean annotationEquals(BlockAnnotation other) {
6874
return this.featureMapping.equals(other.featureMapping)
69-
&& this.presenceCondition.equals(other.presenceCondition);
75+
&& this.presenceCondition.equals(other.presenceCondition)
76+
&& this.nodeType.equals(other.nodeType);
7077
}
7178

7279
public boolean annotationEquals(LineAnnotation other) {
7380
return this.featureMapping.equals(other.featureMapping())
74-
&& this.presenceCondition.equals(other.presenceCondition());
81+
&& this.presenceCondition.equals(other.presenceCondition())
82+
&& this.nodeType.equals(other.nodeType());
7583
}
7684

7785
@Override
7886
public String toString() {
7987
return "[" +
8088
"lineStartInclusive=" + lineStartInclusive + ", " +
8189
"lineEndExclusive=" + lineEndInclusive + ", " +
90+
"nodeType=" + nodeType + ", " +
8291
"featureMapping=" + featureMapping + ", " +
8392
"presenceCondition=" + presenceCondition + ']';
8493
}
8594

8695
public String asCSVLine() {
87-
return "%s;%s;%d;%d".formatted(normalizeCondition(this.featureMapping.mapping()),
96+
return "%s;%s;%s;%d;%d".formatted(normalizeCondition(this.featureMapping.mapping()),
8897
normalizeCondition(this.presenceCondition.condition()),
98+
this.nodeType,
8999
this.lineStartInclusive,
90100
this.lineEndInclusive);
91101
}

src/main/java/org/variantsync/vevos/extraction/gt/FileGT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private static String csvMatchingLines(Complete complete) {
274274
private static ArrayList<BlockAnnotation> aggregateBlocks(Complete complete) {
275275
ArrayList<BlockAnnotation> blocks = new ArrayList<>();
276276
// The root annotation is always true and covers all lines
277-
BlockAnnotation rootBlock = new BlockAnnotation(1, complete.size(), new FeatureMapping("True"), new PresenceCondition("True"));
277+
BlockAnnotation rootBlock = new BlockAnnotation(1, complete.size(), new FeatureMapping("True"), new PresenceCondition("True"), "ROOT");
278278

279279
LinkedList<BlockAnnotation> blockStack = new LinkedList<>();
280280
blockStack.push(rootBlock);
@@ -312,7 +312,7 @@ private static ArrayList<BlockAnnotation> aggregateBlocks(Complete complete) {
312312
// If the current line is in a new block
313313
if (annotationChange) {
314314
// Push a new block onto the stack
315-
blockStack.push(new BlockAnnotation(line.lineNumber(), line.lineNumber(), line.featureMapping(), line.presenceCondition()));
315+
blockStack.push(new BlockAnnotation(line.lineNumber(), line.lineNumber(), line.featureMapping(), line.presenceCondition(), line.nodeType()));
316316
}
317317
}
318318
// Unwind the stack fully

src/main/java/org/variantsync/vevos/extraction/gt/GroundTruth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public String combinedVariablesListAsString(GroundTruth other) {
102102

103103
public String asPcCsvString() {
104104
return generateCsv(
105-
"Path;File Condition;Block Condition;Presence Condition;start;end",
105+
"Path;File Condition;Block Condition;Line Type;Presence Condition;start;end",
106106
FileGT.Complete::csvPCLines
107107
);
108108
}

0 commit comments

Comments
 (0)