Java Code Examples for net.bytebuddy.description.method.MethodDescription#getReturnType()

The following examples show how to use net.bytebuddy.description.method.MethodDescription#getReturnType() . 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: FixedValue.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) {
    if (instrumentedMethod.getParameters().size() <= index) {
        throw new IllegalStateException(instrumentedMethod + " does not define a parameter with index " + index);
    }
    ParameterDescription parameterDescription = instrumentedMethod.getParameters().get(index);
    StackManipulation stackManipulation = new StackManipulation.Compound(
            MethodVariableAccess.load(parameterDescription),
            assigner.assign(parameterDescription.getType(), instrumentedMethod.getReturnType(), typing),
            MethodReturn.of(instrumentedMethod.getReturnType())
    );
    if (!stackManipulation.isValid()) {
        throw new IllegalStateException("Cannot assign " + instrumentedMethod.getReturnType() + " to " + parameterDescription);
    }
    return new Size(stackManipulation.apply(methodVisitor, implementationContext).getMaximalSize(), instrumentedMethod.getStackSize());
}
 
Example 2
Source File: BiDirectionalAssociationHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static TypeDescription.Generic target(FieldDescription persistentField) {
	AnnotationDescription.Loadable<Access> access = persistentField.getDeclaringType().asErasure().getDeclaredAnnotations().ofType( Access.class );
	if ( access != null && access.loadSilent().value() == AccessType.FIELD ) {
		return persistentField.getType();
	}
	else {
		MethodDescription getter = EnhancerImpl.getterOf( persistentField );
		if ( getter == null ) {
			return persistentField.getType();
		}
		else {
			return getter.getReturnType();
		}
	}
}
 
Example 3
Source File: TemplateModelProxyHandler.java    From flow with Apache License 2.0 5 votes vote down vote up
private static boolean isAccessor(MethodDescription method) {
    if (method.getDeclaringType().represents(Object.class)) {
        return false;
    }
    String methodName = method.getName();
    Generic returnType = method.getReturnType();
    ParameterList<?> args = method.getParameters();

    boolean isSetter = Generic.VOID.equals(returnType) && args.size() == 1
            && ReflectTools.isSetterName(methodName);
    boolean isGetter = !Generic.VOID.equals(returnType) && args.isEmpty()
            && ReflectTools.isGetterName(methodName,
                    returnType.represents(boolean.class));
    return isSetter || isGetter;
}
 
Example 4
Source File: MethodCall.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public StackManipulation toStackManipulation(MethodDescription invokedMethod, MethodDescription instrumentedMethod, Assigner assigner, Assigner.Typing typing) {
    StackManipulation stackManipulation = assigner.assign(invokedMethod.isConstructor()
            ? invokedMethod.getDeclaringType().asGenericType()
            : invokedMethod.getReturnType(), instrumentedMethod.getReturnType(), typing);
    if (!stackManipulation.isValid()) {
        throw new IllegalStateException("Cannot return " + invokedMethod.getReturnType() + " from " + instrumentedMethod);
    }
    return new StackManipulation.Compound(stackManipulation, MethodReturn.of(instrumentedMethod.getReturnType()));
}