Repository: micronaut-projects/micronaut-core
File: core-processor/src/main/java/io/micronaut/inject/writer/DispatchWriter.java (Java)

Code before:

        @Override
        public boolean supportsDispatchOne() {
            return true;
        }

        @Override
        public boolean supportsDispatchMulti() {
            return false;
        }

        @Override
        public MethodElement getMethodElement() {
            return null;
        }

        @Override
        public TypedElement getDeclaringType() {
            return null;
        }

        @Override
        public StatementDef dispatchOne(int caseValue, ExpressionDef caseExpression, ExpressionDef target, ExpressionDef value) {
            final TypeDef propertyType = TypeDef.of(beanField.getType());
            final ClassTypeDef targetType = ClassTypeDef.of(beanField.getOwningType());
            if (beanField.isReflectionRequired()) {
                return TYPE_REFLECTION_UTILS.invokeStatic(METHOD_SET_FIELD_VALUE,
                    ExpressionDef.constant(targetType), // Target class
                    ExpressionDef.constant(beanField.getName()), // Field name
                    target, // Target instance
                    value // Field value
                ).after(ExpressionDef.nullValue().returning());
            } else {
                return target.cast(targetType)
                    .field(beanField)
                    .put(value.cast(propertyType))
                    .after(ExpressionDef.nullValue().returning());
            }
        }

        @NonNull
        public FieldElement getField() {
            return beanField;
        }
    }

    /**
     * Method invocation dispatch target.
     */
    @Internal
    public static final class MethodDispatchTarget extends AbstractDispatchTarget {

Review comment (refactor):
Would be nice to move this to method handles eventually. Might even work with native image, then

Code after:
            this.beanField = beanField;
        }

        @Override
        public boolean supportsDispatchOne() {
            return true;
        }

        @Override
        public boolean supportsDispatchMulti() {
            return false;
        }

        @Override
        public MethodElement getMethodElement() {
            return null;
        }

        @Override
        public TypedElement getDeclaringType() {
            return null;
        }

        @Override
        public ExpressionDef dispatchExpression(ExpressionDef bean) {
            return TYPE_REFLECTION_UTILS.invokeStatic(
                METHOD_GET_FIELD_VALUE,
                ExpressionDef.constant(ClassTypeDef.of(beanField.getOwningType())), // Target class
                ExpressionDef.constant(beanField.getName()), // Field name,
                bean // Target instance
            ).cast(TypeDef.of(beanField.getType()));
        }

        @NonNull
        public FieldElement getField() {
            return beanField;
        }
    }

    /**
     * Field set dispatch target.
     */
    @Internal
    public static final class FieldSetDispatchTarget extends AbstractDispatchTarget {
        @NonNull
        final FieldElement beanField;

        public FieldSetDispatchTarget(FieldElement beanField) {
            this.beanField = beanField;
        }