1 | package com.github.dakusui.osynth.core; | |
2 | ||
3 | import com.github.dakusui.osynth.core.utils.AssertionUtils; | |
4 | import com.github.dakusui.osynth.exceptions.ValidationException; | |
5 | import com.github.dakusui.osynth.invocationcontrollers.StandardInvocationController; | |
6 | ||
7 | import java.io.ByteArrayOutputStream; | |
8 | import java.io.IOException; | |
9 | import java.io.OutputStream; | |
10 | import java.io.PrintStream; | |
11 | import java.lang.reflect.Proxy; | |
12 | import java.util.*; | |
13 | import java.util.concurrent.atomic.AtomicReference; | |
14 | import java.util.function.BiFunction; | |
15 | import java.util.function.Consumer; | |
16 | import java.util.function.Predicate; | |
17 | import java.util.stream.Collectors; | |
18 | ||
19 | import static com.github.dakusui.osynth.annotations.BuiltInHandlerFactory.MethodHandlerFactory.createMethodHandlersForBuiltInMethods; | |
20 | import static com.github.dakusui.osynth.core.AbstractObjectSynthesizer.InternalUtils.validateValue; | |
21 | import static com.github.dakusui.osynth.core.MethodHandlerDecorator.filterOutPredefinedMethods; | |
22 | import static com.github.dakusui.osynth.core.SynthesizedObject.RESERVED_METHODS; | |
23 | import static com.github.dakusui.osynth.core.utils.AssertionUtils.*; | |
24 | import static com.github.dakusui.osynth.core.utils.MessageUtils.messageForReservedMethodOverridingValidationFailure; | |
25 | import static com.github.dakusui.pcond.forms.Predicates.*; | |
26 | import static com.github.dakusui.pcond.forms.Printables.predicate; | |
27 | import static com.github.dakusui.pcond.internals.InternalUtils.formatObject; | |
28 | import static com.github.dakusui.valid8j.Ensures.ensure; | |
29 | import static com.github.dakusui.valid8j.Requires.*; | |
30 | import static com.github.dakusui.valid8j.Validates.validate; | |
31 | ||
32 | public abstract class AbstractObjectSynthesizer<O extends AbstractObjectSynthesizer<O>> { | |
33 | protected static final Object DEFAULT_FALLBACK_OBJECT = new Object() { | |
34 | @Override | |
35 | public String toString() { | |
36 |
1
1. toString : replaced return value with "" for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$1::toString → SURVIVED |
return "autoCreated:<" + super.toString() + ">"; |
37 | } | |
38 | }; | |
39 | protected final SynthesizedObject.Descriptor.Builder descriptorBuilder; | |
40 | private final AtomicReference<SynthesizedObject.Descriptor> finalizedDescriptor = new AtomicReference<>(null); | |
41 | private Validator validator; | |
42 | private Preprocessor preprocessor; | |
43 | private ClassLoader classLoader; | |
44 | private InvocationControllerFactory invocationControllerFactory; | |
45 | ||
46 | public AbstractObjectSynthesizer(SynthesizedObject.Descriptor.Builder builder) { | |
47 | this.descriptorBuilder = builder; | |
48 | this.classLoader(this.getClass().getClassLoader()) | |
49 | .handleMethodsWithSignatureMatching() | |
50 | .validateWith(Validator.DEFAULT) | |
51 | .preprocessWith(Preprocessor.DEFAULT) | |
52 | .disableMethodHandlerDecorator(); | |
53 | } | |
54 | ||
55 | @SuppressWarnings("unchecked") | |
56 | public O addInterface(Class<?> interfaceClass) { | |
57 | descriptorBuilder.addInterface(interfaceClass); | |
58 |
1
1. addInterface : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::addInterface → KILLED |
return (O) this; |
59 | } | |
60 | ||
61 | @SuppressWarnings("unchecked") | |
62 | public O classLoader(ClassLoader classLoader) { | |
63 | this.classLoader = classLoader; | |
64 |
1
1. classLoader : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::classLoader → KILLED |
return (O) this; |
65 | } | |
66 | ||
67 | @SuppressWarnings("unchecked") | |
68 | public O fallbackTo(Object fallbackObject) { | |
69 | this.descriptorBuilder.fallbackObject(fallbackObject); | |
70 |
1
1. fallbackTo : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::fallbackTo → KILLED |
return (O) this; |
71 | } | |
72 | ||
73 | @SuppressWarnings("unchecked") | |
74 | public O handle(MethodHandlerEntry handlerEntry) { | |
75 | requireNonNull(handlerEntry); | |
76 |
1
1. handle : removed call to com/github/dakusui/osynth/core/SynthesizedObject$Descriptor$Builder::addMethodHandler → KILLED |
this.descriptorBuilder.addMethodHandler(handlerEntry); |
77 |
1
1. handle : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::handle → KILLED |
return (O) this; |
78 | } | |
79 | ||
80 | @SuppressWarnings("unchecked") | |
81 | public O validateWith(Validator validator) { | |
82 | this.validator = requireNonNull(validator); | |
83 |
1
1. validateWith : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::validateWith → KILLED |
return (O) this; |
84 | } | |
85 | ||
86 | public O enableDuplicatedInterfaceCheck() { | |
87 |
1
1. enableDuplicatedInterfaceCheck : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::enableDuplicatedInterfaceCheck → KILLED |
return this.validateWith(Validator.sequence(this.validator(), Validator.ENFORCE_NO_DUPLICATION)); |
88 | ||
89 | } | |
90 | ||
91 | public O disableValidation() { | |
92 |
1
1. disableValidation : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::disableValidation → KILLED |
return this.validateWith(Validator.PASS_THROUGH); |
93 | } | |
94 | ||
95 | @SuppressWarnings("unchecked") | |
96 | public O preprocessWith(Preprocessor preprocessor) { | |
97 | this.preprocessor = requireNonNull(preprocessor); | |
98 |
1
1. preprocessWith : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::preprocessWith → KILLED |
return (O) this; |
99 | } | |
100 | ||
101 | public O includeInterfacesFromFallbackObject() { | |
102 |
1
1. includeInterfacesFromFallbackObject : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::includeInterfacesFromFallbackObject → KILLED |
return this.preprocessWith(Preprocessor.sequence(this.preprocessor(), Preprocessor.INCLUDE_INTERFACES_FROM_FALLBACK)); |
103 | } | |
104 | ||
105 | public O disablePreprocessing() { | |
106 |
1
1. disablePreprocessing : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::disablePreprocessing → KILLED |
return this.preprocessWith(Preprocessor.PASS_THROUGH); |
107 | } | |
108 | ||
109 | @SuppressWarnings("unchecked") | |
110 | public O createInvocationControllerWith(InvocationControllerFactory factory) { | |
111 | this.invocationControllerFactory = requireNonNull(factory); | |
112 |
1
1. createInvocationControllerWith : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::createInvocationControllerWith → KILLED |
return (O) this; |
113 | } | |
114 | ||
115 | @SuppressWarnings("unchecked") | |
116 | public O methodHandlerDecorator(MethodHandlerDecorator methodHandlerDecorator) { | |
117 | this.descriptorBuilder.methodHandlerDecorator(requireNonNull(methodHandlerDecorator)); | |
118 |
1
1. methodHandlerDecorator : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::methodHandlerDecorator → KILLED |
return (O) this; |
119 | } | |
120 | ||
121 | public O disableMethodHandlerDecorator() { | |
122 |
1
1. disableMethodHandlerDecorator : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::disableMethodHandlerDecorator → KILLED |
return this.methodHandlerDecorator(MethodHandlerDecorator.IDENTITY); |
123 | } | |
124 | ||
125 | public O enableAutoLogging() { | |
126 |
1
1. enableAutoLogging : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::enableAutoLogging → KILLED |
return enableAutoLoggingWritingTo(System.err::println); |
127 | } | |
128 | ||
129 | /** | |
130 | * Note that this method is using `defaultLogEntryPrinter(Consumer)`, | |
131 | * which is not meant for production usages. | |
132 | * This method should also not be used in the production. | |
133 | * | |
134 | * @param out A consumer to which log records are sent. | |
135 | * @return This object. | |
136 | */ | |
137 | public O enableAutoLoggingWritingTo(Consumer<String> out) { | |
138 |
1
1. enableAutoLoggingWritingTo : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::enableAutoLoggingWritingTo → KILLED |
return enableAutoLoggingWith(AbstractObjectSynthesizer.defaultLogEntryPrinter(out)); |
139 | } | |
140 | ||
141 | public O enableAutoLoggingWith(AutoLogger autoLogger) { | |
142 |
1
1. enableAutoLoggingWith : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::enableAutoLoggingWith → KILLED |
return this.methodHandlerDecorator(AutoLogger.create(autoLogger)); |
143 | } | |
144 | ||
145 | public O handleMethodsWithSignatureMatching() { | |
146 |
2
1. handleMethodsWithSignatureMatching : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::handleMethodsWithSignatureMatching → KILLED 2. lambda$handleMethodsWithSignatureMatching$0 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::lambda$handleMethodsWithSignatureMatching$0 → KILLED |
return this.createInvocationControllerWith(objectSynthesizer -> new StandardInvocationController(objectSynthesizer.finalizedDescriptor())); |
147 | } | |
148 | ||
149 | public SynthesizedObject synthesize(Object fallbackObject) { | |
150 |
1
1. synthesize : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::synthesize → KILLED |
return this.fallbackTo(fallbackObject).synthesize(); |
151 | } | |
152 | ||
153 | public SynthesizedObject synthesize() { | |
154 |
1
1. synthesize : removed call to com/github/dakusui/osynth/core/AbstractObjectSynthesizer::finalizeDescriptor → KILLED |
finalizeDescriptor( |
155 | preprocessDescriptor( | |
156 | validateDescriptor( | |
157 | this.descriptorBuilder.methodHandlerDecorator( | |
158 | filterOutPredefinedMethods(this.descriptorBuilder.methodHandlerDecorator())) | |
159 | .build()))); | |
160 |
1
1. synthesize : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::synthesize → KILLED |
return (SynthesizedObject) InternalUtils.createProxy(this); |
161 | } | |
162 | ||
163 | public Preprocessor preprocessor() { | |
164 |
1
1. preprocessor : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::preprocessor → KILLED |
return this.preprocessor; |
165 | } | |
166 | ||
167 | public Validator validator() { | |
168 |
1
1. validator : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::validator → KILLED |
return this.validator; |
169 | } | |
170 | ||
171 | public MethodHandlerDecorator methodHandlerDecorator() { | |
172 |
1
1. methodHandlerDecorator : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::methodHandlerDecorator → KILLED |
return this.descriptorBuilder.methodHandlerDecorator(); |
173 | } | |
174 | ||
175 | public SynthesizedObject.Descriptor finalizedDescriptor() { | |
176 |
1
1. finalizedDescriptor : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::finalizedDescriptor → KILLED |
return Optional.ofNullable(finalizedDescriptor.get()) |
177 | .orElseThrow(IllegalAccessError::new); | |
178 | } | |
179 | ||
180 | public boolean isDescriptorFinalized() { | |
181 |
2
1. isDescriptorFinalized : negated conditional → KILLED 2. isDescriptorFinalized : replaced boolean return with true for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::isDescriptorFinalized → KILLED |
return finalizedDescriptor.get() != null; |
182 | } | |
183 | ||
184 | private void finalizeDescriptor(SynthesizedObject.Descriptor descriptor) { | |
185 | requireState(this.isDescriptorFinalized(), isFalse()); | |
186 |
1
1. finalizeDescriptor : removed call to java/util/concurrent/atomic/AtomicReference::set → KILLED |
this.finalizedDescriptor.set(descriptor); |
187 | } | |
188 | ||
189 | private SynthesizedObject.Descriptor validateDescriptor(SynthesizedObject.Descriptor descriptor) { | |
190 | requireState(this.validator, isNotNull()); | |
191 | SynthesizedObject.Descriptor ret = this.validator.apply(this, descriptor); | |
192 | ensure(ret, predicate("Validation must not change the content of the descriptor.", allOf( | |
193 | transform(descriptorInterfaces()).check(isEqualTo(descriptor.interfaces())), | |
194 | transform(descriptorMethodHandlerEntries()).check(isEqualTo(descriptor.methodHandlerEntries())), | |
195 | transform(descriptorFallbackObject()).check(isEqualTo(descriptor.fallbackObject()))))); | |
196 |
1
1. validateDescriptor : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::validateDescriptor → KILLED |
return ret; |
197 | } | |
198 | ||
199 | private SynthesizedObject.Descriptor preprocessDescriptor(SynthesizedObject.Descriptor descriptor) { | |
200 | requireState(this.preprocessor, isNotNull()); | |
201 |
1
1. preprocessDescriptor : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::preprocessDescriptor → KILLED |
return ensure(this.preprocessor.apply(this, descriptor), isNotNull()); |
202 | } | |
203 | ||
204 | /** | |
205 | * Note that the {@link AutoLogger} instance returned by this method is meant | |
206 | * only for demonstrating how the feature works, not for real-production usage. | |
207 | * | |
208 | * @param out A consumer log records sent to. | |
209 | * @return A default log entry printer instance. | |
210 | */ | |
211 | static AutoLogger defaultLogEntryPrinter(Consumer<String> out) { | |
212 |
1
1. defaultLogEntryPrinter : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer::defaultLogEntryPrinter → KILLED |
return entry -> { |
213 |
1
1. lambda$defaultLogEntryPrinter$1 : removed call to java/util/function/Consumer::accept → KILLED |
out.accept(InternalUtils.formatLogEntry(entry)); |
214 |
1
1. lambda$defaultLogEntryPrinter$1 : negated conditional → KILLED |
if (entry.type() == AutoLogger.Entry.Type.EXCEPTION) { |
215 | require(entry.value(), isInstanceOf(Throwable.class)); | |
216 | try (PrintStream ps = InternalUtils.toPrintStream(out)) { | |
217 |
1
1. lambda$defaultLogEntryPrinter$1 : removed call to java/lang/Throwable::printStackTrace → SURVIVED |
((Throwable) entry.value()).printStackTrace(ps); |
218 | } | |
219 | } | |
220 | }; | |
221 | } | |
222 | ||
223 | enum InternalUtils { | |
224 | ; | |
225 | ||
226 | static Object createProxy(AbstractObjectSynthesizer<?> objectSynthesizer) { | |
227 | SynthesizedObject.Descriptor descriptor = objectSynthesizer.finalizedDescriptor(); | |
228 |
1
1. createProxy : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::createProxy → KILLED |
return Proxy.newProxyInstance( |
229 | objectSynthesizer.classLoader, | |
230 | descriptor.interfaces().toArray(new Class[0]), | |
231 | objectSynthesizer.invocationControllerFactory.apply(objectSynthesizer)); | |
232 | } | |
233 | ||
234 | public static List<Object> reservedMethodMisOverridings(Collection<MethodHandlerEntry> methodHandlerEntries) { | |
235 |
1
1. reservedMethodMisOverridings : replaced return value with Collections.emptyList for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::reservedMethodMisOverridings → KILLED |
return methodHandlerEntries |
236 | .stream() | |
237 |
1
1. lambda$reservedMethodMisOverridings$1 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::lambda$reservedMethodMisOverridings$1 → KILLED |
.map((MethodHandlerEntry methodHandlerEntry) -> new ReservedMethodViolation( |
238 | methodHandlerEntry, | |
239 | RESERVED_METHODS | |
240 | .stream() | |
241 |
2
1. lambda$null$0 : replaced boolean return with false for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::lambda$null$0 → KILLED 2. lambda$null$0 : replaced boolean return with true for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::lambda$null$0 → KILLED |
.filter(method -> methodHandlerEntry.matcher().test(method)) |
242 | .map(MethodSignature::create) | |
243 | .collect(Collectors.toList()))) | |
244 |
2
1. lambda$reservedMethodMisOverridings$2 : negated conditional → KILLED 2. lambda$reservedMethodMisOverridings$2 : replaced boolean return with true for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::lambda$reservedMethodMisOverridings$2 → KILLED |
.filter(reservedMethodViolation -> !reservedMethodViolation.violatedReservedMethods.isEmpty()) |
245 | .collect(Collectors.toList()); | |
246 | } | |
247 | ||
248 | static <V> void validateValue(V value, Predicate<V> predicate) { | |
249 | validate( | |
250 | value, | |
251 | predicate, | |
252 | s -> { | |
253 | throw new ValidationException(s); | |
254 | } | |
255 | ); | |
256 | } | |
257 | ||
258 | private static String formatLogEntry(AutoLogger.Entry logEntry) { | |
259 | String valueType = logEntry.type().outputValueLabel(); | |
260 | ||
261 |
1
1. formatLogEntry : replaced return value with "" for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::formatLogEntry → KILLED |
return String.format( |
262 | "%-10s class:<%s> method:<%s> object:<%10s> %s:<%s>", | |
263 | logEntry.type() + ":", | |
264 | logEntry.method().getDeclaringClass().getSimpleName(), | |
265 | MethodSignature.create(logEntry.method()), | |
266 | formatObject(logEntry.object(), 20), | |
267 | valueType, | |
268 | formatObject(logEntry.value(), 80)); | |
269 | } | |
270 | ||
271 | private static PrintStream toPrintStream(Consumer<String> out) { | |
272 |
1
1. toPrintStream : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::toPrintStream → KILLED |
return new PrintStream(new OutputStream() { |
273 | final ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
274 | final char LINE_SEPARATOR_CHAR = String.format("%n").charAt(0); | |
275 | ||
276 | @Override | |
277 | public void write(int b) { | |
278 |
1
1. write : negated conditional → SURVIVED |
if (b == LINE_SEPARATOR_CHAR) { |
279 |
1
1. write : removed call to com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils$1::lineBreak → SURVIVED |
lineBreak(); |
280 | } else { | |
281 |
1
1. write : removed call to java/io/ByteArrayOutputStream::write → SURVIVED |
bos.write(b); |
282 | } | |
283 | } | |
284 | ||
285 | private void lineBreak() { | |
286 |
1
1. lineBreak : removed call to java/util/function/Consumer::accept → SURVIVED |
out.accept(bos.toString()); |
287 |
1
1. lineBreak : removed call to java/io/ByteArrayOutputStream::reset → SURVIVED |
bos.reset(); |
288 | } | |
289 | ||
290 | @Override | |
291 | public void close() throws IOException { | |
292 |
1
1. close : removed call to java/io/OutputStream::close → SURVIVED |
super.close(); |
293 |
1
1. close : removed call to com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils$1::lineBreak → SURVIVED |
lineBreak(); |
294 | } | |
295 | }); | |
296 | } | |
297 | ||
298 | static class ReservedMethodViolation { | |
299 | final List<MethodSignature> violatedReservedMethods; | |
300 | final MethodHandlerEntry violatingEntry; | |
301 | ||
302 | ReservedMethodViolation(MethodHandlerEntry violatingEntry, List<MethodSignature> violatedReservedMethods) { | |
303 | this.violatedReservedMethods = violatedReservedMethods; | |
304 | this.violatingEntry = violatingEntry; | |
305 | } | |
306 | ||
307 | @Override | |
308 | public String toString() { | |
309 |
1
1. toString : replaced return value with "" for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils$ReservedMethodViolation::toString → KILLED |
return String.format("violation:entry:%s -> %s", violatingEntry, violatedReservedMethods); |
310 | } | |
311 | } | |
312 | } | |
313 | ||
314 | interface Stage extends BiFunction<AbstractObjectSynthesizer<?>, SynthesizedObject.Descriptor, SynthesizedObject.Descriptor> { | |
315 | } | |
316 | ||
317 | public interface Validator extends Stage { | |
318 | Validator DEFAULT = toNamed("defaultValidator", (objectSynthesizer, descriptor) -> { | |
319 | require(objectSynthesizer, isNotNull()); | |
320 | require(descriptor, isNotNull()); | |
321 |
1
1. lambda$static$1 : removed call to com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::validateValue → KILLED |
validateValue( |
322 | descriptor, | |
323 | predicate( | |
324 |
1
1. lambda$null$0 : replaced return value with "" for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Validator::lambda$null$0 → KILLED |
() -> messageForReservedMethodOverridingValidationFailure(InternalUtils.reservedMethodMisOverridings(descriptor.methodHandlerEntries())), |
325 | transform(descriptorMethodHandlerEntries() | |
326 | .andThen(AbstractObjectSynthesizer.InternalUtils::reservedMethodMisOverridings)) | |
327 | .check(isEmpty()))); | |
328 |
1
1. lambda$static$1 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Validator::lambda$static$1 → KILLED |
return descriptor; |
329 | }); | |
330 | ||
331 | Validator ENFORCE_NO_DUPLICATION = toNamed("noDuplicationEnforcingValidator", (objectSynthesizer, descriptor) -> { | |
332 | require(objectSynthesizer, isNotNull()); | |
333 | require(descriptor, isNotNull()); | |
334 |
1
1. lambda$static$2 : removed call to com/github/dakusui/osynth/core/AbstractObjectSynthesizer$InternalUtils::validateValue → KILLED |
validateValue(descriptor, transform(descriptorInterfaces().andThen(AssertionUtils.collectionDuplicatedElements())).check(isEmpty())); |
335 |
1
1. lambda$static$2 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Validator::lambda$static$2 → KILLED |
return descriptor; |
336 | }); | |
337 | ||
338 |
1
1. lambda$static$3 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Validator::lambda$static$3 → KILLED |
Validator PASS_THROUGH = toNamed("passThroughValidator", (objectSynthesizer, descriptor) -> descriptor); |
339 | ||
340 | static Validator sequence(Validator... validators) { | |
341 |
1
1. sequence : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Validator::sequence → KILLED |
return toNamed("validatorSequence:" + Arrays.toString(validators), (objectSynthesizer, descriptor) -> { |
342 | SynthesizedObject.Descriptor ret = descriptor; | |
343 | for (Validator each : validators) { | |
344 | ret = requireNonNull(each).apply(objectSynthesizer, descriptor); | |
345 | ensure(ret, predicate("Validation must not change the content of the descriptor.", allOf( | |
346 | transform(descriptorInterfaces()).check(isEqualTo(descriptor.interfaces())), | |
347 | transform(descriptorMethodHandlerEntries()).check(isEqualTo(descriptor.methodHandlerEntries())), | |
348 | transform(descriptorFallbackObject()).check(isEqualTo(descriptor.fallbackObject()))))); | |
349 | } | |
350 |
1
1. lambda$sequence$4 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Validator::lambda$sequence$4 → KILLED |
return ret; |
351 | }); | |
352 | } | |
353 | ||
354 | static Validator toNamed(String name, Validator validator) { | |
355 | require(name, isNotNull()); | |
356 | require(validator, isNotNull()); | |
357 |
1
1. toNamed : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Validator::toNamed → KILLED |
return new Validator() { |
358 | @Override | |
359 | public SynthesizedObject.Descriptor apply(AbstractObjectSynthesizer<?> objectSynthesizer, SynthesizedObject.Descriptor descriptor) { | |
360 |
1
1. apply : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Validator$1::apply → KILLED |
return validator.apply(objectSynthesizer, descriptor); |
361 | } | |
362 | ||
363 | @Override | |
364 | public String toString() { | |
365 |
1
1. toString : replaced return value with "" for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Validator$1::toString → SURVIVED |
return name; |
366 | } | |
367 | }; | |
368 | } | |
369 | ||
370 | SynthesizedObject.Descriptor apply( | |
371 | AbstractObjectSynthesizer<?> objectSynthesizer, | |
372 | SynthesizedObject.Descriptor descriptor); | |
373 | } | |
374 | ||
375 | public interface Preprocessor { | |
376 | Preprocessor INCLUDE_BUILTIN_METHOD_HANDLERS = toNamed("builtInMethodHandlers", ((objectSynthesizer, descriptor) -> { | |
377 | SynthesizedObject.Descriptor.Builder builder = new SynthesizedObject.Descriptor.Builder(descriptor); | |
378 | createMethodHandlersForBuiltInMethods(objectSynthesizer::finalizedDescriptor) | |
379 |
1
1. lambda$static$0 : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach(builder::addMethodHandler); |
380 |
1
1. lambda$static$0 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::lambda$static$0 → KILLED |
return builder.build(); |
381 | })); | |
382 | Preprocessor INCLUDE_BUILTIN_INTERFACES = toNamed("builtInInterfaces", ((objectSynthesizer, descriptor) -> { | |
383 | SynthesizedObject.Descriptor.Builder builder = new SynthesizedObject.Descriptor.Builder(descriptor); | |
384 |
1
1. lambda$static$1 : negated conditional → KILLED |
if (!builder.interfaces().contains(SynthesizedObject.class)) |
385 | builder.addInterface(SynthesizedObject.class); | |
386 |
1
1. lambda$static$1 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::lambda$static$1 → KILLED |
return builder.build(); |
387 | })); | |
388 | ||
389 | Preprocessor DEFAULT = toNamed("defaultPreprocessor", sequence( | |
390 | INCLUDE_BUILTIN_METHOD_HANDLERS, | |
391 | INCLUDE_BUILTIN_INTERFACES | |
392 | )); | |
393 | Preprocessor INCLUDE_INTERFACES_FROM_FALLBACK = toNamed("interfacesFromFallback", (objectSynthesizer, descriptor) -> { | |
394 | SynthesizedObject.Descriptor.Builder builder = new SynthesizedObject.Descriptor.Builder(descriptor); | |
395 | Set<Class<?>> interfacesInOriginalDescriptor = new HashSet<>(descriptor.interfaces()); | |
396 | Arrays.stream(descriptor.fallbackObject().getClass().getInterfaces()) | |
397 |
2
1. lambda$null$2 : negated conditional → KILLED 2. lambda$null$2 : replaced boolean return with true for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::lambda$null$2 → KILLED |
.filter(eachInterfaceInFallback -> !interfacesInOriginalDescriptor.contains(eachInterfaceInFallback)) |
398 |
1
1. lambda$static$3 : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach(builder::addInterface); |
399 |
1
1. lambda$static$3 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::lambda$static$3 → KILLED |
return builder.build(); |
400 | }); | |
401 | ||
402 |
1
1. lambda$static$4 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::lambda$static$4 → KILLED |
Preprocessor PASS_THROUGH = toNamed("passThrough", (objectSynthesizer, descriptor) -> descriptor); |
403 | ||
404 | static Preprocessor importDescriptorFromAnotherSynthesizedObject(SynthesizedObject.Descriptor descriptor) { | |
405 |
1
1. importDescriptorFromAnotherSynthesizedObject : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::importDescriptorFromAnotherSynthesizedObject → KILLED |
return toNamed( |
406 | "importDescriptorFromAnotherSynthesizedObject", | |
407 |
1
1. lambda$importDescriptorFromAnotherSynthesizedObject$5 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::lambda$importDescriptorFromAnotherSynthesizedObject$5 → KILLED |
(objectSynthesizer, descriptorFromThisSynthesizer) -> SynthesizedObject.Descriptor.merge(descriptorFromThisSynthesizer, descriptor)); |
408 | } | |
409 | ||
410 | ||
411 | SynthesizedObject.Descriptor apply( | |
412 | AbstractObjectSynthesizer<?> objectSynthesizer, | |
413 | SynthesizedObject.Descriptor descriptor); | |
414 | ||
415 | static Preprocessor sequence(Preprocessor... preprocessors) { | |
416 |
1
1. sequence : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::sequence → KILLED |
return toNamed("preprocessorSequence:" + Arrays.toString(preprocessors), (objectSynthesizer, descriptor) -> { |
417 | SynthesizedObject.Descriptor ret = descriptor; | |
418 | for (Preprocessor each : preprocessors) { | |
419 | ret = ensure(requireNonNull(each).apply(objectSynthesizer, ret), isNotNull()); | |
420 | } | |
421 |
1
1. lambda$sequence$6 : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::lambda$sequence$6 → KILLED |
return ret; |
422 | }); | |
423 | } | |
424 | ||
425 | static Preprocessor toNamed(String name, Preprocessor preprocessor) { | |
426 | require(name, isNotNull()); | |
427 | require(preprocessor, isNotNull()); | |
428 |
1
1. toNamed : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor::toNamed → KILLED |
return new Preprocessor() { |
429 | @Override | |
430 | public SynthesizedObject.Descriptor apply(AbstractObjectSynthesizer<?> objectSynthesizer, SynthesizedObject.Descriptor descriptor) { | |
431 |
1
1. apply : replaced return value with null for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor$1::apply → KILLED |
return preprocessor.apply(objectSynthesizer, descriptor); |
432 | } | |
433 | ||
434 | @Override | |
435 | public String toString() { | |
436 |
1
1. toString : replaced return value with "" for com/github/dakusui/osynth/core/AbstractObjectSynthesizer$Preprocessor$1::toString → SURVIVED |
return name; |
437 | } | |
438 | ||
439 | }; | |
440 | } | |
441 | } | |
442 | } | |
Mutations | ||
36 |
1.1 |
|
58 |
1.1 |
|
64 |
1.1 |
|
70 |
1.1 |
|
76 |
1.1 |
|
77 |
1.1 |
|
83 |
1.1 |
|
87 |
1.1 |
|
92 |
1.1 |
|
98 |
1.1 |
|
102 |
1.1 |
|
106 |
1.1 |
|
112 |
1.1 |
|
118 |
1.1 |
|
122 |
1.1 |
|
126 |
1.1 |
|
138 |
1.1 |
|
142 |
1.1 |
|
146 |
1.1 2.2 |
|
150 |
1.1 |
|
154 |
1.1 |
|
160 |
1.1 |
|
164 |
1.1 |
|
168 |
1.1 |
|
172 |
1.1 |
|
176 |
1.1 |
|
181 |
1.1 2.2 |
|
186 |
1.1 |
|
196 |
1.1 |
|
201 |
1.1 |
|
212 |
1.1 |
|
213 |
1.1 |
|
214 |
1.1 |
|
217 |
1.1 |
|
228 |
1.1 |
|
235 |
1.1 |
|
237 |
1.1 |
|
241 |
1.1 2.2 |
|
244 |
1.1 2.2 |
|
261 |
1.1 |
|
272 |
1.1 |
|
278 |
1.1 |
|
279 |
1.1 |
|
281 |
1.1 |
|
286 |
1.1 |
|
287 |
1.1 |
|
292 |
1.1 |
|
293 |
1.1 |
|
309 |
1.1 |
|
321 |
1.1 |
|
324 |
1.1 |
|
328 |
1.1 |
|
334 |
1.1 |
|
335 |
1.1 |
|
338 |
1.1 |
|
341 |
1.1 |
|
350 |
1.1 |
|
357 |
1.1 |
|
360 |
1.1 |
|
365 |
1.1 |
|
379 |
1.1 |
|
380 |
1.1 |
|
384 |
1.1 |
|
386 |
1.1 |
|
397 |
1.1 2.2 |
|
398 |
1.1 |
|
399 |
1.1 |
|
402 |
1.1 |
|
405 |
1.1 |
|
407 |
1.1 |
|
416 |
1.1 |
|
421 |
1.1 |
|
428 |
1.1 |
|
431 |
1.1 |
|
436 |
1.1 |