+ private static final class NonnullMethodImplementation extends AbstractMethodImplementation {
+ private static final StackManipulation NONNULL_MEMBER = invokeMethod(CodecDataObject.class,
+ "codecMemberOrEmpty", Object.class, Class.class);
+
+ private final Class<?> bindingClass;
+ private final Method getterMethod;
+
+ NonnullMethodImplementation(final String methodName, final TypeDescription retType,
+ final Class<?> bindingClass, final Method getterMethod) {
+ super(methodName, retType);
+ this.bindingClass = requireNonNull(bindingClass);
+ this.getterMethod = requireNonNull(getterMethod);
+ }
+
+ @Override
+ public ByteCodeAppender appender(final Target implementationTarget) {
+ return new ByteCodeAppender.Simple(
+ // return (FooType) codecMemberOrEmpty(getFoo(), FooType.class)
+ loadThis(),
+ loadThis(),
+ invokeMethod(getterMethod),
+ ClassConstant.of(TypeDefinition.Sort.describe(bindingClass).asErasure()),
+ NONNULL_MEMBER,
+ TypeCasting.to(retType),
+ MethodReturn.REFERENCE);
+ }
+
+ @Override
+ public InstrumentedType prepare(final InstrumentedType instrumentedType) {
+ // No-op
+ return instrumentedType;
+ }
+ }
+