Skip to content

Commit f677560

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

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

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

Lines changed: 20 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

@@ -374,6 +375,25 @@ public int count(final Predicate<DiffNode<L>> nodesToCount) {
374375
return count.get();
375376
}
376377

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

0 commit comments

Comments
 (0)