Add `postProcess` from InputMapTemplateTest to `InputMapTemplate`
See TomasMikula/RichTextFX#288
So, I don't really get most of this code (so don't be surprised if this is way off), but by following the test as a model, I came up with this:
public static <S, T extends Event> InputMapTemplate<S, T> postProcess(
InputMapTemplate<S, T> imt, BiConsumer<? extends S, ? extends T> postConsumption) {
return new InputMapTemplate<S, T>() {
@Override
protected InputHandlerTemplateMap<S, T> getInputHandlerTemplateMap() {
return imt.getInputHandlerTemplateMap().map(iht -> {
return (s, evt) -> {
Result res = iht.process(s, evt);
if (res == Result.CONSUME) {
// Here's the issue:
// 's': capture<? extends S> cannot be applied to 'S'
// 'evt': capture<? extends T> cannot be applied to 'T'
postConsumption.accept(s, evt);
}
return res;
};
});
}
};
}
If I change the BiConsumer<? extends S, ? extends T> to BiConsumer<S, T>, the above issue goes away, but I wasn't sure if that was correct or not.
Looks good. The bounds on type parameters should be
<? super S, ? super T>
i.e. super instead of extends.
Ok that's easy to fix (turns out the method below the place where I positioned this actually uses ? super S, ? super U as well... Should have known :smile: )
Edit: the test I wrote didn't work, but that was because I removed the lines that only applied postConsumption if res == Result.CONSUME. Now that these lines are back in place, the test runs fine.