com.ui4j.bytebuddy.instrumentation.StubMethod Maven / Gradle / Ivy
package com.ui4j.bytebuddy.instrumentation;
import com.ui4j.bytebuddy.instrumentation.method.MethodDescription;
import com.ui4j.bytebuddy.instrumentation.method.bytecode.ByteCodeAppender;
import com.ui4j.bytebuddy.instrumentation.method.bytecode.stack.StackManipulation;
import com.ui4j.bytebuddy.instrumentation.method.bytecode.stack.constant.DefaultValue;
import com.ui4j.bytebuddy.instrumentation.method.bytecode.stack.member.MethodReturn;
import com.ui4j.bytebuddy.instrumentation.type.InstrumentedType;
import com.ui4j.bytebuddy.jar.asm.MethodVisitor;
/**
* This instrumentation creates a method stub which does nothing but returning the default value of the return
* type of the method. These default values are:
*
* - The value {@code 0} for all numeric type.
* - The null character for the {@code char} type.
* - {@code false} for the {@code boolean} type.
* - Nothing for {@code void} types.
* - A {@code null} reference for any reference types. Note that this includes primitive wrapper types.
*
*/
public enum StubMethod implements Instrumentation, ByteCodeAppender {
/**
* The singleton instance.
*/
INSTANCE;
@Override
public InstrumentedType prepare(InstrumentedType instrumentedType) {
return instrumentedType;
}
@Override
public ByteCodeAppender appender(Target instrumentationTarget) {
return this;
}
@Override
public boolean appendsCode() {
return true;
}
@Override
public Size apply(MethodVisitor methodVisitor,
Context instrumentationContext,
MethodDescription instrumentedMethod) {
StackManipulation.Size stackSize = new StackManipulation.Compound(
DefaultValue.of(instrumentedMethod.getReturnType()),
MethodReturn.returning(instrumentedMethod.getReturnType())
).apply(methodVisitor, instrumentationContext);
return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy