Fix failing test cases

This commit is contained in:
Kris De Volder
2016-12-16 18:40:59 -08:00
parent 05bd1dfcd6
commit 9056bff359
4 changed files with 35 additions and 7 deletions

View File

@@ -28,6 +28,7 @@ public interface YamlNavigable<T> {
/**
* Traversal which silently ignores ambiguity by picking the first valid target
* returned by traverseAmbiguously.
*
*/
default T traverse(YamlPathSegment s) throws Exception {
return traverseAmbiguously(s).findFirst().orElse(null);

View File

@@ -129,7 +129,9 @@ public class YamlPath {
if (startNode!=null) {
Stream<T> result = Stream.of(startNode);
for (YamlPathSegment s : segments) {
result = result.flatMap((node) -> node.traverseAmbiguously(s));
result = result.flatMap((node) -> {
return node.traverseAmbiguously(s);
});
}
return result;
}

View File

@@ -21,6 +21,7 @@ import org.springframework.ide.vscode.commons.yaml.path.YamlNavigable;
import org.springframework.ide.vscode.commons.yaml.path.YamlPath;
import org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment;
import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SKeyNode;
import org.springframework.ide.vscode.commons.yaml.util.Streams;
import org.springframework.ide.vscode.commons.yaml.util.YamlIndentUtil;
import com.google.common.collect.ImmutableList;
@@ -264,8 +265,17 @@ public class YamlStructureParser {
* Default implementation, doesn't support any type of traversal operation.
* Subclasses must override and implement where appropriate.
*/
public SNode traverse(YamlPathSegment s) throws Exception {
return null;
public Stream<SNode> traverseAmbiguously(YamlPathSegment s) {
return Stream.empty();
}
/**
* Default implementation, actusllu the same as the default impl provided by
* the interface. This is only here to prevent subclasses from implementing
* this. They should implement traverseAmbiguously instead.
*/
public SNode traverse(YamlPathSegment s) {
return traverseAmbiguously(s).findFirst().orElse(null);
}
protected abstract void dump(Writer out, int indent) throws Exception;
@@ -350,15 +360,15 @@ public class YamlStructureParser {
}
@Override
public SNode traverse(YamlPathSegment s) throws Exception {
public Stream<SNode> traverseAmbiguously(YamlPathSegment s) {
Integer index = s.toIndex();
if (index!=null) {
List<SNode> cs = getChildren();
if (index>=0 && index<cs.size()) {
return cs.get(index);
return Streams.of(cs.get(index));
}
}
return null;
return Stream.empty();
}
}
@@ -462,12 +472,13 @@ public class YamlStructureParser {
case VAL_AT_KEY:
return this.getChildrenWithKey(s.toPropString());
case VAL_AT_INDEX:
return Stream.of(this.getSeqChildWithIndex(s.toIndex()));
return Streams.of(this.getSeqChildWithIndex(s.toIndex()));
default:
return Stream.empty();
}
}
private SSeqNode getSeqChildWithIndex(int index) {
if (index>=0) {
List<SNode> children = getChildren();

View File

@@ -0,0 +1,14 @@
package org.springframework.ide.vscode.commons.yaml.util;
import java.util.stream.Stream;
public class Streams {
/**
* Like Stream.of but returns Stream.empty of the element is null
*/
public static <T> Stream<T> of(T e) {
return e==null ? Stream.empty() : Stream.of(e);
}
}