package org.shedlang.compiler.testing; import org.pcollections.PVector; import org.zwobble.precisely.MatchResult; import org.zwobble.precisely.Matcher; import org.zwobble.precisely.TextTree; import static org.zwobble.precisely.Matchers.instanceOf; public abstract class MatcherBuilder implements Matcher { private final PVector> submatchers; public MatcherBuilder(PVector> submatchers) { this.submatchers = submatchers; } @Override public MatchResult match(T actual) { return toMatcher().match(actual); } @Override public TextTree describe() { return toMatcher().describe(); } protected abstract Class expectedType(); protected abstract This create(PVector> submatchers); protected This with(Matcher submatcher) { return create(submatchers.plus(submatcher)); } private Matcher toMatcher() { return instanceOf(expectedType(), submatchers); } }