All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.bytebuddy.implementation.StubMethod Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.bytebuddy.implementation;

import com.fitbur.bytebuddy.description.method.MethodDescription;
import com.fitbur.bytebuddy.dynamic.scaffold.InstrumentedType;
import com.fitbur.bytebuddy.implementation.bytecode.ByteCodeAppender;
import com.fitbur.bytebuddy.implementation.bytecode.StackManipulation;
import com.fitbur.bytebuddy.implementation.bytecode.constant.DefaultValue;
import com.fitbur.bytebuddy.implementation.bytecode.member.MethodReturn;
import com.fitbur.bytebuddy.jar.asm.MethodVisitor;

/**
 * This implementation creates a method stub which does nothing but returning the default value of the return
 * type of the method. These default values are:
 * 
    *
  1. The value {@code 0} for all numeric type.
  2. *
  3. The null character for the {@code char} type.
  4. *
  5. {@code false} for the {@code boolean} type.
  6. *
  7. Nothing for {@code void} types.
  8. *
  9. A {@code null} reference for any reference types. Note that this includes primitive wrapper types.
  10. *
*/ public enum StubMethod implements Implementation, ByteCodeAppender { /** * The singleton instance. */ INSTANCE; @Override public InstrumentedType prepare(InstrumentedType instrumentedType) { return instrumentedType; } @Override public ByteCodeAppender appender(Target implementationTarget) { return this; } @Override public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { StackManipulation.Size stackSize = new StackManipulation.Compound( DefaultValue.of(instrumentedMethod.getReturnType().asErasure()), MethodReturn.returning(instrumentedMethod.getReturnType().asErasure()) ).apply(methodVisitor, implementationContext); return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize()); } @Override public String toString() { return "StubMethod." + name(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy