net.bytebuddy.implementation.bind.annotation.FieldValue Java Examples

The following examples show how to use net.bytebuddy.implementation.bind.annotation.FieldValue. 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: GenericImmutableProxyForwarder.java    From reflection-util with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object forward(@Origin Method method,
							 @FieldValue(ImmutableProxy.DELEGATE_FIELD_NAME) Object delegate,
							 @AllArguments Object[] args) throws InvocationTargetException, IllegalAccessException {
	Object value = method.invoke(delegate, args);
	if (ImmutableProxy.isImmutable(value)) {
		return value;
	}
	if (!shouldProxyReturnValue(method)) {
		return value;
	}
	if (value instanceof Collection) {
		return createImmutableCollection(value, method);
	} else if (value instanceof Map) {
		return createImmutableMap(value, method);
	} else {
		return ImmutableProxy.create(value);
	}
}
 
Example #2
Source File: ConcordionInterceptor.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object intercept(@FieldValue("executor") DecoratorExecutor executor, @FieldValue("bean") Object bean, @Origin Method method, @AllArguments Object[] args) throws Exception {
	
       final FeatureResolver resolver = FeatureResolver.newFeatureResolver(bean.getClass()).withTestMethod(method)
               .withDefaultCleanupPhase(CleanupPhase.NONE).build();

       Object result = null;
       final TestInvocationImpl invocation = new TestInvocationImpl(bean, method, resolver);
       executor.processBefore(invocation);
       try {
           result = method.invoke(bean, args);
       } catch (final Exception e) {
       	Exception cause = (Exception)e.getCause();
           invocation.setTestException(cause);
           executor.processAfter(invocation);
           throw cause;
       }
       executor.processAfter(invocation);

       return result;
   }
 
Example #3
Source File: CucumberInterceptor.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object intercept(@FieldValue("executor") DecoratorExecutor executor, @FieldValue("bean") Object bean, @Origin Method method, @AllArguments Object[] args) throws Exception {
	
       final FeatureResolver resolver = FeatureResolver.newFeatureResolver(bean.getClass()).withTestMethod(method)
               .withDefaultCleanupPhase(CleanupPhase.NONE).build();

       Object result = null;
       final TestInvocationImpl invocation = new TestInvocationImpl(bean, method, resolver);
       executor.processBefore(invocation);
       try {
           result = method.invoke(bean, args);
       } catch (final Exception e) {
       	Exception cause = (Exception)e.getCause();
           invocation.setTestException(cause);
           executor.processAfter(invocation);
           throw cause;
       }
       executor.processAfter(invocation);

       return result;
   }
 
Example #4
Source File: ProxyConfiguration.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Intercepts a method call to a proxy.
 *
 * @param instance The proxied instance.
 * @param method The invoked method.
 * @param arguments The method arguments.
 * @param stubValue The intercepted method's default value.
 * @param interceptor The proxy object's interceptor instance.
 *
 * @return The intercepted method's return value.
 *
 * @throws Throwable If the intercepted method raises an exception.
 */
@RuntimeType
public static Object intercept(
		@This final Object instance,
		@Origin final Method method,
		@AllArguments final Object[] arguments,
		@StubValue final Object stubValue,
		@FieldValue(INTERCEPTOR_FIELD_NAME) Interceptor interceptor
) throws Throwable {
	if ( interceptor == null ) {
		if ( method.getName().equals( "getHibernateLazyInitializer" ) ) {
			return instance;
		}
		else {
			return stubValue;
		}
	}
	else {
		return interceptor.intercept( instance, method, arguments );
	}
}
 
Example #5
Source File: EqualsInterceptor.java    From jpa-unit with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(@This Object thiz, @Argument(0) Object other, @FieldValue("bean") Object bean) throws IllegalAccessException, NoSuchFieldException {			
       if (thiz == other) {
           return true;
       } else if (other instanceof EnhancedProxy) {
       	return bean.equals(ReflectionUtils.getValue(other, "bean"));
       } else {
       	return bean.equals(other);
       }
}
 
Example #6
Source File: EqualsInterceptor.java    From jpa-unit with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(@This Object thiz, @Argument(0) Object other, @FieldValue("bean") Object bean) throws IllegalAccessException, NoSuchFieldException {			
       if (thiz == other) {
           return true;
       } else if (other instanceof EnhancedProxy) {
           return bean.equals(ReflectionUtils.getValue(other, "bean"));
       } else {
       	return bean.equals(other);
       }
}
 
Example #7
Source File: RMapInterceptor.java    From redisson with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
        @Origin Method method,
        @AllArguments Object[] args,
        @FieldValue("liveObjectLiveMap") RMap<?, ?> map
) throws Exception {
    return method.invoke(map, args);
}
 
