diff --git a/src/main/java/org/variantsync/diffdetective/mining/VariationDiffMiner.java b/src/main/java/org/variantsync/diffdetective/mining/VariationDiffMiner.java index aa0cd5961..48401bea3 100644 --- a/src/main/java/org/variantsync/diffdetective/mining/VariationDiffMiner.java +++ b/src/main/java/org/variantsync/diffdetective/mining/VariationDiffMiner.java @@ -21,7 +21,6 @@ import org.variantsync.diffdetective.variation.diff.transform.CollapseNestedNonEditedAnnotations; import org.variantsync.diffdetective.variation.diff.transform.CutNonEditedSubtrees; import org.variantsync.diffdetective.variation.diff.transform.VariationDiffTransformer; -import org.variantsync.diffdetective.variation.diff.transform.Starfold; import java.io.IOException; import java.nio.file.Path; @@ -43,7 +42,6 @@ public static List> Postprocessing(fina final List> processing = new ArrayList<>(); processing.add(new CutNonEditedSubtrees<>()); processing.add(new CollapseNestedNonEditedAnnotations()); - processing.add(Starfold.IgnoreNodeOrder()); return processing; } diff --git a/src/main/java/org/variantsync/diffdetective/variation/diff/transform/Starfold.java b/src/main/java/org/variantsync/diffdetective/variation/diff/transform/Starfold.java deleted file mode 100644 index 16411ba0e..000000000 --- a/src/main/java/org/variantsync/diffdetective/variation/diff/transform/Starfold.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.variantsync.diffdetective.variation.diff.transform; - -import org.variantsync.diffdetective.diff.text.DiffLineNumber; -import org.variantsync.diffdetective.variation.DiffLinesLabel; -import org.variantsync.diffdetective.variation.diff.DiffNode; -import org.variantsync.diffdetective.variation.diff.VariationDiff; -import org.variantsync.diffdetective.variation.diff.DiffType; -import org.variantsync.diffdetective.variation.diff.Time; - -import java.util.ArrayList; -import java.util.List; - -/** - * Starfold reduces redundancy in edited leaves. - * It identifies stars and simplifies its arms. - * A star is a non-edited annotation node together with all its children - * that are artifact nodes and leaves. - * The Starfold collapses all these children to a single child for each time. - * This means, all inserted star-children will be merged into a single child, and for deletions respectively. - * @author Paul Bittner, Benjamin Moosherr - */ -public class Starfold implements VariationDiffTransformer { - private final boolean respectNodeOrder; - - private Starfold(boolean respectNodeOrder) { - this.respectNodeOrder = respectNodeOrder; - } - - /** - * Create a new Starfold that respects node order. - * It will not fold a star such that the order of children is mixed up after the fold. - * @return A new order-respecting Starfold. - */ - public static Starfold RespectNodeOrder() { - return new Starfold(true); - } - - /** - * Create a new Starfold that ignores node order. - * It will fold stars aggressively and might shuffle the order of children below a star-root. - * @return A new order-ignoring Starfold. - */ - public static Starfold IgnoreNodeOrder() { - return new Starfold(false); - } - - @Override - public void transform(VariationDiff variationDiff) { - // All non-artifact nodes are potential roots of stars. - final List> annotations = variationDiff.computeAllNodesThat(Starfold::isStarRoot); -// System.out.println("Inspecting " + annotations.size() + " star roots."); - for (DiffNode annotation : annotations) { -// System.out.println("Found star root " + annotation); - foldStar(annotation); - } - } - - private void foldStar(final DiffNode starRoot) { - // We fold the stars for each time respectively. - Time.forAll(t -> foldStarAtTime(starRoot, t)); - } - - private void foldStarAtTime(final DiffNode starRoot, Time time) { -// System.out.println("Fold " + starRoot + " at time " + time); - final DiffType targetDiffType = DiffType.thatExistsOnlyAt(time); - final List> starArms = new ArrayList<>(); - - for (DiffNode child : starRoot.getAllChildren()) { - if (!starRoot.isChild(child, time)) { - continue; - } - - if (isStarArm(child) && child.diffType == targetDiffType) { -// System.out.println(" Found arm " + child); - starArms.add(child); - } else if (respectNodeOrder && !starArms.isEmpty() && child.isNon()) { - // If we find a non-edited node, we cannot continue grouping arm nodes without invalidating the order - // of the nodes. We thus have to merge and restart after the non-edited node. -// System.out.println(" Found blocker " + child); - mergeArms(starRoot, time, targetDiffType, starArms); - starArms.clear(); - } - } - - mergeArms(starRoot, time, targetDiffType, starArms); - } - - private void mergeArms(final DiffNode starRoot, Time time, final DiffType targetDiffType, final List> starArms) { - // If there is more than one arm, merge. - if (starArms.size() > 1) { - final int targetIndex = starRoot.indexOfChild(starArms.get(0), time); - starRoot.removeChildren(starArms); - starRoot.insertChild( - DiffNode.createArtifact( - targetDiffType, - DiffLineNumber.Invalid(), - DiffLineNumber.Invalid(), - new DiffLinesLabel(starArms.stream().flatMap(node -> node.getLabel().getDiffLines().stream()).toList()) - ), - targetIndex, - time - ); - } - } - - private static boolean isStarRoot(final DiffNode node) { - return !node.isArtifact() && node.isNon(); - } - - private static boolean isStarArm(final DiffNode node) { - return node.isLeaf() && node.isArtifact(); - } -} diff --git a/src/test/java/StarfoldTest.java b/src/test/java/StarfoldTest.java deleted file mode 100644 index 857ae6311..000000000 --- a/src/test/java/StarfoldTest.java +++ /dev/null @@ -1,54 +0,0 @@ -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import org.variantsync.diffdetective.variation.DiffLinesLabel; -import org.variantsync.diffdetective.variation.diff.VariationDiff; -import org.variantsync.diffdetective.variation.diff.parse.VariationDiffParseOptions; -import org.variantsync.diffdetective.variation.diff.transform.Starfold; -import org.variantsync.diffdetective.diff.result.DiffParseException; -import org.variantsync.functjonal.error.NotImplementedException; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.stream.Stream; - -public class StarfoldTest { - private static final Path INPUT_DIR = Constants.RESOURCE_DIR.resolve("starfold"); - private static final Path EXPECTED_DIR = INPUT_DIR.resolve("expected"); - - public static Stream testCases() { - return Stream - .of("2x2", "nesting1") - .map(s -> s + ".diff"); - } - - private void test(Path inputDiff, final Starfold starfold, Path expected) throws IOException, DiffParseException { - final VariationDiff t = VariationDiff.fromFile(inputDiff, new VariationDiffParseOptions(true, true)); - starfold.transform(t); - - // missing: Check that t is correct. - throw new NotImplementedException(); - } - - @Disabled("missing validation of starfold results") - @ParameterizedTest - @MethodSource("testCases") - public void testRespectNodeOrder(String filename) throws IOException, DiffParseException { - test( - INPUT_DIR.resolve(filename), - Starfold.RespectNodeOrder(), - EXPECTED_DIR.resolve("respectNodeOrder").resolve(filename) - ); - } - - @Disabled("missing validation of starfold results") - @ParameterizedTest - @MethodSource("testCases") - public void testIgnoreNodeOrder(String filename) throws IOException, DiffParseException { - test( - INPUT_DIR.resolve(filename), - Starfold.IgnoreNodeOrder(), - EXPECTED_DIR.resolve("ignoreNodeOrder").resolve(filename) - ); - } -} diff --git a/src/test/resources/starfold/2x2.diff b/src/test/resources/starfold/2x2.diff deleted file mode 100644 index 78da3cf2b..000000000 --- a/src/test/resources/starfold/2x2.diff +++ /dev/null @@ -1,5 +0,0 @@ -+1 --2 - foo -+3 --4 \ No newline at end of file diff --git a/src/test/resources/starfold/expected/ignoreNodeOrder/2x2.diff b/src/test/resources/starfold/expected/ignoreNodeOrder/2x2.diff deleted file mode 100644 index daa856e5c..000000000 --- a/src/test/resources/starfold/expected/ignoreNodeOrder/2x2.diff +++ /dev/null @@ -1,5 +0,0 @@ -+1 -+3 --2 --4 - foo \ No newline at end of file diff --git a/src/test/resources/starfold/expected/ignoreNodeOrder/nesting1.diff b/src/test/resources/starfold/expected/ignoreNodeOrder/nesting1.diff deleted file mode 100644 index b74fa319c..000000000 --- a/src/test/resources/starfold/expected/ignoreNodeOrder/nesting1.diff +++ /dev/null @@ -1,19 +0,0 @@ -+1 -+2 -+4 -+6 - #if A -+ A1 -+ A3 -+ A5 -- A2 -- A4 - #if B -+ B1 -+ B3 -- B2 -- B4 - #endif - #endif --3 --5 diff --git a/src/test/resources/starfold/expected/respectNodeOrder/2x2.diff b/src/test/resources/starfold/expected/respectNodeOrder/2x2.diff deleted file mode 100644 index 78da3cf2b..000000000 --- a/src/test/resources/starfold/expected/respectNodeOrder/2x2.diff +++ /dev/null @@ -1,5 +0,0 @@ -+1 --2 - foo -+3 --4 \ No newline at end of file diff --git a/src/test/resources/starfold/expected/respectNodeOrder/nesting1.diff b/src/test/resources/starfold/expected/respectNodeOrder/nesting1.diff deleted file mode 100644 index 80beadd7a..000000000 --- a/src/test/resources/starfold/expected/respectNodeOrder/nesting1.diff +++ /dev/null @@ -1,19 +0,0 @@ -+1 - #if A -+ A1 -- A2 - #if B -+ B1 -+ B3 -- B2 -- B4 - #endif -+ A3 -+ A5 -- A4 - #endif -+2 -+4 -+6 --3 --5 \ No newline at end of file diff --git a/src/test/resources/starfold/nesting1.diff b/src/test/resources/starfold/nesting1.diff deleted file mode 100644 index ee25a0a77..000000000 --- a/src/test/resources/starfold/nesting1.diff +++ /dev/null @@ -1,19 +0,0 @@ -+1 - #if A -+ A1 -- A2 - #if B -+ B1 -- B2 -+ B3 -- B4 - #endif -+ A3 -- A4 -+ A5 - #endif -+2 --3 -+4 --5 -+6 \ No newline at end of file