1 | package com.github.valid8j.pcond.core; | |
2 | ||
3 | import com.github.valid8j.pcond.experimentals.currying.context.CurriedContext; | |
4 | import com.github.valid8j.pcond.internals.InternalUtils; | |
5 | ||
6 | import java.util.function.Function; | |
7 | import java.util.function.Predicate; | |
8 | import java.util.stream.Stream; | |
9 | ||
10 | import static com.github.valid8j.pcond.core.EvaluationContext.formNameOf; | |
11 | import static com.github.valid8j.pcond.core.EvaluationContext.resolveEvaluationEntryType; | |
12 | import static com.github.valid8j.pcond.core.ValueHolder.CreatorFormType.FUNC_HEAD; | |
13 | import static com.github.valid8j.pcond.core.ValueHolder.CreatorFormType.FUNC_TAIL; | |
14 | import static com.github.valid8j.pcond.core.ValueHolder.State.*; | |
15 | import static java.util.Objects.requireNonNull; | |
16 | ||
17 | /** | |
18 | * A visitor interface that defines a mechanism to "evaluate" printable predicates. | |
19 | */ | |
20 | public interface Evaluator { | |
21 | /** | |
22 | * Evaluates `value` with `conjunction` predicate ("and"). | |
23 | * | |
24 | * @param <T> The type of the `value`. | |
25 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
26 | * @param evaluationContext An evaluation context. | |
27 | * @see Evaluable.Conjunction | |
28 | */ | |
29 | <T> void evaluateConjunction(EvaluableIo<T, Evaluable.Conjunction<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
30 | | |
31 | /** | |
32 | * Evaluates `value` with a `disjunction` predicate ("or"). | |
33 | * | |
34 | * @param <T> The type of the `value`. | |
35 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
36 | * @param evaluationContext An evaluation context. | |
37 | * @see Evaluable.Disjunction | |
38 | */ | |
39 | <T> void evaluateDisjunction(EvaluableIo<T, Evaluable.Disjunction<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
40 | | |
41 | /** | |
42 | * Evaluates `value` with a `negation` predicate ("not"). | |
43 | * | |
44 | * @param <T> The type of the `value`. | |
45 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
46 | * @param evaluationContext An evaluation context. | |
47 | * @see Evaluable.Negation | |
48 | */ | |
49 | <T> void evaluateNegation(EvaluableIo<T, Evaluable.Negation<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
50 | | |
51 | /** | |
52 | * Evaluates `value` with a leaf predicate. | |
53 | * | |
54 | * @param <T> The type of the `value`. | |
55 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
56 | * @param evaluationContext An evaluation context. | |
57 | * @see Evaluable.LeafPred | |
58 | */ | |
59 | <T> void evaluateLeaf(EvaluableIo<T, Evaluable.LeafPred<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
60 | | |
61 | /** | |
62 | * Evaluates `value` with a "function" predicate. | |
63 | * | |
64 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
65 | * @param evaluationContext An evaluation context. | |
66 | * @see Evaluable.Func | |
67 | */ | |
68 | <T, R> void evaluateFunction(EvaluableIo<T, Evaluable.Func<T>, R> evaluableIo, EvaluationContext<T> evaluationContext); | |
69 | | |
70 | /** | |
71 | * Evaluates `value` with a context predicate. | |
72 | * | |
73 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
74 | * @param evaluationContext An evaluation context. | |
75 | * @see Evaluable.CurriedContextPred | |
76 | */ | |
77 | void evaluateCurriedContextPredicate(EvaluableIo<CurriedContext, Evaluable.CurriedContextPred, Boolean> evaluableIo, EvaluationContext<CurriedContext> evaluationContext); | |
78 | | |
79 | /** | |
80 | * Evaluates `value` with a "transformation" predicate. | |
81 | * | |
82 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
83 | * @param evaluationContext An evaluation context. | |
84 | * @see Evaluable.Transformation | |
85 | */ | |
86 | <T, R> void evaluateTransformation(EvaluableIo<T, Evaluable.Transformation<T, R>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
87 | | |
88 | /** | |
89 | * Evaluates `value` with a predicate for a stream. | |
90 | * | |
91 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
92 | * @param evaluationContext An evaluation context. | |
93 | * @see Evaluable.StreamPred | |
94 | */ | |
95 | <E> void evaluateStreamPredicate(EvaluableIo<Stream<E>, Evaluable.StreamPred<E>, Boolean> evaluableIo, EvaluationContext<Stream<E>> evaluationContext); | |
96 | | |
97 | /** | |
98 | * Returns a new instance of this interface. | |
99 | * | |
100 | * @return a new instance of this interface. | |
101 | */ | |
102 | static Evaluator create() { | |
103 |
1
1. create : replaced return value with null for com/github/valid8j/pcond/core/Evaluator::create → KILLED |
return new Impl(); |
104 | } | |
105 | | |
106 | class Impl implements Evaluator { | |
107 | public static final Object EVALUATION_SKIPPED = new Object() { | |
108 | @Override | |
109 | public String toString() { | |
110 |
1
1. toString : replaced return value with "" for com/github/valid8j/pcond/core/Evaluator$Impl$1::toString → KILLED |
return "(not evaluated)"; |
111 | } | |
112 | }; | |
113 | | |
114 | private static final Object NULL_VALUE = new Object() { | |
115 | public String toString() { | |
116 |
1
1. toString : replaced return value with "" for com/github/valid8j/pcond/core/Evaluator$Impl$2::toString → SURVIVED |
return "null"; |
117 | } | |
118 | }; | |
119 | | |
120 | public Impl() { | |
121 | } | |
122 | | |
123 | @Override | |
124 | public <T> void evaluateConjunction(EvaluableIo<T, Evaluable.Conjunction<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
125 |
1
1. evaluateConjunction : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
126 | evaluableIo, | |
127 | (Evaluable.Conjunction<T> evaluable, ValueHolder<T> input) -> { | |
128 | ValueHolder<Boolean> ret = ValueHolder.create(); | |
129 | boolean result = true; | |
130 | ValueHolder<Boolean> retSkipped = null; | |
131 | for (Evaluable<T> each : evaluable.children()) { | |
132 | EvaluableIo<T, Evaluable<T>, Boolean> child = createChildEvaluableIoOf(each, input); | |
133 |
1
1. lambda$evaluateConjunction$0 : removed call to com/github/valid8j/pcond/core/Evaluable::accept → KILLED |
each.accept(child, evaluationContext, this); |
134 | ValueHolder<Boolean> outputFromEach = child.output(); | |
135 |
1
1. lambda$evaluateConjunction$0 : negated conditional → KILLED |
if (outputFromEach.isValueReturned()) { |
136 |
1
1. lambda$evaluateConjunction$0 : Replaced bitwise AND with OR → KILLED |
result &= outputFromEach.returnedValue(); |
137 | ret = ValueHolder.forValue(result); | |
138 |
1
1. lambda$evaluateConjunction$0 : negated conditional → KILLED |
} else if (child.output().isExceptionThrown()) { |
139 | ret = ValueHolder.<Boolean>create().evaluationSkipped(); | |
140 |
1
1. lambda$evaluateConjunction$0 : negated conditional → SURVIVED |
retSkipped = retSkipped != null ? retSkipped : ret; |
141 |
1
1. lambda$evaluateConjunction$0 : negated conditional → KILLED |
} else if (child.output().isEvaluationSkipped()) { |
142 | ret = ValueHolder.<Boolean>create().evaluationSkipped(); | |
143 |
1
1. lambda$evaluateConjunction$0 : negated conditional → SURVIVED |
retSkipped = retSkipped != null ? retSkipped : ret; |
144 | } else | |
145 | assert false; | |
146 |
3
1. lambda$evaluateConjunction$0 : negated conditional → KILLED 2. lambda$evaluateConjunction$0 : negated conditional → KILLED 3. lambda$evaluateConjunction$0 : negated conditional → KILLED |
if (evaluable.shortcut() && (ret.isEvaluationSkipped() || !result)) |
147 | break; | |
148 | } | |
149 |
2
1. lambda$evaluateConjunction$0 : negated conditional → KILLED 2. lambda$evaluateConjunction$0 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateConjunction$0 → KILLED |
return retSkipped != null ? retSkipped : ret; |
150 | }); | |
151 | } | |
152 | | |
153 | @Override | |
154 | public <T> void evaluateDisjunction(EvaluableIo<T, Evaluable.Disjunction<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
155 |
1
1. evaluateDisjunction : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
156 | evaluableIo, | |
157 | (Evaluable.Disjunction<T> evaluable, ValueHolder<T> input) -> { | |
158 | ValueHolder<Boolean> ret = ValueHolder.create(); | |
159 | boolean result = false; | |
160 | ValueHolder<Boolean> retSkipped = null; | |
161 | for (Evaluable<T> each : evaluable.children()) { | |
162 | EvaluableIo<T, Evaluable<T>, Boolean> child = createChildEvaluableIoOf(each, input); | |
163 |
1
1. lambda$evaluateDisjunction$1 : removed call to com/github/valid8j/pcond/core/Evaluable::accept → KILLED |
each.accept(child, evaluationContext, this); |
164 | ValueHolder<Boolean> outputFromEach = child.output(); | |
165 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → KILLED |
if (outputFromEach.isValueReturned()) { |
166 |
1
1. lambda$evaluateDisjunction$1 : Replaced bitwise OR with AND → KILLED |
result |= outputFromEach.returnedValue(); |
167 | ret = ValueHolder.forValue(result); | |
168 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → KILLED |
} else if (outputFromEach.isExceptionThrown()) { |
169 | ret = ValueHolder.<Boolean>create().evaluationSkipped(); | |
170 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → SURVIVED |
retSkipped = retSkipped != null ? retSkipped : ret; |
171 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → NO_COVERAGE |
} else if (outputFromEach.isEvaluationSkipped()) { |
172 | ret = ValueHolder.<Boolean>create().evaluationSkipped(); | |
173 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → NO_COVERAGE |
retSkipped = retSkipped != null ? retSkipped : ret; |
174 | } else | |
175 | assert false; | |
176 |
3
1. lambda$evaluateDisjunction$1 : negated conditional → KILLED 2. lambda$evaluateDisjunction$1 : negated conditional → KILLED 3. lambda$evaluateDisjunction$1 : negated conditional → KILLED |
if (evaluable.shortcut() && (ret.isEvaluationSkipped() || result)) |
177 | break; | |
178 | } | |
179 |
2
1. lambda$evaluateDisjunction$1 : negated conditional → KILLED 2. lambda$evaluateDisjunction$1 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateDisjunction$1 → KILLED |
return retSkipped != null ? retSkipped : ret; |
180 | }); | |
181 | } | |
182 | | |
183 | @Override | |
184 | public <T> void evaluateNegation(EvaluableIo<T, Evaluable.Negation<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
185 |
1
1. evaluateNegation : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
186 | evaluableIo, | |
187 | (Evaluable.Negation<T> evaluable, ValueHolder<T> input) -> { | |
188 |
1
1. lambda$evaluateNegation$2 : removed call to com/github/valid8j/pcond/core/EvaluationContext::flipExpectation → KILLED |
evaluationContext.flipExpectation(); |
189 | try { | |
190 | EvaluableIo<T, Evaluable<T>, Boolean> childIo = createChildEvaluableIoOf(evaluable.target(), input); | |
191 |
1
1. lambda$evaluateNegation$2 : removed call to com/github/valid8j/pcond/core/Evaluable::accept → KILLED |
evaluable.target().accept(childIo, evaluationContext, this); |
192 |
2
1. lambda$evaluateNegation$2 : negated conditional → KILLED 2. lambda$evaluateNegation$2 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateNegation$2 → KILLED |
return childIo.output().isValueReturned() ? |
193 |
1
1. lambda$evaluateNegation$2 : Replaced XOR with AND → KILLED |
ValueHolder.forValue(evaluationContext.isExpectationFlipped() ^ childIo.output().returnedValue()) : |
194 | childIo.output(); | |
195 | } finally { | |
196 |
1
1. lambda$evaluateNegation$2 : removed call to com/github/valid8j/pcond/core/EvaluationContext::flipExpectation → KILLED |
evaluationContext.flipExpectation(); |
197 | } | |
198 | } | |
199 | ); | |
200 | } | |
201 | | |
202 | @Override | |
203 | public <T> void evaluateLeaf(EvaluableIo<T, Evaluable.LeafPred<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
204 |
1
1. evaluateLeaf : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
205 | EvaluationEntry.Type.LEAF, | |
206 | evaluableIo, | |
207 | (evaluable, input) -> { | |
208 | ValueHolder<Boolean> ret = ValueHolder.create(); | |
209 |
1
1. lambda$evaluateLeaf$3 : negated conditional → KILLED |
if (input.isValueReturned()) { |
210 | T value = input.returnedValue(); | |
211 | Predicate<? super T> predicate = requireNonNull(evaluable.predicate()); | |
212 | try { | |
213 |
1
1. lambda$evaluateLeaf$3 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateLeaf$3 → KILLED |
return ret.valueReturned(predicate.test(value)); |
214 | } catch (Throwable t) { | |
215 |
1
1. lambda$evaluateLeaf$3 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateLeaf$3 → KILLED |
return ret.exceptionThrown(t); |
216 | } | |
217 | } else | |
218 |
1
1. lambda$evaluateLeaf$3 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateLeaf$3 → KILLED |
return ret.evaluationSkipped(); |
219 | }); | |
220 | } | |
221 | | |
222 | @SuppressWarnings("unchecked") | |
223 | @Override | |
224 | public <T, R> void evaluateFunction(EvaluableIo<T, Evaluable.Func<T>, R> evaluableIo, EvaluationContext<T> evaluationContext) { | |
225 |
1
1. evaluateFunction : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( //#2 |
226 | EvaluationEntry.Type.FUNCTION, | |
227 | evaluableIo, | |
228 | (Evaluable.Func<T> evaluable, ValueHolder<T> input) -> { | |
229 | ValueHolder<R> ret; | |
230 | { | |
231 | EvaluableIo<T, Evaluable<T>, Object> ioForHead = createChildEvaluableIoOf(evaluable, input); | |
232 | EvaluationContext<T> childContext = new EvaluationContext<>(evaluationContext); | |
233 |
1
1. lambda$evaluateFunction$6 : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
childContext.evaluate(EvaluationEntry.Type.FUNCTION, ioForHead, io -> { |
234 | ValueHolder<Object> tmp = ValueHolder.create(); | |
235 |
1
1. lambda$null$4 : negated conditional → KILLED |
if (io.input().isValueReturned()) |
236 | tmp = applyFunction(tmp, io.input().returnedValue(), ((Evaluable.Func<T>) io.evaluable()).head()); | |
237 | else | |
238 | tmp = tmp.evaluationSkipped(); | |
239 |
1
1. lambda$null$4 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$null$4 → KILLED |
return tmp.creatorFormType(FUNC_HEAD); |
240 | }); | |
241 |
1
1. lambda$evaluateFunction$6 : removed call to com/github/valid8j/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext, 1); |
242 | ret = (ValueHolder<R>) ioForHead.output().creatorFormType(FUNC_TAIL); | |
243 | } | |
244 | ValueHolder<Object> finalRet = (ValueHolder<Object>) ret; | |
245 |
1
1. lambda$evaluateFunction$6 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateFunction$6 → KILLED |
return evaluable.tail().map((Evaluable<Object> e) -> { |
246 | EvaluableIo<Object, Evaluable<Object>, R> ioForTail = createChildEvaluableIoOf(e, finalRet); | |
247 |
1
1. lambda$null$5 : removed call to com/github/valid8j/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("FUNC_TAIL:BEFORE", ioForTail); |
248 |
1
1. lambda$null$5 : removed call to com/github/valid8j/pcond/core/Evaluable::accept → KILLED |
e.accept(ioForTail, (EvaluationContext<Object>) evaluationContext, this); |
249 |
1
1. lambda$null$5 : removed call to com/github/valid8j/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("FUNC_TAIL:AFTER", ioForTail); |
250 |
1
1. lambda$null$5 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$null$5 → KILLED |
return ioForTail.output().creatorFormType(FUNC_TAIL); |
251 | }) | |
252 | .orElse(ret); | |
253 | }); | |
254 | } | |
255 | | |
256 | @SuppressWarnings("unchecked") | |
257 | private static <T, R> ValueHolder<R> applyFunction(ValueHolder<R> ret, T in, Function<? super T, Object> function) { | |
258 | try { | |
259 | R returnedValue; | |
260 | returnedValue = (R) function.apply(in); | |
261 |
1
1. applyFunction : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::applyFunction → KILLED |
return ret.valueReturned(returnedValue); |
262 | } catch (Throwable t) { | |
263 |
1
1. applyFunction : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::applyFunction → KILLED |
return ret.exceptionThrown(t); |
264 | } | |
265 | } | |
266 | | |
267 | @SuppressWarnings({"unchecked", "rawtypes"}) | |
268 | @Override | |
269 | public <T, R> void evaluateTransformation(EvaluableIo<T, Evaluable.Transformation<T, R>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
270 |
1
1. evaluateTransformation : negated conditional → KILLED |
if (InternalUtils.isDummyFunction((Function<?, ?>) evaluableIo.evaluable().mapper())) { |
271 |
1
1. evaluateTransformation : removed call to com/github/valid8j/pcond/core/Evaluable::accept → NO_COVERAGE |
evaluableIo.evaluable().checker().accept((EvaluableIo<R, Evaluable<R>, Boolean>) (Evaluable) evaluableIo, (EvaluationContext<R>) evaluationContext, this); |
272 | return; | |
273 | } | |
274 | EvaluationContext<T> childContext = new EvaluationContext<>(evaluationContext); | |
275 |
1
1. evaluateTransformation : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
childContext.evaluate( |
276 | evaluableIo, | |
277 | (Evaluable.Transformation<T, R> evaluable, ValueHolder<T> input) -> { | |
278 |
1
1. lambda$evaluateTransformation$7 : removed call to com/github/valid8j/pcond/core/DebuggingUtils::printInput → SURVIVED |
DebuggingUtils.printInput("TRANSFORMATION:BEFORE", evaluable, input); |
279 | EvaluableIo<T, Evaluable<T>, R> mapperIo = evaluateMapper(evaluable.mapperName().orElse("transform"), evaluable.mapper(), input, childContext); | |
280 | EvaluableIo<R, Evaluable<R>, Boolean> checkerIo = evaluateChecker(evaluable.checkerName().orElse("check"), evaluable.checker(), mapperIo.output(), childContext); | |
281 |
1
1. lambda$evaluateTransformation$7 : removed call to com/github/valid8j/pcond/core/DebuggingUtils::printInputAndOutput → SURVIVED |
DebuggingUtils.printInputAndOutput(evaluable, input, checkerIo.output()); |
282 |
1
1. lambda$evaluateTransformation$7 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateTransformation$7 → KILLED |
return checkerIo.output(); |
283 | } | |
284 | ); | |
285 |
1
1. evaluateTransformation : removed call to com/github/valid8j/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext, 1); |
286 | } | |
287 | | |
288 | private <T, R> EvaluableIo<T, Evaluable<T>, R> evaluateMapper(String mapperName, Evaluable<T> mapper, ValueHolder<T> input, EvaluationContext<T> evaluationContext) { | |
289 | EvaluableIo<T, Evaluable<T>, R> ioForMapper = createChildEvaluableIoOf(mapper, input.creatorFormType(ValueHolder.CreatorFormType.TRANSFORM)); | |
290 | { | |
291 | EvaluationContext<T> childContext = new EvaluationContext<>(evaluationContext); | |
292 | | |
293 | // #1 | |
294 |
1
1. evaluateMapper : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
childContext.evaluate(EvaluationEntry.Type.TRANSFORM, mapperName, ioForMapper, io -> { |
295 |
1
1. lambda$evaluateMapper$8 : removed call to com/github/valid8j/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("TRANSFORM:BEFORE", io); |
296 |
1
1. lambda$evaluateMapper$8 : removed call to com/github/valid8j/pcond/core/Evaluable::accept → KILLED |
io.evaluable().accept(io, childContext, this); |
297 |
1
1. lambda$evaluateMapper$8 : removed call to com/github/valid8j/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("TRANSFORM:AFTER", io); |
298 |
1
1. lambda$evaluateMapper$8 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateMapper$8 → KILLED |
return io.output(); |
299 | }); | |
300 | | |
301 |
1
1. evaluateMapper : removed call to com/github/valid8j/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext, 0); |
302 | } | |
303 |
1
1. evaluateMapper : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::evaluateMapper → KILLED |
return ioForMapper; |
304 | } | |
305 | | |
306 | private <T, R> EvaluableIo<R, Evaluable<R>, Boolean> evaluateChecker(String checkerName, Evaluable<R> checker, ValueHolder<R> input, EvaluationContext<T> evaluationContext) { | |
307 | EvaluableIo<R, Evaluable<R>, Boolean> ioForChecker = createChildEvaluableIoOf(checker, input); | |
308 | { | |
309 | EvaluationContext<R> childContext = new EvaluationContext<>(evaluationContext); | |
310 | | |
311 |
1
1. evaluateChecker : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
childContext.evaluate(EvaluationEntry.Type.CHECK, checkerName, ioForChecker, io -> { |
312 |
1
1. lambda$evaluateChecker$9 : removed call to com/github/valid8j/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("CHECK:BEFORE", io); |
313 |
1
1. lambda$evaluateChecker$9 : removed call to com/github/valid8j/pcond/core/Evaluable::accept → KILLED |
io.evaluable().accept(io, childContext, this); |
314 |
1
1. lambda$evaluateChecker$9 : removed call to com/github/valid8j/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("CHECK:AFTER", io); |
315 |
1
1. lambda$evaluateChecker$9 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateChecker$9 → KILLED |
return io.output(); |
316 | }); | |
317 | | |
318 |
1
1. evaluateChecker : removed call to com/github/valid8j/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext, 0); |
319 | } | |
320 |
1
1. evaluateChecker : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::evaluateChecker → KILLED |
return ioForChecker; |
321 | } | |
322 | | |
323 | // ValueToCut ValueOnCut ValueForNone(=default) | |
324 | // NoneMatch true false true | |
325 | // AnyMatch true true false | |
326 | // AllMatch false false true | |
327 | | |
328 | @Override | |
329 | public <E> void evaluateStreamPredicate(EvaluableIo<Stream<E>, Evaluable.StreamPred<E>, Boolean> evaluableIo, EvaluationContext<Stream<E>> evaluationContext) { | |
330 |
1
1. evaluateStreamPredicate : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
331 | evaluableIo, | |
332 | (Evaluable.StreamPred<E> evaluable, ValueHolder<Stream<E>> input) -> input.returnedValue() | |
333 | .map((E e) -> { | |
334 |
1
1. lambda$null$10 : negated conditional → KILLED |
if (evaluable.requestExpectationFlip()) |
335 |
1
1. lambda$null$10 : removed call to com/github/valid8j/pcond/core/EvaluationContext::flipExpectation → KILLED |
evaluationContext.flipExpectation(); |
336 | try { | |
337 | EvaluationContext<E> childContext = new EvaluationContext<>(evaluationContext); | |
338 | EvaluableIo<E, Evaluable<E>, Boolean> ioForCutPredicate = createChildEvaluableIoOf(evaluable.cut(), ValueHolder.forValue(e)); | |
339 |
1
1. lambda$null$10 : removed call to com/github/valid8j/pcond/core/Evaluable::accept → KILLED |
evaluable.cut().accept(ioForCutPredicate, childContext, this); |
340 |
1
1. lambda$null$10 : removed call to com/github/valid8j/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext); |
341 |
1
1. lambda$null$10 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$null$10 → KILLED |
return ioForCutPredicate.output(); |
342 | } finally { | |
343 |
1
1. lambda$null$10 : negated conditional → KILLED |
if (evaluable.requestExpectationFlip()) |
344 |
1
1. lambda$null$10 : removed call to com/github/valid8j/pcond/core/EvaluationContext::flipExpectation → KILLED |
evaluationContext.flipExpectation(); |
345 | } | |
346 | }) | |
347 | .filter(eachResult -> { | |
348 |
1
1. lambda$null$11 : negated conditional → KILLED |
if (!eachResult.isValueReturned()) |
349 |
1
1. lambda$null$11 : replaced boolean return with false for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$null$11 → KILLED |
return true; |
350 |
2
1. lambda$null$11 : negated conditional → KILLED 2. lambda$null$11 : replaced boolean return with true for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$null$11 → KILLED |
return eachResult.returnedValue() == evaluable.valueToCut(); |
351 | }) | |
352 |
2
1. lambda$null$12 : negated conditional → KILLED 2. lambda$null$12 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$null$12 → KILLED |
.map(eachResult -> eachResult.valueReturned(!evaluable.defaultValue())) // compute Value on cut |
353 | .findFirst() | |
354 |
2
1. lambda$evaluateStreamPredicate$14 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateStreamPredicate$14 → KILLED 2. lambda$null$13 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$null$13 → KILLED |
.orElseGet(() -> ValueHolder.forValue(evaluable.defaultValue()))); // compute Value for none |
355 | } | |
356 | | |
357 | @Override | |
358 | public void evaluateCurriedContextPredicate(EvaluableIo<CurriedContext, Evaluable.CurriedContextPred, Boolean> evaluableIo, EvaluationContext<CurriedContext> evaluationContext) { | |
359 |
1
1. evaluateCurriedContextPredicate : removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate(evaluableIo, (Evaluable.CurriedContextPred evaluable, ValueHolder<CurriedContext> input) -> { |
360 | EvaluableIo<Object, Evaluable<Object>, Boolean> io = createChildEvaluableIoOf(evaluable.enclosed(), ValueHolder.forValue(input.returnedValue().valueAt(evaluable.argIndex()))); | |
361 | EvaluationContext<Object> childContext = new EvaluationContext<>(evaluationContext); | |
362 |
1
1. lambda$evaluateCurriedContextPredicate$15 : removed call to com/github/valid8j/pcond/core/Evaluable::accept → KILLED |
evaluable.enclosed().accept(io, childContext, this); |
363 |
1
1. lambda$evaluateCurriedContextPredicate$15 : removed call to com/github/valid8j/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext); |
364 |
1
1. lambda$evaluateCurriedContextPredicate$15 : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::lambda$evaluateCurriedContextPredicate$15 → KILLED |
return io.output(); |
365 | }); | |
366 | } | |
367 | | |
368 | private static <T, E extends Evaluable<T>, O> EvaluableIo<T, Evaluable<T>, O> createChildEvaluableIoOf(E evaluable, ValueHolder<T> input) { | |
369 |
1
1. createChildEvaluableIoOf : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::createChildEvaluableIoOf → KILLED |
return createChildEvaluableIoOf(resolveEvaluationEntryType(evaluable).formName(evaluable), evaluable, input); |
370 | } | |
371 | | |
372 | private static <T, E extends Evaluable<T>, O> EvaluableIo<T, Evaluable<T>, O> createChildEvaluableIoOf(String formName, E evaluable, ValueHolder<T> input) { | |
373 | EvaluationEntry.Type evaluableType = resolveEvaluationEntryType(evaluable); | |
374 |
1
1. createChildEvaluableIoOf : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::createChildEvaluableIoOf → KILLED |
return createChildEvaluableIoOf(evaluableType, formName, evaluable, input); |
375 | } | |
376 | | |
377 | private static <T, E extends Evaluable<T>, O> EvaluableIo<T, Evaluable<T>, O> createChildEvaluableIoOf(EvaluationEntry.Type evaluableType, String formName, E evaluable, ValueHolder<T> input) { | |
378 |
1
1. createChildEvaluableIoOf : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Impl::createChildEvaluableIoOf → KILLED |
return new EvaluableIo<>(input, evaluableType, formName, evaluable); |
379 | } | |
380 | } | |
381 | | |
382 | /** | |
383 | * If an input or an output value object of a form implements this interface, | |
384 | * The value returned by `snapshot` method is stored in a {@link EvaluationEntry} | |
385 | * record, instead of the value itself. | |
386 | * | |
387 | * An implementation of this interface should override `toString()` method to return a string form of the original state of this object. | |
388 | */ | |
389 | interface Snapshottable { | |
390 | | |
391 | Object NULL = new Object() { | |
392 | @Override | |
393 | public String toString() { | |
394 |
1
1. toString : replaced return value with "" for com/github/valid8j/pcond/core/Evaluator$Snapshottable$1::toString → SURVIVED |
return "null"; |
395 | } | |
396 | }; | |
397 | | |
398 | Object snapshot(); | |
399 | | |
400 | static Object toSnapshotIfPossible(Object value) { | |
401 |
1
1. toSnapshotIfPossible : negated conditional → KILLED |
if (value instanceof Snapshottable) |
402 |
1
1. toSnapshotIfPossible : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Snapshottable::toSnapshotIfPossible → SURVIVED |
return ((Snapshottable) value).snapshot(); |
403 |
1
1. toSnapshotIfPossible : negated conditional → KILLED |
if (value == null) |
404 |
1
1. toSnapshotIfPossible : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Snapshottable::toSnapshotIfPossible → SURVIVED |
return NULL; |
405 | else | |
406 |
1
1. toSnapshotIfPossible : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Snapshottable::toSnapshotIfPossible → KILLED |
return value; |
407 | } | |
408 | } | |
409 | | |
410 | /** | |
411 | * An interface to define methods that make a predicate "explainable" to humans. | |
412 | */ | |
413 | interface Explainable { | |
414 | Object explainOutputExpectation(); | |
415 | | |
416 | Object explainActual(Object actualValue); | |
417 | | |
418 | static Object explainOutputExpectation(Object evaluable, EvaluableIo<?, ?, ?> evaluableIo) { | |
419 |
1
1. explainOutputExpectation : negated conditional → KILLED |
if (evaluable instanceof Explainable) |
420 |
1
1. explainOutputExpectation : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Explainable::explainOutputExpectation → KILLED |
return InternalUtils.explainValue(((Explainable) evaluable).explainOutputExpectation()); |
421 |
1
1. explainOutputExpectation : negated conditional → SURVIVED |
if (evaluable instanceof Evaluable) |
422 |
1
1. explainOutputExpectation : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Explainable::explainOutputExpectation → SURVIVED |
return formNameOf(evaluableIo); |
423 | return null; | |
424 | } | |
425 | | |
426 | static Object explainInputActualValue(Object evaluable, Object actualValue) { | |
427 |
1
1. explainInputActualValue : negated conditional → KILLED |
if (evaluable instanceof Explainable) |
428 |
1
1. explainInputActualValue : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Explainable::explainInputActualValue → SURVIVED |
return InternalUtils.explainValue(((Explainable) evaluable).explainActual(actualValue)); |
429 | return null; | |
430 | } | |
431 | | |
432 | static <T, E extends Evaluable<T>> Object explainActual(EvaluableIo<T, E, ?> evaluableIo) { | |
433 |
1
1. explainActual : negated conditional → KILLED |
if (evaluableIo.output().state() == VALUE_RETURNED) { |
434 | T ret = evaluableIo.input().returnedValue(); | |
435 |
2
1. explainActual : negated conditional → KILLED 2. explainActual : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Explainable::explainActual → KILLED |
return ret != null ? ret : Impl.NULL_VALUE; |
436 |
1
1. explainActual : negated conditional → KILLED |
} else if (evaluableIo.output().state() == EXCEPTION_THROWN) |
437 |
1
1. explainActual : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Explainable::explainActual → KILLED |
return EvaluationEntry.composeDetailOutputActualValueFromInputAndThrowable(evaluableIo.input().value(), evaluableIo.output().thrownException()); |
438 | else { | |
439 | assert evaluableIo.output().state() == EVALUATION_SKIPPED : "evaluableIo:" + evaluableIo; | |
440 |
1
1. explainActual : replaced return value with null for com/github/valid8j/pcond/core/Evaluator$Explainable::explainActual → SURVIVED |
return EVALUATION_SKIPPED; |
441 | } | |
442 | } | |
443 | } | |
444 | } | |
Mutations | ||
103 |
1.1 |
|
110 |
1.1 |
|
116 |
1.1 |
|
125 |
1.1 |
|
133 |
1.1 |
|
135 |
1.1 |
|
136 |
1.1 |
|
138 |
1.1 |
|
140 |
1.1 |
|
141 |
1.1 |
|
143 |
1.1 |
|
146 |
1.1 2.2 3.3 |
|
149 |
1.1 2.2 |
|
155 |
1.1 |
|
163 |
1.1 |
|
165 |
1.1 |
|
166 |
1.1 |
|
168 |
1.1 |
|
170 |
1.1 |
|
171 |
1.1 |
|
173 |
1.1 |
|
176 |
1.1 2.2 3.3 |
|
179 |
1.1 2.2 |
|
185 |
1.1 |
|
188 |
1.1 |
|
191 |
1.1 |
|
192 |
1.1 2.2 |
|
193 |
1.1 |
|
196 |
1.1 |
|
204 |
1.1 |
|
209 |
1.1 |
|
213 |
1.1 |
|
215 |
1.1 |
|
218 |
1.1 |
|
225 |
1.1 |
|
233 |
1.1 |
|
235 |
1.1 |
|
239 |
1.1 |
|
241 |
1.1 |
|
245 |
1.1 |
|
247 |
1.1 |
|
248 |
1.1 |
|
249 |
1.1 |
|
250 |
1.1 |
|
261 |
1.1 |
|
263 |
1.1 |
|
270 |
1.1 |
|
271 |
1.1 |
|
275 |
1.1 |
|
278 |
1.1 |
|
281 |
1.1 |
|
282 |
1.1 |
|
285 |
1.1 |
|
294 |
1.1 |
|
295 |
1.1 |
|
296 |
1.1 |
|
297 |
1.1 |
|
298 |
1.1 |
|
301 |
1.1 |
|
303 |
1.1 |
|
311 |
1.1 |
|
312 |
1.1 |
|
313 |
1.1 |
|
314 |
1.1 |
|
315 |
1.1 |
|
318 |
1.1 |
|
320 |
1.1 |
|
330 |
1.1 |
|
334 |
1.1 |
|
335 |
1.1 |
|
339 |
1.1 |
|
340 |
1.1 |
|
341 |
1.1 |
|
343 |
1.1 |
|
344 |
1.1 |
|
348 |
1.1 |
|
349 |
1.1 |
|
350 |
1.1 2.2 |
|
352 |
1.1 2.2 |
|
354 |
1.1 2.2 |
|
359 |
1.1 |
|
362 |
1.1 |
|
363 |
1.1 |
|
364 |
1.1 |
|
369 |
1.1 |
|
374 |
1.1 |
|
378 |
1.1 |
|
394 |
1.1 |
|
401 |
1.1 |
|
402 |
1.1 |
|
403 |
1.1 |
|
404 |
1.1 |
|
406 |
1.1 |
|
419 |
1.1 |
|
420 |
1.1 |
|
421 |
1.1 |
|
422 |
1.1 |
|
427 |
1.1 |
|
428 |
1.1 |
|
433 |
1.1 |
|
435 |
1.1 2.2 |
|
436 |
1.1 |
|
437 |
1.1 |
|
440 |
1.1 |