| 1 | package com.github.dakusui.pcond.core.refl; | |
| 2 | ||
| 3 | import java.util.Arrays; | |
| 4 | import java.util.Objects; | |
| 5 | import java.util.function.Function; | |
| 6 | import java.util.function.Predicate; | |
| 7 | ||
| 8 | import static com.github.dakusui.pcond.core.refl.ReflUtils.replacePlaceHolderWithActualArgument; | |
| 9 | import static com.github.dakusui.pcond.internals.InternalChecks.requireArgument; | |
| 10 | import static java.lang.String.format; | |
| 11 | import static java.util.Objects.requireNonNull; | |
| 12 | import static java.util.stream.Collectors.joining; | |
| 13 | ||
| 14 | /** | |
| 15 | * An interface that models a query to specify a method. | |
| 16 | */ | |
| 17 | public interface MethodQuery { | |
| 18 | boolean isStatic(); | |
| 19 | ||
| 20 | Object targetObject(); | |
| 21 | ||
| 22 | Class<?> targetClass(); | |
| 23 | ||
| 24 | String methodName(); | |
| 25 | ||
| 26 | Object[] arguments(); | |
| 27 | ||
| 28 | /** | |
| 29 | * Returns a string that describes this object. | |
| 30 | * | |
| 31 | * @return A description of this object. | |
| 32 | */ | |
| 33 | String describe(); | |
| 34 | ||
| 35 | default MethodQuery bindActualArguments(Predicate<Object> isPlaceHolder, Function<Object, Object> replace) { | |
| 36 |
1
1. lambda$bindActualArguments$0 : replaced return value with null for com/github/dakusui/pcond/core/refl/MethodQuery::lambda$bindActualArguments$0 → KILLED |
Function<Object, Object> argReplacer = object -> replacePlaceHolderWithActualArgument(object, isPlaceHolder, replace); |
| 37 | Object targetObject = argReplacer.apply(this.targetObject()); | |
| 38 |
1
1. bindActualArguments : replaced return value with null for com/github/dakusui/pcond/core/refl/MethodQuery::bindActualArguments → KILLED |
return create( |
| 39 | this.isStatic(), | |
| 40 | targetObject, | |
| 41 |
1
1. bindActualArguments : negated conditional → KILLED |
this.isStatic() ? this.targetClass() : targetObject.getClass(), |
| 42 | this.methodName(), | |
| 43 | Arrays.stream(this.arguments()).map(argReplacer).toArray()); | |
| 44 | } | |
| 45 | ||
| 46 | static MethodQuery instanceMethod(Object targetObject, String methodName, Object... arguments) { | |
| 47 |
1
1. instanceMethod : replaced return value with null for com/github/dakusui/pcond/core/refl/MethodQuery::instanceMethod → KILLED |
return create(false, requireNonNull(targetObject), ReflUtils.targetTypeOf(targetObject), methodName, arguments); |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Create a `MethodQuery` object to search matching static methods. | |
| 52 | * | |
| 53 | * @param targetClass A class from which a method is searched. | |
| 54 | * @param methodName A name of a method to be searched. | |
| 55 | * @param arguments Argument values; | |
| 56 | * @return A `MethodQuery` object. | |
| 57 | */ | |
| 58 | static MethodQuery classMethod(Class<?> targetClass, String methodName, Object... arguments) { | |
| 59 |
1
1. classMethod : replaced return value with null for com/github/dakusui/pcond/core/refl/MethodQuery::classMethod → KILLED |
return create(true, null, targetClass, methodName, arguments); |
| 60 | } | |
| 61 | ||
| 62 | static MethodQuery create(boolean isStatic, Object targetObject, Class<?> targetClass, String methodName, Object[] arguments) { | |
| 63 | requireNonNull(targetClass); | |
| 64 | requireNonNull(arguments); | |
| 65 | requireNonNull(methodName); | |
| 66 |
1
1. create : negated conditional → KILLED |
if (isStatic) |
| 67 |
1
1. lambda$create$1 : replaced return value with "" for com/github/dakusui/pcond/core/refl/MethodQuery::lambda$create$1 → NO_COVERAGE |
requireArgument(targetObject, Objects::isNull, () -> "targetObject must be null when isStatic is true."); |
| 68 | else { | |
| 69 | requireNonNull(targetObject); | |
| 70 |
3
1. lambda$create$2 : replaced boolean return with true for com/github/dakusui/pcond/core/refl/MethodQuery::lambda$create$2 → SURVIVED 2. lambda$create$3 : replaced return value with "" for com/github/dakusui/pcond/core/refl/MethodQuery::lambda$create$3 → NO_COVERAGE 3. lambda$create$2 : replaced boolean return with false for com/github/dakusui/pcond/core/refl/MethodQuery::lambda$create$2 → KILLED |
requireArgument(targetObject, v -> targetClass.isAssignableFrom(v.getClass()), () -> format("Incompatible object '%s' was given it needs to be assignable to '%s'.", targetObject, targetClass.getName())); |
| 71 | } | |
| 72 | ||
| 73 |
1
1. create : replaced return value with null for com/github/dakusui/pcond/core/refl/MethodQuery::create → KILLED |
return new MethodQuery() { |
| 74 | @Override | |
| 75 | public boolean isStatic() { | |
| 76 |
2
1. isStatic : replaced boolean return with false for com/github/dakusui/pcond/core/refl/MethodQuery$1::isStatic → KILLED 2. isStatic : replaced boolean return with true for com/github/dakusui/pcond/core/refl/MethodQuery$1::isStatic → KILLED |
return isStatic; |
| 77 | } | |
| 78 | ||
| 79 | @Override | |
| 80 | public Object targetObject() { | |
| 81 |
1
1. targetObject : replaced return value with null for com/github/dakusui/pcond/core/refl/MethodQuery$1::targetObject → KILLED |
return targetObject; |
| 82 | } | |
| 83 | ||
| 84 | @Override | |
| 85 | public String methodName() { | |
| 86 |
1
1. methodName : replaced return value with "" for com/github/dakusui/pcond/core/refl/MethodQuery$1::methodName → KILLED |
return methodName; |
| 87 | } | |
| 88 | ||
| 89 | @Override | |
| 90 | public Class<?> targetClass() { | |
| 91 |
1
1. targetClass : replaced return value with null for com/github/dakusui/pcond/core/refl/MethodQuery$1::targetClass → KILLED |
return targetClass; |
| 92 | } | |
| 93 | ||
| 94 | @Override | |
| 95 | public Object[] arguments() { | |
| 96 |
1
1. arguments : replaced return value with null for com/github/dakusui/pcond/core/refl/MethodQuery$1::arguments → KILLED |
return arguments; |
| 97 | } | |
| 98 | ||
| 99 | @Override | |
| 100 | public String describe() { | |
| 101 |
1
1. lambda$describe$0 : replaced return value with "" for com/github/dakusui/pcond/core/refl/MethodQuery$1::lambda$describe$0 → KILLED |
Function<Object, String> parameterFormatter = s -> "<" + s + ">"; |
| 102 |
2
1. describe : negated conditional → KILLED 2. describe : replaced return value with "" for com/github/dakusui/pcond/core/refl/MethodQuery$1::describe → KILLED |
return format("%s.%s(%s)", |
| 103 | isStatic ? | |
| 104 | targetClass.getName() : | |
| 105 | parameterFormatter.apply(targetObject), | |
| 106 | methodName, | |
| 107 | Arrays.stream(arguments) | |
| 108 | .map(parameterFormatter) | |
| 109 | .collect(joining(","))); | |
| 110 | } | |
| 111 | }; | |
| 112 | } | |
| 113 | } | |
Mutations | ||
| 36 |
1.1 |
|
| 38 |
1.1 |
|
| 41 |
1.1 |
|
| 47 |
1.1 |
|
| 59 |
1.1 |
|
| 66 |
1.1 |
|
| 67 |
1.1 |
|
| 70 |
1.1 2.2 3.3 |
|
| 73 |
1.1 |
|
| 76 |
1.1 2.2 |
|
| 81 |
1.1 |
|
| 86 |
1.1 |
|
| 91 |
1.1 |
|
| 96 |
1.1 |
|
| 101 |
1.1 |
|
| 102 |
1.1 2.2 |