BuiltInHandlerFactory.java

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
Location : createBuiltInMethodHandlerFor
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.givenSynthesizerWithInterfaceBTwice$whenSynthesize$thenThrowsException(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::createBuiltInMethodHandlerFor → KILLED

2.2
Location : lambda$createBuiltInMethodHandlerFor$0
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.givenSynthesizerWithInterfaceBTwice$whenSynthesize$thenThrowsException(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$createBuiltInMethodHandlerFor$0 → KILLED

37

1.1
Location : createMethodHandlersForBuiltInMethods
Killed by : com.github.dakusui.osynth.ut.core.SynthesizedObjectTest.descriptorSameReference(com.github.dakusui.osynth.ut.core.SynthesizedObjectTest)
replaced return value with Stream.empty for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::createMethodHandlersForBuiltInMethods → KILLED

38

1.1
Location : lambda$createMethodHandlersForBuiltInMethods$1
Killed by : com.github.dakusui.osynth.ut.core.SynthesizedObjectTest.descriptorSameReference(com.github.dakusui.osynth.ut.core.SynthesizedObjectTest)
replaced boolean return with false for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$createMethodHandlersForBuiltInMethods$1 → KILLED

2.2
Location : lambda$createMethodHandlersForBuiltInMethods$1
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.givenSynthesizerWithInterfaceBTwice$whenSynthesize$thenThrowsException(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced boolean return with true for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$createMethodHandlersForBuiltInMethods$1 → KILLED

41

1.1
Location : lambda$createMethodHandlersForBuiltInMethods$4
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.givenSynthesizerWithInterfaceBTwice$whenSynthesize$thenThrowsException(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$createMethodHandlersForBuiltInMethods$4 → KILLED

42

1.1
Location : lambda$null$2
Killed by : none
replaced return value with "" for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$null$2 → SURVIVED

43

1.1
Location : lambda$null$3
Killed by : com.github.dakusui.osynth.ut.core.SynthesizedObjectTest.descriptorSameReference(com.github.dakusui.osynth.ut.core.SynthesizedObjectTest)
replaced boolean return with false for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$null$3 → KILLED

2.2
Location : lambda$null$3
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.whenEqualsItself$thenTrue(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced boolean return with true for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$MethodHandlerFactory::lambda$null$3 → KILLED

53

1.1
Location : create
Killed by : com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest.notGivenAnyObjectForFallback$whenSynthesizeAndCallMethod$thenDoesntBreak(com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForToString::create → KILLED

2.2
Location : lambda$create$0
Killed by : com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest.notGivenAnyObjectForFallback$whenSynthesizeAndCallMethod$thenDoesntBreak(com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForToString::lambda$create$0 → KILLED

57

1.1
Location : composeFormattedString
Killed by : com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest.notGivenAnyObjectForFallback$whenSynthesizeAndCallMethod$thenDoesntBreak(com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest)
replaced return value with "" for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForToString::composeFormattedString → KILLED

69

1.1
Location : create
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.givenSynthesizedObjectsFromDifferentDefinitions$whenEquals$thenFalse(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForHashCode::create → KILLED

2.2
Location : lambda$create$0
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.givenSynthesizedObjectsFromDifferentDefinitions$whenEquals$thenFalse(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForHashCode::lambda$create$0 → KILLED

76

1.1
Location : create
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.whenEqualsItself$thenTrue(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForEquals::create → KILLED

77

1.1
Location : lambda$create$0
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.givenSynthesizedObjectsFromDifferentDefinitions$whenEquals$thenFalse(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
negated conditional → KILLED

78

1.1
Location : lambda$create$0
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.whenEqualsItself$thenTrue(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForEquals::lambda$create$0 → KILLED

79

1.1
Location : lambda$create$0
Killed by : com.github.dakusui.osynth.compat.ut.SimpleObjectSynthesizerTest.whenEqualsOnAnotherXNotEqual$thenFalse(com.github.dakusui.osynth.compat.ut.SimpleObjectSynthesizerTest)
negated conditional → KILLED

80

1.1
Location : lambda$create$0
Killed by : com.github.dakusui.osynth.compat.ut.SimpleObjectSynthesizerTest.whenEqualsOnAnotherXNotEqual$thenFalse(com.github.dakusui.osynth.compat.ut.SimpleObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForEquals::lambda$create$0 → KILLED

82

1.1
Location : lambda$create$0
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.givenSynthesizedObjectsFromDifferentDefinitions$whenEquals$thenFalse(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForEquals::lambda$create$0 → KILLED

90

1.1
Location : create
Killed by : com.github.dakusui.osynth.ut.core.SynthesizedObjectTest.descriptorSameReference(com.github.dakusui.osynth.ut.core.SynthesizedObjectTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForDescriptor::create → KILLED

2.2
Location : lambda$create$0
Killed by : com.github.dakusui.osynth.ut.core.SynthesizedObjectTest.descriptorSameReference(com.github.dakusui.osynth.ut.core.SynthesizedObjectTest)
replaced return value with null for com/github/dakusui/osynth/annotations/BuiltInHandlerFactory$ForDescriptor::lambda$create$0 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3