Example #8
Source File: RObjectInterceptor.java    From redisson with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
        @Origin Method method,
        @AllArguments Object[] args,
        @FieldValue("liveObjectLiveMap") RMap<?, ?> map
) throws Exception {
    throw new UnsupportedOperationException("Please use RLiveObjectService instance for this type of functions");
}
 
Example #9
Source File: FieldAccessorInterceptor.java    From redisson with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
        @Origin Method method,
        @AllArguments Object[] args,
        @This Object me,
        @FieldValue("liveObjectLiveMap") RMap<?, ?> map
) throws Exception {
    if (args.length >= 1 && String.class.isAssignableFrom(args[0].getClass())) {
        String name = ((String) args[0]).substring(0, 1).toUpperCase() + ((String) args[0]).substring(1);
        if ("get".equals(method.getName()) && args.length == 1) {
            try {
                return me.getClass().getMethod("get" + name).invoke(me);
            } catch (NoSuchMethodException noSuchMethodException) {
                throw new NoSuchFieldException((String) args[0]);
            }
        } else if ("set".equals(method.getName()) && args.length == 2) {
            Method m = ClassUtils.searchForMethod(me.getClass(), "set" + name, new Class[]{args[1].getClass()});
            if (m != null) {
                return m.invoke(me, args[1]);
            } else {
                throw new NoSuchFieldException((String) args[0]);
            }
        }
    }
    throw new NoSuchMethodException(method.getName() + " has wrong signature");

}
 
Example #10
Source File: RExpirableInterceptor.java    From redisson with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
        @Origin Method method,
        @AllArguments Object[] args,
        @FieldValue("liveObjectLiveMap") RMap<?, ?> map
) throws Exception {
    Class<?>[] cls = new Class[args.length];
    for (int i = 0; i < args.length; i++) {
        cls[i] = args[i].getClass();
    }
    return ClassUtils.searchForMethod(RExpirable.class, method.getName(), cls).invoke(map, args);
}
 
Example #11
Source File: MethodDelegationFieldValueTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static Object intercept(@FieldValue Object value) {
    return value;
}
 
Example #12
Source File: ImmutableProxyForwarderInteger.java    From reflection-util with Apache License 2.0 4 votes vote down vote up
public static Integer forward(@Origin Method method,
							  @FieldValue(ImmutableProxy.DELEGATE_FIELD_NAME) Object delegate,
							  @AllArguments Object[] args) throws InvocationTargetException, IllegalAccessException {
	return (Integer) method.invoke(delegate, args);
}
 
Example #13
Source File: MethodDelegationFieldValueTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static Object intercept(@FieldValue(value = FOO, declaringType = SimpleField.class) Object value) {
    return value;
}
 
Example #14
Source File: MethodDelegationFieldValueTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static Object intercept(@RuntimeType @FieldValue(FOO) String value) {
    return value;
}
 
Example #15
Source File: MethodDelegationFieldValueTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static Object intercept(@FieldValue(FOO) String value) {
    return value;
}
 
Example #16
Source File: MethodDelegationFieldValueTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static Object intercept(@FieldValue(FOO) Object value) {
    return value;
}
 
Example #17
Source File: ImmutableProxyForwarderString.java    From reflection-util with Apache License 2.0 4 votes vote down vote up
public static String forward(@Origin Method method,
							 @FieldValue(ImmutableProxy.DELEGATE_FIELD_NAME) Object delegate,
							 @AllArguments Object[] args) throws InvocationTargetException, IllegalAccessException {
	return (String) method.invoke(delegate, args);
}
 
Example #18
Source File: MethodCaptor.java    From reflection-util with Apache License 2.0 4 votes vote down vote up
@RuntimeType
public static Object intercept(@Origin Method method, @FieldValue(FIELD_NAME) MethodCaptor methodCaptor) {
	methodCaptor.capture(method);
	return PropertyUtils.getDefaultValueObject(method.getReturnType());
}
 
Example #19
Source File: ImmutableProxyForwarderBoolean.java    From reflection-util with Apache License 2.0 4 votes vote down vote up
public static Boolean forward(@Origin Method method,
							  @FieldValue(ImmutableProxy.DELEGATE_FIELD_NAME) Object delegate,
							  @AllArguments Object[] args) throws InvocationTargetException, IllegalAccessException {
	return (Boolean) method.invoke(delegate, args);
}
 
Example #20
Source File: ImmutableProxyForwarderLong.java    From reflection-util with Apache License 2.0 4 votes vote down vote up
public static Long forward(@Origin Method method,
						   @FieldValue(ImmutableProxy.DELEGATE_FIELD_NAME) Object delegate,
						   @AllArguments Object[] args) throws InvocationTargetException, IllegalAccessException {
	return (Long) method.invoke(delegate, args);
}