AnnotationTarget.java

1
package com.ancientprogramming.fixedformat4j.format.impl;
2
3
import java.lang.invoke.MethodHandle;
4
import java.lang.invoke.MethodHandles;
5
import java.lang.reflect.AnnotatedElement;
6
import java.lang.reflect.Method;
7
8
import static java.lang.String.format;
9
10
/**
11
 * Pairs a getter {@link Method} (used for invocation and type resolution) with an
12
 * {@link AnnotatedElement} (used for supplementary annotation lookup). When the
13
 * {@code @Field} annotation is on the getter, both references point to the same object.
14
 * When it is on a Java field, they differ.
15
 *
16
 * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a>
17
 * @since 1.6.0
18
 */
19
class AnnotationTarget {
20
21
  final Method getter;
22
  final AnnotatedElement annotationSource;
23
  final MethodHandle getterHandle;
24
25
  private AnnotationTarget(Method getter, AnnotatedElement annotationSource) {
26 1 1. <init> : Removed assignment to member variable getter → KILLED
    this.getter = getter;
27 1 1. <init> : Removed assignment to member variable annotationSource → KILLED
    this.annotationSource = annotationSource;
28
    try {
29 3 1. <init> : removed call to java/lang/invoke/MethodHandles$Lookup::unreflect → KILLED
2. <init> : Removed assignment to member variable getterHandle → KILLED
3. <init> : removed call to java/lang/invoke/MethodHandles::lookup → KILLED
      this.getterHandle = MethodHandles.lookup().unreflect(getter);
30
    } catch (IllegalAccessException e) {
31 5 1. <init> : removed call to java/lang/RuntimeException::<init> → NO_COVERAGE
2. <init> : Substituted 0 with 1 → NO_COVERAGE
3. <init> : removed call to java/lang/String::format → NO_COVERAGE
4. <init> : Substituted 1 with 0 → NO_COVERAGE
5. <init> : replaced call to java/lang/String::format with argument → NO_COVERAGE
      throw new RuntimeException(format("Cannot create MethodHandle for %s", getter), e);
32
    }
33
  }
34
35
  /** Annotation is on the getter — getter serves as both invoker and annotation source. */
36
  static AnnotationTarget ofMethod(Method method) {
37 2 1. ofMethod : removed call to com/ancientprogramming/fixedformat4j/format/impl/AnnotationTarget::<init> → KILLED
2. ofMethod : replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/AnnotationTarget::ofMethod → KILLED
    return new AnnotationTarget(method, method);
38
  }
39
40
  /** Annotation is on a Java field — getter is derived, field is the annotation source. */
41
  static AnnotationTarget ofField(Method getter, java.lang.reflect.Field field) {
42 2 1. ofField : replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/AnnotationTarget::ofField → KILLED
2. ofField : removed call to com/ancientprogramming/fixedformat4j/format/impl/AnnotationTarget::<init> → KILLED
    return new AnnotationTarget(getter, field);
43
  }
44
}

Mutations

26

1.1
Location : <init>
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport]/[method:export_nullCollection_throwsFixedFormatException()]
Removed assignment to member variable getter → KILLED

27

1.1
Location : <init>
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestAnnotationScanner.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestAnnotationScanner]/[method:scan_fieldsAnnotation_returnsTarget()]
Removed assignment to member variable annotationSource → KILLED

29

1.1
Location : <init>
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport]/[method:export_repeatingField_writesAllElements()]
removed call to java/lang/invoke/MethodHandles$Lookup::unreflect → KILLED

2.2
Location : <init>
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport]/[method:export_repeatingField_writesAllElements()]
Removed assignment to member variable getterHandle → KILLED

3.3
Location : <init>
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport]/[method:export_nullCollection_throwsFixedFormatException()]
removed call to java/lang/invoke/MethodHandles::lookup → KILLED

31

1.1
Location : <init>
Killed by : none
removed call to java/lang/RuntimeException::<init> → NO_COVERAGE

2.2
Location : <init>
Killed by : none
Substituted 0 with 1 → NO_COVERAGE

3.3
Location : <init>
Killed by : none
removed call to java/lang/String::format → NO_COVERAGE

4.4
Location : <init>
Killed by : none
Substituted 1 with 0 → NO_COVERAGE

5.5
Location : <init>
Killed by : none
replaced call to java/lang/String::format with argument → NO_COVERAGE

37

1.1
Location : ofMethod
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport]/[method:export_nullCollection_throwsFixedFormatException()]
removed call to com/ancientprogramming/fixedformat4j/format/impl/AnnotationTarget::<init> → KILLED

2.2
Location : ofMethod
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestRepeatingFieldSupport]/[method:export_nullCollection_throwsFixedFormatException()]
replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/AnnotationTarget::ofMethod → KILLED

42

1.1
Location : ofField
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestAnnotationScanner.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestAnnotationScanner]/[method:scan_superclassFields_included()]
replaced return value with null for com/ancientprogramming/fixedformat4j/format/impl/AnnotationTarget::ofField → KILLED

2.2
Location : ofField
Killed by : com.ancientprogramming.fixedformat4j.format.impl.TestAnnotationScanner.[engine:junit-jupiter]/[class:com.ancientprogramming.fixedformat4j.format.impl.TestAnnotationScanner]/[method:scan_superclassFields_included()]
removed call to com/ancientprogramming/fixedformat4j/format/impl/AnnotationTarget::<init> → KILLED

Active mutators

Tests examined


Report generated by PIT 1.23.1 support