Skip to content

Commit

Permalink
why??
Browse files Browse the repository at this point in the history
  • Loading branch information
jevanlingen committed Nov 15, 2024
1 parent 841982c commit b2738e9
Showing 1 changed file with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.openrewrite.internal.ListUtils.concatAll;
import static org.openrewrite.internal.ListUtils.map;
import static org.openrewrite.internal.ListUtils.*;

@AllArgsConstructor
@RequiredArgsConstructor
Expand Down Expand Up @@ -72,6 +71,7 @@ public MergeYamlVisitor(Yaml scope, @Language("yml") String yamlString, boolean

@Override
public Yaml visitScalar(Scalar existingScalar, P p) {
System.out.println((boolean) (getCursor().getMessage("RemovePrefix", false)));
if (existing.isScope(existingScalar) && incoming instanceof Scalar) {
return mergeScalar(existingScalar, (Scalar) incoming);
}
Expand All @@ -80,6 +80,8 @@ public Yaml visitScalar(Scalar existingScalar, P p) {

@Override
public Yaml visitSequence(Yaml.Sequence existingSeq, P p) {
System.out.println((boolean) (getCursor().getMessage("RemovePrefix", false)));

if (existing.isScope(existingSeq)) {
if (incoming instanceof Yaml.Mapping) {
// Distribute the incoming mapping to each entry in the sequence
Expand All @@ -98,12 +100,24 @@ public Yaml visitSequence(Yaml.Sequence existingSeq, P p) {

@Override
public Yaml visitMapping(Yaml.Mapping existingMapping, P p) {
System.out.println("<<< visitMapping");
if (getCursor().toString().equals("Cursor{Mapping->Document->Documents->root}")) {
System.out.println("ja!!");
}
System.out.println(getCursor());
System.out.println((boolean) (getCursor().getMessage("RemovePrefix", false)));
if (existing.isScope(existingMapping) && incoming instanceof Yaml.Mapping) {
return mergeMapping(existingMapping, (Yaml.Mapping) incoming, p, getCursor());
}
return super.visitMapping(existingMapping, p);
}

@Override
public Yaml visitMappingEntry(Yaml.Mapping.Entry entry, P p) {
System.out.println((boolean) (getCursor().getMessage("RemovePrefix", false)));
return super.visitMappingEntry(entry, p);
}

private static boolean keyMatches(Yaml.Mapping.@Nullable Entry e1, Yaml.Mapping.@Nullable Entry e2) {
return e1 != null && e2 != null && e1.getKey().getValue().equals(e2.getKey().getValue());
}
Expand Down Expand Up @@ -173,10 +187,6 @@ private Yaml.Mapping mergeMapping(Yaml.Mapping m1, Yaml.Mapping m2, P p, Cursor
return false;
});

// int index2 = ((Yaml.Mapping) currCursor.getValue()).getEntries().size() -1;
System.out.println(">>>");
System.out.println(c);

if (c.getValue() instanceof Yaml.Document || c.getValue() instanceof Yaml.Mapping) {
Yaml.Mapping.Entry lastEntry = mutatedEntries.get(mutatedEntries.size() - 1);
String comment = "";
Expand All @@ -203,6 +213,12 @@ private Yaml.Mapping mergeMapping(Yaml.Mapping m1, Yaml.Mapping m2, P p, Cursor
}

mutatedEntries.set(mutatedEntries.size() - 1, lastEntry.withPrefix(comment + lastEntry.getPrefix()));



// int index2 = ((Yaml.Mapping) currCursor.getValue()).getEntries().size() -1;
System.out.println(">>>");
System.out.println(c);
c.putMessage("RemovePrefix", true);
}
}
Expand All @@ -212,21 +228,23 @@ private Yaml.Mapping mergeMapping(Yaml.Mapping m1, Yaml.Mapping m2, P p, Cursor
System.out.println((Boolean) currCursor.getMessage("RemovePrefix", null));
System.out.println("----");*/

if (cursor.getMessage("RemovePrefix", false)) {
System.out.println("Waarom niet ");
}

for (int i = 0; i < m1.getEntries().size(); i++) {
if (m1.getEntries().get(i).getValue() instanceof Yaml.Mapping &&
mutatedEntries.get(i).getValue() instanceof Yaml.Mapping &&
((Yaml.Mapping) mutatedEntries.get(i).getValue()).getEntries().size() > ((Yaml.Mapping) m1.getEntries().get(i).getValue()).getEntries().size()) {
System.out.println("yawel!!");

// temporary if
if ((i + 1) < mutatedEntries.size()) {
System.out.println("en go......");
mutatedEntries.set(i + 1, mutatedEntries.get(i + 1).withPrefix("\n" + mutatedEntries.get(i + 1).getPrefix().split("\n")[1]));
}

//Entry s = mutatedEntries.get(i).getValue().withPrefix("Whatever");
/*Yaml.Mapping xdx = (Yaml.Mapping) mutatedEntries.get(i).getValue();
Yaml.Mapping xxxx= xdx.withEntries(mapLast(xdx.getEntries(), it -> it.withPrefix("boom\n")));
mutatedEntries.set(i, mutatedEntries.get(i).withValue(xxxx));*/

}


Expand Down

0 comments on commit b2738e9

Please sign in to comment.