Skip to content

Commit 973e21c

Browse files
committed
feat: VariationDiff::computeAllFeatureNames()
1 parent 3d8f9cf commit 973e21c

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.variantsync.diffdetective.variation.diff.traverse.VariationDiffTraversal;
2525
import org.variantsync.diffdetective.variation.diff.traverse.VariationDiffVisitor;
2626
import org.variantsync.diffdetective.variation.tree.VariationTree;
27+
import org.variantsync.diffdetective.util.fide.FixTrueFalse;
2728
import org.variantsync.functjonal.Cast;
2829
import org.variantsync.functjonal.Result;
2930

@@ -34,6 +35,7 @@
3435
import java.nio.file.Path;
3536
import java.util.ArrayList;
3637
import java.util.HashMap;
38+
import java.util.LinkedHashSet;
3739
import java.util.List;
3840
import java.util.Map;
3941
import java.util.concurrent.atomic.AtomicBoolean;
@@ -374,6 +376,25 @@ public int count(final Predicate<DiffNode<L>> nodesToCount) {
374376
return count.get();
375377
}
376378

379+
380+
/**
381+
* Returns all variable names occurring in annotations (i.e., formulas of mapping nodes) in this variation diff.
382+
* This method is deterministic: It will return the feature names always in the same order, assuming the variation diff is not changed inbetween.
383+
* @return A set of every occuring feature name.
384+
*/
385+
public LinkedHashSet<String> computeAllFeatureNames() {
386+
LinkedHashSet<String> features = new LinkedHashSet<>();
387+
forAll(node -> {
388+
if (node.isConditionalAnnotation()) {
389+
features.addAll(node.getFormula().getUniqueContainedFeatures());
390+
}
391+
});
392+
// Since FeatureIDE falsely reports constants "True" and "False" as feature names, we have to remove them from the resulting set.
393+
features.removeIf(FixTrueFalse::isTrueLiteral);
394+
features.removeIf(FixTrueFalse::isFalseLiteral);
395+
return features;
396+
}
397+
377398
/**
378399
* Sets the source of this VariationDiff.
379400
* @see VariationDiffSource

0 commit comments

Comments
 (0)