| 1 | package com.ancientprogramming.fixedformat4j.format.impl; | |
| 2 | ||
| 3 | import com.ancientprogramming.fixedformat4j.annotation.Field; | |
| 4 | import com.ancientprogramming.fixedformat4j.format.FixedFormatter; | |
| 5 | import com.ancientprogramming.fixedformat4j.format.FormatContext; | |
| 6 | import com.ancientprogramming.fixedformat4j.format.FormatInstructions; | |
| 7 | ||
| 8 | import java.lang.invoke.MethodHandle; | |
| 9 | import java.lang.reflect.Method; | |
| 10 | ||
| 11 | /** | |
| 12 | * Immutable bundle of all per-field metadata computed once per class and cached for reuse across | |
| 13 | * every {@code load()} and {@code export()} call. | |
| 14 | * | |
| 15 | * <p>For repeating fields ({@code count > 1}), {@link #context} is {@code null}; | |
| 16 | * {@link #formatInstructions} and {@link #formatter} describe a single <em>element</em>, and | |
| 17 | * {@link #elementType} / {@link #elementContexts} carry the element type and one | |
| 18 | * {@link FormatContext} per element (offsets {@code offset + length * i}). The runtime delegates | |
| 19 | * to {@link RepeatingFieldSupport}. | |
| 20 | * For fields whose type is itself a {@code @Record}, {@link #formatter} is {@code null} and the | |
| 21 | * runtime recurses into {@code FixedFormatManagerImpl}. | |
| 22 | * | |
| 23 | * @author Jacob von Eyben - <a href="https://eybenconsult.com">https://eybenconsult.com</a> | |
| 24 | * @since 1.7.0 | |
| 25 | */ | |
| 26 | class FieldDescriptor { | |
| 27 | ||
| 28 | final AnnotationTarget target; | |
| 29 | final Method setter; | |
| 30 | final MethodHandle setterHandle; | |
| 31 | final Field fieldAnnotation; | |
| 32 | final Class<?> datatype; | |
| 33 | final FormatContext<?> context; | |
| 34 | final FormatInstructions formatInstructions; | |
| 35 | final FixedFormatter<?> formatter; | |
| 36 | final boolean isRepeating; | |
| 37 | final boolean isNestedRecord; | |
| 38 | /** Element type of a repeating field; {@code null} for non-repeating fields. */ | |
| 39 | final Class<?> elementType; | |
| 40 | /** Per-element contexts of a repeating field; {@code null} for non-repeating fields. */ | |
| 41 | final FormatContext<?>[] elementContexts; | |
| 42 | /** | |
| 43 | * {@code true} when this descriptor should participate in {@code load()} (i.e. its parsed value | |
| 44 | * is written to the POJO via the setter). For plain {@code @Field} annotations this is always | |
| 45 | * {@code true}. For {@code @Fields}, only the first annotation in the array is a load field; | |
| 46 | * the remainder are export-only. | |
| 47 | */ | |
| 48 | final boolean isLoadField; | |
| 49 | ||
| 50 | FieldDescriptor( | |
| 51 | AnnotationTarget target, | |
| 52 | Method setter, | |
| 53 | MethodHandle setterHandle, | |
| 54 | Field fieldAnnotation, | |
| 55 | Class<?> datatype, | |
| 56 | FormatContext<?> context, | |
| 57 | FormatInstructions formatInstructions, | |
| 58 | FixedFormatter<?> formatter, | |
| 59 | boolean isRepeating, | |
| 60 | boolean isNestedRecord, | |
| 61 | boolean isLoadField, | |
| 62 | Class<?> elementType, | |
| 63 | FormatContext<?>[] elementContexts) { | |
| 64 |
1
1. <init> : Removed assignment to member variable target → KILLED |
this.target = target; |
| 65 |
1
1. <init> : Removed assignment to member variable setter → KILLED |
this.setter = setter; |
| 66 |
1
1. <init> : Removed assignment to member variable setterHandle → KILLED |
this.setterHandle = setterHandle; |
| 67 |
1
1. <init> : Removed assignment to member variable fieldAnnotation → KILLED |
this.fieldAnnotation = fieldAnnotation; |
| 68 |
1
1. <init> : Removed assignment to member variable datatype → KILLED |
this.datatype = datatype; |
| 69 |
1
1. <init> : Removed assignment to member variable context → KILLED |
this.context = context; |
| 70 |
1
1. <init> : Removed assignment to member variable formatInstructions → KILLED |
this.formatInstructions = formatInstructions; |
| 71 |
1
1. <init> : Removed assignment to member variable formatter → KILLED |
this.formatter = formatter; |
| 72 |
1
1. <init> : Removed assignment to member variable isRepeating → KILLED |
this.isRepeating = isRepeating; |
| 73 |
1
1. <init> : Removed assignment to member variable isNestedRecord → KILLED |
this.isNestedRecord = isNestedRecord; |
| 74 |
1
1. <init> : Removed assignment to member variable isLoadField → KILLED |
this.isLoadField = isLoadField; |
| 75 |
1
1. <init> : Removed assignment to member variable elementType → KILLED |
this.elementType = elementType; |
| 76 |
1
1. <init> : Removed assignment to member variable elementContexts → KILLED |
this.elementContexts = elementContexts; |
| 77 | } | |
| 78 | } | |
Mutations | ||
| 64 |
1.1 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |
|
| 69 |
1.1 |
|
| 70 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 74 |
1.1 |
|
| 75 |
1.1 |
|
| 76 |
1.1 |