| 1 | package com.github.dakusui.osynth; | |
| 2 | ||
| 3 | import com.github.dakusui.osynth.core.*; | |
| 4 | ||
| 5 | import java.lang.annotation.Annotation; | |
| 6 | import java.lang.reflect.Method; | |
| 7 | import java.util.Arrays; | |
| 8 | import java.util.Objects; | |
| 9 | import java.util.concurrent.atomic.AtomicInteger; | |
| 10 | import java.util.function.Function; | |
| 11 | import java.util.function.Predicate; | |
| 12 | import java.util.regex.Pattern; | |
| 13 | ||
| 14 | import static com.github.dakusui.osynth.core.AbstractObjectSynthesizer.Preprocessor.importDescriptorFromAnotherSynthesizedObject; | |
| 15 | import static com.github.dakusui.osynth.core.utils.MethodUtils.*; | |
| 16 | import static java.lang.String.format; | |
| 17 | ||
| 18 | /** | |
| 19 | * The main entry pont of the `osynth` object synthesizer library. | |
| 20 | */ | |
| 21 | public class ObjectSynthesizer extends AbstractObjectSynthesizer<ObjectSynthesizer> { | |
| 22 | ||
| 23 | public ObjectSynthesizer() { | |
| 24 | super(new SynthesizedObject.Descriptor.Builder() | |
| 25 | .fallbackObject(DEFAULT_FALLBACK_OBJECT)); | |
| 26 | } | |
| 27 | ||
| 28 | public ObjectSynthesizer(SynthesizedObject.Descriptor descriptor) { | |
| 29 | super(new SynthesizedObject.Descriptor.Builder(descriptor)); | |
| 30 | } | |
| 31 | ||
| 32 | public static MethodHandlerEntry.Builder methodCall(String methodName, Class<?>... parameterTypes) { | |
| 33 |
1
1. methodCall : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::methodCall → KILLED |
return methodCall(MethodSignature.create(methodName, parameterTypes)); |
| 34 | } | |
| 35 | ||
| 36 | public static MethodHandlerEntry.Builder methodCall(MethodSignature methodSignature) { | |
| 37 |
1
1. methodCall : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::methodCall → KILLED |
return new MethodHandlerEntry.Builder().matcher(matchingExactly(methodSignature)); |
| 38 | } | |
| 39 | ||
| 40 | public static MethodHandlerEntry.Builder methodCall(MethodMatcher matcher) { | |
| 41 |
1
1. methodCall : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::methodCall → KILLED |
return new MethodHandlerEntry.Builder().matcher(matcher); |
| 42 | } | |
| 43 | ||
| 44 | public static MethodMatcher matchingExactly(MethodSignature signature) { | |
| 45 |
2
1. lambda$matchingExactly$0 : replaced return value with "" for com/github/dakusui/osynth/ObjectSynthesizer::lambda$matchingExactly$0 → KILLED 2. matchingExactly : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::matchingExactly → KILLED |
return MethodMatcher.overrideToString(mm -> ("matchingExactly:" + mm.toString()), nameMatchingExactly(signature.name()).and(parameterTypesMatchingExactly(signature.parameterTypes()))); |
| 46 | } | |
| 47 | ||
| 48 | /** | |
| 49 | * Returns a "lenient" method matcher by signature. | |
| 50 | * The returned matcher checks if | |
| 51 | * | |
| 52 | * 1. The name of a method to be tested if it is matching the name of the `targetMethodSignature` as a regular expression. | |
| 53 | * 2. Every parameter types of the method to be tested is equal to or more special than the corresponding parameter type in the `signature`. | |
| 54 | * | |
| 55 | * If the signature doesn't have any parameter types, it matches a method without | |
| 56 | * any parameters. | |
| 57 | * In case you want to create a matcher that matches a method with a specific name but | |
| 58 | * doesn't care any parameter types, use {@link ObjectSynthesizer#nameMatchingRegex(String)} | |
| 59 | * or {@link ObjectSynthesizer#nameMatchingExactly(String)}. | |
| 60 | * | |
| 61 | * ,@param signature The method signature that matches a returned matcher. | |
| 62 | * | |
| 63 | * @return A method matcher by signature. | |
| 64 | */ | |
| 65 | public static MethodMatcher matchingLeniently(MethodSignature signature) { | |
| 66 |
2
1. lambda$matchingLeniently$1 : replaced return value with "" for com/github/dakusui/osynth/ObjectSynthesizer::lambda$matchingLeniently$1 → KILLED 2. matchingLeniently : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::matchingLeniently → KILLED |
return MethodMatcher.overrideToString(mm -> ("matchingLeniently:" + mm.toString()), nameMatchingRegex(signature.name()).and(parameterTypesMatchingLeniently(signature.parameterTypes()))); |
| 67 | } | |
| 68 | ||
| 69 | public static MethodMatcher nameMatchingExactly(String methodName) { | |
| 70 |
1
1. nameMatchingExactly : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::nameMatchingExactly → KILLED |
return MethodMatcher.create( |
| 71 |
1
1. lambda$nameMatchingExactly$2 : replaced return value with "" for com/github/dakusui/osynth/ObjectSynthesizer::lambda$nameMatchingExactly$2 → KILLED |
(mm) -> format("nameMatchingExactly[%s]", methodName), |
| 72 |
2
1. lambda$nameMatchingExactly$3 : replaced boolean return with false for com/github/dakusui/osynth/ObjectSynthesizer::lambda$nameMatchingExactly$3 → KILLED 2. lambda$nameMatchingExactly$3 : replaced boolean return with true for com/github/dakusui/osynth/ObjectSynthesizer::lambda$nameMatchingExactly$3 → KILLED |
method -> Objects.equals(methodName, method.getName())); |
| 73 | } | |
| 74 | ||
| 75 | public static MethodMatcher nameMatchingRegex(String regexForMethodName) { | |
| 76 | Pattern regex = Pattern.compile(regexForMethodName); | |
| 77 |
1
1. nameMatchingRegex : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::nameMatchingRegex → KILLED |
return MethodMatcher.create( |
| 78 |
1
1. lambda$nameMatchingRegex$4 : replaced return value with "" for com/github/dakusui/osynth/ObjectSynthesizer::lambda$nameMatchingRegex$4 → KILLED |
(mm) -> format("nameMatchingRegex[%s]", regexForMethodName), |
| 79 |
2
1. lambda$nameMatchingRegex$5 : replaced boolean return with false for com/github/dakusui/osynth/ObjectSynthesizer::lambda$nameMatchingRegex$5 → KILLED 2. lambda$nameMatchingRegex$5 : replaced boolean return with true for com/github/dakusui/osynth/ObjectSynthesizer::lambda$nameMatchingRegex$5 → KILLED |
method -> regex.matcher(method.getName()).matches()); |
| 80 | } | |
| 81 | ||
| 82 | public static MethodMatcher parameterTypesMatchingExactly(Class<?>[] parameterTypes) { | |
| 83 |
1
1. parameterTypesMatchingExactly : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::parameterTypesMatchingExactly → KILLED |
return MethodMatcher.create( |
| 84 |
1
1. lambda$parameterTypesMatchingExactly$6 : replaced return value with "" for com/github/dakusui/osynth/ObjectSynthesizer::lambda$parameterTypesMatchingExactly$6 → SURVIVED |
(mm) -> format("parameterTypesMatchingExactly%s", Arrays.toString(parameterTypes)), |
| 85 |
2
1. lambda$parameterTypesMatchingExactly$7 : replaced boolean return with false for com/github/dakusui/osynth/ObjectSynthesizer::lambda$parameterTypesMatchingExactly$7 → KILLED 2. lambda$parameterTypesMatchingExactly$7 : replaced boolean return with true for com/github/dakusui/osynth/ObjectSynthesizer::lambda$parameterTypesMatchingExactly$7 → KILLED |
method -> Arrays.equals(parameterTypes, method.getParameterTypes()) |
| 86 | ); | |
| 87 | } | |
| 88 | ||
| 89 | public static MethodMatcher parameterTypesMatchingLeniently(Class<?>[] parameterTypes) { | |
| 90 |
1
1. parameterTypesMatchingLeniently : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::parameterTypesMatchingLeniently → KILLED |
return MethodMatcher.create( |
| 91 |
1
1. lambda$parameterTypesMatchingLeniently$8 : replaced return value with "" for com/github/dakusui/osynth/ObjectSynthesizer::lambda$parameterTypesMatchingLeniently$8 → SURVIVED |
(mm) -> format("parameterTypesMatchingLeniently%s", Arrays.toString(parameterTypes)), |
| 92 | method -> { | |
| 93 | AtomicInteger i = new AtomicInteger(0); | |
| 94 |
2
1. lambda$parameterTypesMatchingLeniently$10 : negated conditional → KILLED 2. lambda$parameterTypesMatchingLeniently$10 : replaced boolean return with true for com/github/dakusui/osynth/ObjectSynthesizer::lambda$parameterTypesMatchingLeniently$10 → KILLED |
return parameterTypes.length == method.getParameterTypes().length && |
| 95 | Arrays.stream(method.getParameterTypes()) | |
| 96 |
3
1. lambda$null$9 : replaced boolean return with false for com/github/dakusui/osynth/ObjectSynthesizer::lambda$null$9 → KILLED 2. lambda$null$9 : replaced boolean return with true for com/github/dakusui/osynth/ObjectSynthesizer::lambda$null$9 → KILLED 3. lambda$parameterTypesMatchingLeniently$10 : negated conditional → KILLED |
.allMatch(type -> type.isAssignableFrom(parameterTypes[i.getAndIncrement()])); |
| 97 | } | |
| 98 | ); | |
| 99 | } | |
| 100 | ||
| 101 | public static <A extends Annotation> MethodMatcher annotatedWith(Class<A> annotationClass) { | |
| 102 |
1
1. annotatedWith : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::annotatedWith → KILLED |
return matching( |
| 103 |
1
1. lambda$annotatedWith$11 : replaced return value with "" for com/github/dakusui/osynth/ObjectSynthesizer::lambda$annotatedWith$11 → KILLED |
m -> "annotatedWith(@" + simpleClassNameOf(annotationClass) + ")", |
| 104 |
2
1. lambda$annotatedWith$12 : replaced boolean return with false for com/github/dakusui/osynth/ObjectSynthesizer::lambda$annotatedWith$12 → KILLED 2. lambda$annotatedWith$12 : replaced boolean return with true for com/github/dakusui/osynth/ObjectSynthesizer::lambda$annotatedWith$12 → KILLED |
method -> method.isAnnotationPresent(annotationClass)); |
| 105 | } | |
| 106 | ||
| 107 | public static <A extends Annotation> MethodMatcher annotatedWith(Class<A> annotationClass, Predicate<A> annotationPredicate) { | |
| 108 |
1
1. annotatedWith : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::annotatedWith → KILLED |
return annotatedWith(annotationClass).and( |
| 109 | matching( | |
| 110 |
1
1. lambda$annotatedWith$13 : replaced return value with "" for com/github/dakusui/osynth/ObjectSynthesizer::lambda$annotatedWith$13 → KILLED |
m -> "satisfying:" + prettierToString(m), |
| 111 |
2
1. lambda$annotatedWith$14 : replaced boolean return with false for com/github/dakusui/osynth/ObjectSynthesizer::lambda$annotatedWith$14 → KILLED 2. lambda$annotatedWith$14 : replaced boolean return with true for com/github/dakusui/osynth/ObjectSynthesizer::lambda$annotatedWith$14 → KILLED |
m -> annotationPredicate.test(m.getAnnotation(annotationClass)))); |
| 112 | } | |
| 113 | ||
| 114 | public static MethodMatcher matching(Function<MethodMatcher, String> nameComposer, Predicate<Method> p) { | |
| 115 |
1
1. matching : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::matching → KILLED |
return MethodMatcher.create(nameComposer, p); |
| 116 | } | |
| 117 | ||
| 118 | public static ObjectSynthesizer from(SynthesizedObject.Descriptor descriptor) { | |
| 119 | ObjectSynthesizer ret; | |
| 120 |
1
1. from : replaced return value with null for com/github/dakusui/osynth/ObjectSynthesizer::from → KILLED |
return (ret = new ObjectSynthesizer()).preprocessWith(Preprocessor.sequence( |
| 121 | importDescriptorFromAnotherSynthesizedObject(descriptor), | |
| 122 | ret.preprocessor())); | |
| 123 | } | |
| 124 | } | |
Mutations | ||
| 33 |
1.1 |
|
| 37 |
1.1 |
|
| 41 |
1.1 |
|
| 45 |
1.1 2.2 |
|
| 66 |
1.1 2.2 |
|
| 70 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 2.2 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 2.2 |
|
| 83 |
1.1 |
|
| 84 |
1.1 |
|
| 85 |
1.1 2.2 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 94 |
1.1 2.2 |
|
| 96 |
1.1 2.2 3.3 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 2.2 |
|
| 108 |
1.1 |
|
| 110 |
1.1 |
|
| 111 |
1.1 2.2 |
|
| 115 |
1.1 |
|
| 120 |
1.1 |