1 | package com.github.dakusui.osynth.annotations; | |
2 | ||
3 | import com.github.dakusui.osynth.core.*; | |
4 | ||
5 | import java.lang.annotation.Retention; | |
6 | import java.lang.reflect.Method; | |
7 | import java.util.Arrays; | |
8 | import java.util.Objects; | |
9 | import java.util.function.Supplier; | |
10 | import java.util.stream.Stream; | |
11 | ||
12 | import static com.github.dakusui.osynth.core.utils.AssertionUtils.methodIsAnnotationPresent; | |
13 | import static com.github.dakusui.osynth.core.utils.MethodUtils.execute; | |
14 | import static com.github.dakusui.osynth.core.utils.MethodUtils.withName; | |
15 | import static com.github.dakusui.pcond.forms.Predicates.and; | |
16 | import static com.github.dakusui.pcond.forms.Predicates.isNotNull; | |
17 | import static com.github.dakusui.valid8j.Assertions.that; | |
18 | import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
19 | import static java.util.stream.Collectors.joining; | |
20 | ||
21 | @Retention(RUNTIME) | |
22 | public @interface BuiltInHandlerFactory { | |
23 | Class<? extends MethodHandlerFactory> value(); | |
24 | ||
25 | interface MethodHandlerFactory { | |
26 | MethodHandler create(Supplier<SynthesizedObject.Descriptor> descriptorSupplier); | |
27 | ||
28 | static MethodHandler createBuiltInMethodHandlerFor(Method method, Supplier<SynthesizedObject.Descriptor> descriptorSupplier) { | |
29 | assert that(method, and( | |
30 | isNotNull(), | |
31 | methodIsAnnotationPresent(BuiltInHandlerFactory.class))); | |
32 | BuiltInHandlerFactory annotation = method.getAnnotation(BuiltInHandlerFactory.class); | |
33 |
2
1. createBuiltInMethodHandlerFor : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::createBuiltInMethodHandlerFor → KILLED 2. lambda$createBuiltInMethodHandlerFor$0 : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$createBuiltInMethodHandlerFor$0 → KILLED |
return execute(() -> withName("builtIn-" + method.getName(), annotation.value().newInstance().create(descriptorSupplier))); |
34 | } | |
35 | ||
36 | static Stream<MethodHandlerEntry> createMethodHandlersForBuiltInMethods(Supplier<SynthesizedObject.Descriptor> descriptorSupplier) { | |
37 |
1
1. createMethodHandlersForBuiltInMethods : replaced return value with Stream.empty for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::createMethodHandlersForBuiltInMethods → KILLED |
return Arrays.stream(SynthesizedObject.class.getMethods()) |
38 |
2
1. lambda$createMethodHandlersForBuiltInMethods$1 : replaced boolean return with false for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$createMethodHandlersForBuiltInMethods$1 → KILLED 2. lambda$createMethodHandlersForBuiltInMethods$1 : replaced boolean return with true for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$createMethodHandlersForBuiltInMethods$1 → KILLED |
.filter(each -> each.isAnnotationPresent(BuiltInHandlerFactory.class)) |
39 | .map((Method eachMethod) -> { | |
40 | MethodSignature targetMethodSignature = MethodSignature.create(eachMethod); | |
41 |
1
1. lambda$createMethodHandlersForBuiltInMethods$4 : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$createMethodHandlersForBuiltInMethods$4 → KILLED |
return MethodHandlerEntry.create( |
42 |
1
1. lambda$null$2 : replaced return value with "" for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$null$2 → SURVIVED |
MethodMatcher.create(mm -> String.format("builtInFor:%s%s", eachMethod.getName(), Arrays.toString(eachMethod.getParameterTypes())), |
43 |
2
1. lambda$null$3 : replaced boolean return with false for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$null$3 → KILLED 2. lambda$null$3 : replaced boolean return with true for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$null$3 → KILLED |
(Method candidate) -> targetMethodSignature.equals(MethodSignature.create(candidate))), |
44 | createBuiltInMethodHandlerFor(eachMethod, descriptorSupplier), true); | |
45 | }); | |
46 | } | |
47 | ||
48 | } | |
49 | ||
50 | class ForToString implements MethodHandlerFactory { | |
51 | @Override | |
52 | public MethodHandler.BuiltIn create(Supplier<SynthesizedObject.Descriptor> descriptorSupplier) { | |
53 |
2
1. create : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForToString::create → KILLED 2. lambda$create$0 : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForToString::lambda$create$0 → KILLED |
return (synthesizedObject, objects) -> composeFormattedString(synthesizedObject); |
54 | } | |
55 | ||
56 | private static String composeFormattedString(SynthesizedObject synthesizedObject) { | |
57 |
1
1. composeFormattedString : replaced return value with "" for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForToString::composeFormattedString → KILLED |
return String.format("osynth(%s):%s", |
58 | synthesizedObject.descriptor().interfaces() | |
59 | .stream() | |
60 | .map(Class::getSimpleName) | |
61 | .collect(joining(",")), | |
62 | synthesizedObject.descriptor()); | |
63 | } | |
64 | } | |
65 | ||
66 | class ForHashCode implements MethodHandlerFactory { | |
67 | @Override | |
68 | public MethodHandler.BuiltIn create(Supplier<SynthesizedObject.Descriptor> descriptorSupplier) { | |
69 |
2
1. create : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForHashCode::create → KILLED 2. lambda$create$0 : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForHashCode::lambda$create$0 → KILLED |
return (synthesizedObject, objects) -> synthesizedObject.descriptor().hashCode(); |
70 | } | |
71 | } | |
72 | ||
73 | class ForEquals implements MethodHandlerFactory { | |
74 | @Override | |
75 | public MethodHandler.BuiltIn create(Supplier<SynthesizedObject.Descriptor> descriptorSupplier) { | |
76 |
1
1. create : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForEquals::create → KILLED |
return (synthesizedObject, objects) -> { |
77 |
1
1. lambda$create$0 : negated conditional → KILLED |
if (synthesizedObject == objects[0]) |
78 |
1
1. lambda$create$0 : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForEquals::lambda$create$0 → KILLED |
return true; |
79 |
1
1. lambda$create$0 : negated conditional → KILLED |
if (!(objects[0] instanceof SynthesizedObject)) |
80 |
1
1. lambda$create$0 : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForEquals::lambda$create$0 → KILLED |
return false; |
81 | SynthesizedObject another = (SynthesizedObject) objects[0]; | |
82 |
1
1. lambda$create$0 : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForEquals::lambda$create$0 → KILLED |
return Objects.equals(synthesizedObject.descriptor(), another.descriptor()); |
83 | }; | |
84 | } | |
85 | } | |
86 | ||
87 | class ForDescriptor implements MethodHandlerFactory { | |
88 | @Override | |
89 | public MethodHandler.BuiltIn create(Supplier<SynthesizedObject.Descriptor> descriptorSupplier) { | |
90 |
2
1. create : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForDescriptor::create → KILLED 2. lambda$create$0 : replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForDescriptor::lambda$create$0 → KILLED |
return (synthesizedObject, objects) -> descriptorSupplier.get(); |
91 | } | |
92 | } | |
93 | } | |
94 | ||
Mutations | ||
33 |
1.1 2.2 |
|
37 |
1.1 |
|
38 |
1.1 2.2 |
|
41 |
1.1 |
|
42 |
1.1 |
|
43 |
1.1 2.2 |
|
53 |
1.1 2.2 |
|
57 |
1.1 |
|
69 |
1.1 2.2 |
|
76 |
1.1 |
|
77 |
1.1 |
|
78 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
82 |
1.1 |
|
90 |
1.1 2.2 |