Java Code Examples for net.bytebuddy.implementation.bytecode.ByteCodeAppender#Simple

The following examples show how to use net.bytebuddy.implementation.bytecode.ByteCodeAppender#Simple . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ByteBuddy.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ByteCodeAppender appender(Target implementationTarget) {
    StringBuilder stringBuilder = new StringBuilder();
    List<Object> methodHandles = new ArrayList<Object>(implementationTarget.getInstrumentedType().getRecordComponents().size());
    for (RecordComponentDescription.InDefinedShape recordComponent : implementationTarget.getInstrumentedType().getRecordComponents()) {
        if (stringBuilder.length() > 0) {
            stringBuilder.append(";");
        }
        stringBuilder.append(recordComponent.getActualName());
        methodHandles.add(JavaConstant.MethodHandle.ofGetter(implementationTarget.getInstrumentedType().getDeclaredFields()
                .filter(named(recordComponent.getActualName()))
                .getOnly()).asConstantPoolValue());
    }
    return new ByteCodeAppender.Simple(MethodVariableAccess.loadThis(),
            stackManipulation,
            MethodInvocation.invoke(new MethodDescription.Latent(JavaType.OBJECT_METHODS.getTypeStub(), new MethodDescription.Token("bootstrap",
                    Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
                    TypeDescription.Generic.OBJECT,
                    Arrays.asList(JavaType.METHOD_HANDLES_LOOKUP.getTypeStub().asGenericType(),
                            TypeDescription.STRING.asGenericType(),
                            JavaType.TYPE_DESCRIPTOR.getTypeStub().asGenericType(),
                            TypeDescription.CLASS.asGenericType(),
                            TypeDescription.STRING.asGenericType(),
                            TypeDescription.ArrayProjection.of(JavaType.METHOD_HANDLE.getTypeStub()).asGenericType())))).dynamic(name,
                    returnType,
                    CompoundList.of(implementationTarget.getInstrumentedType(), arguments),
                    CompoundList.of(Arrays.asList(org.objectweb.asm.Type.getType(implementationTarget.getInstrumentedType().getDescriptor()), stringBuilder.toString()), methodHandles)),
            MethodReturn.of(returnType));
}
 
Example 2
Source File: AbstractDynamicTypeBuilderTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public ByteCodeAppender appender(Target implementationTarget) {
    return new ByteCodeAppender.Simple(NullConstant.INSTANCE, MethodReturn.REFERENCE);
}
 
Example 3
Source File: AbstractDynamicTypeBuilderTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public ByteCodeAppender appender(Target implementationTarget) {
    return new ByteCodeAppender.Simple(NullConstant.INSTANCE, MethodReturn.REFERENCE);
}
 
Example 4
Source File: Implementation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a stack manipulation where the represented value is stored in the given field.
 *
 * @param fieldDescription A static field in which the value is to be stored.
 * @return A byte code appender that represents this storage.
 */
protected ByteCodeAppender storeIn(FieldDescription fieldDescription) {
    return new ByteCodeAppender.Simple(this, FieldAccess.forField(fieldDescription).write());
}
 
Example 5
Source File: Implementation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new simple instrumentation for the given stack manipulations which are summarized in a
 * byte code appender that defines any requested method by these manipulations.
 *
 * @param stackManipulation The stack manipulation to apply in their order of application.
 */
public Simple(StackManipulation... stackManipulation) {
    byteCodeAppender = new ByteCodeAppender.Simple(stackManipulation);
}