MethodHandlerDecorator.java

1
package com.github.dakusui.osynth.core;
2
3
import java.lang.reflect.Method;
4
import java.util.Collections;
5
import java.util.HashSet;
6
import java.util.Objects;
7
import java.util.Set;
8
import java.util.function.BiFunction;
9
10
import static com.github.dakusui.osynth.core.SynthesizedObject.BUILT_IN_METHODS;
11
import static com.github.dakusui.osynth.core.SynthesizedObject.RESERVED_METHODS;
12
import static java.util.Collections.unmodifiableSet;
13
import static java.util.stream.Collectors.toSet;
14
15
/**
16
 * This interface is applied to a method handler right after it is figured out
17
 * by the `osynth`'s method handler looking up mechanism is finished.
18
 *
19
 * The returned method handler is used by the rest of the library thereafter.
20
 *
21
 * This mechanism is useful to construct an "AOP"-like feature such as auto-logging, etc.
22
 */
23
public interface MethodHandlerDecorator extends BiFunction<Method, MethodHandler, MethodHandler> {
24 1 1. lambda$static$0 : replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::lambda$static$0 → KILLED
  MethodHandlerDecorator IDENTITY                       = (method, methodHandler) -> methodHandler;
25
  Set<MethodSignature>   PASS_THROUGH_METHOD_SIGNATURES = unmodifiableSet(new HashSet<MethodSignature>() {
26
    {
27
      this.addAll(RESERVED_METHODS.stream().map(MethodSignature::create).collect(toSet()));
28
      this.addAll(BUILT_IN_METHODS.stream().map(MethodSignature::create).collect(toSet()));
29
    }
30
  });
31
32
  static MethodHandlerDecorator chainMethodHandlerDecorators(MethodHandlerDecorator methodHandlerDecorator, MethodHandlerDecorator methodHandlerDecorator1) {
33 2 1. chainMethodHandlerDecorators : negated conditional → SURVIVED
2. chainMethodHandlerDecorators : replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::chainMethodHandlerDecorators → KILLED
    return methodHandlerDecorator == null ?
34
        methodHandlerDecorator1 :
35
        methodHandlerDecorator.andThen(methodHandlerDecorator1);
36
  }
37
38
  default MethodHandlerDecorator compose(MethodHandlerDecorator before) {
39 2 1. compose : replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::compose → KILLED
2. lambda$compose$1 : replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::lambda$compose$1 → KILLED
    return (method, methodHandler) -> MethodHandlerDecorator.this.apply(method, before.apply(method, methodHandler));
40
  }
41
42
  default MethodHandlerDecorator andThen(MethodHandlerDecorator after) {
43 2 1. andThen : replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::andThen → KILLED
2. lambda$andThen$2 : replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::lambda$andThen$2 → KILLED
    return (method, methodHandler) -> after.apply(method, MethodHandlerDecorator.this.apply(method, methodHandler));
44
  }
45
46
  static MethodHandlerDecorator filterOutPredefinedMethods(MethodHandlerDecorator decorator) {
47
    class PredefinedMethodFilteringOutMethodHandlerDecorator implements MethodHandlerDecorator {
48
      final MethodHandlerDecorator childDecorator = decorator;
49
50
      @Override
51
      public MethodHandler apply(Method method, MethodHandler methodHandler) {
52 1 1. apply : negated conditional → KILLED
        if (isPassThroughMethod(method))
53 1 1. apply : replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::apply → KILLED
          return methodHandler;
54 1 1. apply : replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::apply → KILLED
        return decorator.apply(method, methodHandler);
55
      }
56
57
      public int hashCode() {
58 1 1. hashCode : replaced int return with 0 for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::hashCode → SURVIVED
        return this.childDecorator.hashCode();
59
      }
60
61
      public boolean equals(Object anotherObject) {
62 1 1. equals : negated conditional → KILLED
        if (this == anotherObject)
63 1 1. equals : replaced boolean return with false for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::equals → KILLED
          return true;
64 1 1. equals : negated conditional → KILLED
        if (!(anotherObject instanceof PredefinedMethodFilteringOutMethodHandlerDecorator))
65 1 1. equals : replaced boolean return with true for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::equals → KILLED
          return false;
66
        PredefinedMethodFilteringOutMethodHandlerDecorator another = (PredefinedMethodFilteringOutMethodHandlerDecorator) anotherObject;
67 2 1. equals : replaced boolean return with false for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::equals → KILLED
2. equals : replaced boolean return with true for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::equals → KILLED
        return Objects.equals(this.childDecorator, another.childDecorator);
68
      }
69
    }
70 1 1. filterOutPredefinedMethods : replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::filterOutPredefinedMethods → KILLED
    return new PredefinedMethodFilteringOutMethodHandlerDecorator();
71
  }
72
73
  static boolean isPassThroughMethod(Method method) {
74 2 1. isPassThroughMethod : replaced boolean return with false for com/github/dakusui/osynth/core/MethodHandlerDecorator::isPassThroughMethod → KILLED
2. isPassThroughMethod : replaced boolean return with true for com/github/dakusui/osynth/core/MethodHandlerDecorator::isPassThroughMethod → KILLED
    return PASS_THROUGH_METHOD_SIGNATURES.contains(MethodSignature.create(method));
75
  }
76
}

Mutations

24

1.1
Location : lambda$static$0
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.whenErrorThrowingMethodIsInvoked$thenExceptionThrown(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::lambda$static$0 → KILLED

33

1.1
Location : chainMethodHandlerDecorators
Killed by : none
negated conditional → SURVIVED

2.2
Location : chainMethodHandlerDecorators
Killed by : com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest.givenSynthesizedFromAnotherSynthesized$whenCallMethod$thenLetsSee(com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::chainMethodHandlerDecorators → KILLED

39

1.1
Location : compose
Killed by : com.github.dakusui.osynth.ut.AutoLoggingTest.modifyAutoLoggingBehaviorBy$compose$_thenModifiedBehaviorObserved(com.github.dakusui.osynth.ut.AutoLoggingTest)
replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::compose → KILLED

2.2
Location : lambda$compose$1
Killed by : com.github.dakusui.osynth.ut.AutoLoggingTest.modifyAutoLoggingBehaviorBy$compose$_thenModifiedBehaviorObserved(com.github.dakusui.osynth.ut.AutoLoggingTest)
replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::lambda$compose$1 → KILLED

43

1.1
Location : andThen
Killed by : com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest.givenSynthesizedFromAnotherSynthesized$whenCallMethod$thenLetsSee(com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::andThen → KILLED

2.2
Location : lambda$andThen$2
Killed by : com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest.givenSynthesizedFromAnotherSynthesized$whenCallMethod$thenLetsSee(com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::lambda$andThen$2 → KILLED

52

1.1
Location : apply
Killed by : com.github.dakusui.osynth.ut.core.SynthesizedObjectTest.differentHandlerDecorator(com.github.dakusui.osynth.ut.core.SynthesizedObjectTest)
negated conditional → KILLED

53

1.1
Location : apply
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/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::apply → KILLED

54

1.1
Location : apply
Killed by : com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest.whenErrorThrowingMethodIsInvoked$thenExceptionThrown(com.github.dakusui.osynth.compat.ut.ObjectSynthesizerTest)
replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::apply → KILLED

58

1.1
Location : hashCode
Killed by : none
replaced int return with 0 for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::hashCode → SURVIVED

62

1.1
Location : equals
Killed by : com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest.examineEqualsMethodForFilteringOutPredefinedMethodsIfObjectIsNotDecorator(com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest)
negated conditional → KILLED

63

1.1
Location : equals
Killed by : com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest.examineEqualsMethodForFilteringOutPredefinedMethods(com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest)
replaced boolean return with false for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::equals → KILLED

64

1.1
Location : equals
Killed by : com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest.examineEqualsMethodForFilteringOutPredefinedMethodsIfObjectIsNotDecorator(com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest)
negated conditional → KILLED

65

1.1
Location : equals
Killed by : com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest.examineEqualsMethodForFilteringOutPredefinedMethodsIfObjectIsNotDecorator(com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest)
replaced boolean return with true for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::equals → KILLED

67

1.1
Location : equals
Killed by : com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest.equalness$differentSameMethodHandlers(com.github.dakusui.osynth.compat.ut.NewObjectSynthesizerTest)
replaced boolean return with false for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::equals → KILLED

2.2
Location : equals
Killed by : com.github.dakusui.osynth.ut.core.SynthesizedObjectTest.differentHandlerDecorator(com.github.dakusui.osynth.ut.core.SynthesizedObjectTest)
replaced boolean return with true for com/github/dakusui/osynth/core/MethodHandlerDecorator$1PredefinedMethodFilteringOutMethodHandlerDecorator::equals → KILLED

70

1.1
Location : filterOutPredefinedMethods
Killed by : com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest.examineEqualsMethodForFilteringOutPredefinedMethodsIfObjectIsNotDecorator(com.github.dakusui.osynth.ut.core.MethodHandlerDecoratorTest)
replaced return value with null for com/github/dakusui/osynth/core/MethodHandlerDecorator::filterOutPredefinedMethods → KILLED

74

1.1
Location : isPassThroughMethod
Killed by : com.github.dakusui.osynth.ut.core.SynthesizedObjectTest.differentHandlerDecorator(com.github.dakusui.osynth.ut.core.SynthesizedObjectTest)
replaced boolean return with false for com/github/dakusui/osynth/core/MethodHandlerDecorator::isPassThroughMethod → KILLED

2.2
Location : isPassThroughMethod
Killed by : com.github.dakusui.osynth.ut.AutoLoggingTest.givenAutoLoggingEnabled_whenDefaultMethod$bMethod$_thenDoesntBreak(com.github.dakusui.osynth.ut.AutoLoggingTest)
replaced boolean return with true for com/github/dakusui/osynth/core/MethodHandlerDecorator::isPassThroughMethod → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3