Java Code Examples for net.bytebuddy.description.type.TypeDescription#OBJECT

The following examples show how to use net.bytebuddy.description.type.TypeDescription#OBJECT . 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: JavaConstant.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a constant {@code null} value of type {@link Object}.
 *
 * @return A dynamically resolved null constant.
 */
public static Dynamic ofNullConstant() {
    return new Dynamic(new ConstantDynamic("nullConstant",
            TypeDescription.OBJECT.getDescriptor(),
            new Handle(Opcodes.H_INVOKESTATIC,
                    CONSTANT_BOOTSTRAPS,
                    "nullConstant",
                    "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;",
                    false)), TypeDescription.OBJECT);
}
 
Example 2
Source File: FieldReaderAppender.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Size apply(
		MethodVisitor methodVisitor,
		Implementation.Context implementationContext,
		MethodDescription instrumentedMethod) {
	TypeDescription dispatcherType = persistentFieldAsDefined.getType().isPrimitive()
			? persistentFieldAsDefined.getType().asErasure()
			: TypeDescription.OBJECT;
	// if ( this.$$_hibernate_getInterceptor() != null )
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	methodVisitor.visitMethodInsn(
			Opcodes.INVOKEVIRTUAL,
			managedCtClass.getInternalName(),
			EnhancerConstants.INTERCEPTOR_GETTER_NAME,
			Type.getMethodDescriptor( Type.getType( PersistentAttributeInterceptor.class ) ),
			false
	);
	Label skip = new Label();
	methodVisitor.visitJumpInsn( Opcodes.IFNULL, skip );
	// this (for field write)
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	// this.$$_hibernate_getInterceptor();
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	methodVisitor.visitMethodInsn(
			Opcodes.INVOKEVIRTUAL,
			managedCtClass.getInternalName(),
			EnhancerConstants.INTERCEPTOR_GETTER_NAME,
			Type.getMethodDescriptor( Type.getType( PersistentAttributeInterceptor.class ) ),
			false
	);
	// .readXXX( self, fieldName, field );
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	methodVisitor.visitLdcInsn( persistentFieldAsDefined.getName() );
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	fieldRead( methodVisitor );
	methodVisitor.visitMethodInsn(
			Opcodes.INVOKEINTERFACE,
			Type.getInternalName( PersistentAttributeInterceptor.class ),
			"read" + EnhancerImpl.capitalize( dispatcherType.getSimpleName() ),
			Type.getMethodDescriptor(
					Type.getType( dispatcherType.getDescriptor() ),
					Type.getType( Object.class ),
					Type.getType( String.class ),
					Type.getType( dispatcherType.getDescriptor() )
			),
			true
	);
	// field = (cast) XXX
	if ( !dispatcherType.isPrimitive() ) {
		methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, persistentFieldAsDefined.getType().asErasure().getInternalName() );
	}
	fieldWrite( methodVisitor );
	// end if
	methodVisitor.visitLabel( skip );
	if ( implementationContext.getClassFileVersion().isAtLeast( ClassFileVersion.JAVA_V6 ) ) {
		methodVisitor.visitFrame( Opcodes.F_SAME, 0, null, 0, null );
	}
	// return field
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	fieldRead( methodVisitor );
	if ( !persistentField.getType().isPrimitive()
			&& !persistentField.getType().asErasure().getInternalName().equals( persistentFieldAsDefined.getType().asErasure().getInternalName() ) ) {
		methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, persistentField.getType().asErasure().getInternalName() );
	}
	methodVisitor.visitInsn( Type.getType( persistentFieldAsDefined.getType().asErasure().getDescriptor() ).getOpcode( Opcodes.IRETURN ) );
	return new Size( 4 + persistentFieldAsDefined.getType().getStackSize().getSize(), instrumentedMethod.getStackSize() );
}
 
Example 3
Source File: FieldWriterAppender.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Size apply(
		MethodVisitor methodVisitor,
		Implementation.Context implementationContext,
		MethodDescription instrumentedMethod) {
	TypeDescription dispatcherType = persistentFieldAsDefined.getType().isPrimitive()
			? persistentFieldAsDefined.getType().asErasure()
			: TypeDescription.OBJECT;
	// if ( this.$$_hibernate_getInterceptor() != null )
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	methodVisitor.visitMethodInsn(
			Opcodes.INVOKEVIRTUAL,
			managedCtClass.getInternalName(),
			EnhancerConstants.INTERCEPTOR_GETTER_NAME,
			Type.getMethodDescriptor( Type.getType( PersistentAttributeInterceptor.class ) ),
			false
	);
	Label noInterceptor = new Label();
	methodVisitor.visitJumpInsn( Opcodes.IFNULL, noInterceptor );
	// this (for field write)
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	// this.$$_hibernate_getInterceptor();
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	methodVisitor.visitMethodInsn(
			Opcodes.INVOKEVIRTUAL,
			managedCtClass.getInternalName(),
			EnhancerConstants.INTERCEPTOR_GETTER_NAME,
			Type.getMethodDescriptor( Type.getType( PersistentAttributeInterceptor.class ) ),
			false
	);
	// .writeXXX( self, fieldName, field, arg1 );
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	methodVisitor.visitLdcInsn( persistentFieldAsDefined.getName() );
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	fieldRead( methodVisitor );
	methodVisitor.visitVarInsn( Type.getType( dispatcherType.getDescriptor() ).getOpcode( Opcodes.ILOAD ), 1 );
	methodVisitor.visitMethodInsn(
			Opcodes.INVOKEINTERFACE,
			Type.getInternalName( PersistentAttributeInterceptor.class ),
			"write" + EnhancerImpl.capitalize( dispatcherType.getSimpleName() ),
			Type.getMethodDescriptor(
					Type.getType( dispatcherType.getDescriptor() ),
					Type.getType( Object.class ),
					Type.getType( String.class ),
					Type.getType( dispatcherType.getDescriptor() ),
					Type.getType( dispatcherType.getDescriptor() )
			),
			true
	);
	// arg1 = (cast) XXX
	if ( !dispatcherType.isPrimitive() ) {
		methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, persistentFieldAsDefined.getType().asErasure().getInternalName() );
	}
	fieldWrite( methodVisitor );
	// return
	methodVisitor.visitInsn( Opcodes.RETURN );
	// else
	methodVisitor.visitLabel( noInterceptor );
	if ( implementationContext.getClassFileVersion().isAtLeast( ClassFileVersion.JAVA_V6 ) ) {
		methodVisitor.visitFrame( Opcodes.F_SAME, 0, null, 0, null );
	}
	// this (for field write)
	methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 );
	// arg1 = (cast) XXX
	methodVisitor.visitVarInsn( Type.getType( dispatcherType.getDescriptor() ).getOpcode( Opcodes.ILOAD ), 1 );
	if ( !dispatcherType.isPrimitive() ) {
		methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, persistentFieldAsDefined.getType().asErasure().getInternalName() );
	}
	fieldWrite( methodVisitor );
	// return
	methodVisitor.visitInsn( Opcodes.RETURN );
	return new Size( 4 + 2 * persistentFieldAsDefined.getType().getStackSize().getSize(), instrumentedMethod.getStackSize() );
}