Java Code Examples for org.springframework.core.MethodParameter#hasMethodAnnotation()

The following examples show how to use org.springframework.core.MethodParameter#hasMethodAnnotation() . 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: AbstractWxMessageReturnValueHandler.java    From FastBootWeixin with Apache License 2.0 6 votes vote down vote up
/**
 * 有WxAsyncMessage注解且
 * 返回值是WxMessage的子类
 * 或者是CharSequence的子类,且有注解WxButton或者WXMessageMapping
 * 这里其实应该判断反向的,即不需要Async发送的。只有几个用户类型的消息不需要异步发送
 *
 * @param returnType
 * @return result
 */
@Deprecated
public boolean supportsReturnTypeOld(MethodParameter returnType) {
    // 如果是iterable或者array,都只能作为asyncMessage消息处理
    boolean isIterableType = Iterable.class.isAssignableFrom(returnType.getParameterType());
    boolean isArrayType = returnType.getParameterType().isArray();
    // 如果是群发消息,只能作为asyncMessage消息处理
    boolean isGroupMessage = WxGroupMessage.class.isAssignableFrom(returnType.getParameterType());
    // 如果是模板消息,只能作为asyncMessage消息处理
    boolean isTemplateMessage = WxTemplateMessage.class.isAssignableFrom(returnType.getParameterType());
    // 如果是模板消息,只能作为asyncMessage消息处理
    boolean isMiniProgramMessage = WxUserMessage.MiniProgram.class.isAssignableFrom(returnType.getParameterType());
    // 理论上WxAsyncMessage已经被上层处理过了,这里保险起见再处理一次
    boolean needAsyncSend = isIterableType || isArrayType || isGroupMessage || isTemplateMessage || isMiniProgramMessage;
    Class realType = getGenericType(returnType);
    boolean isWxMessage = WxMessage.class.isAssignableFrom(realType);
    boolean isWxStringMessage = CharSequence.class.isAssignableFrom(realType) &&
            returnType.hasMethodAnnotation(WxMapping.class);
    return needAsyncSend && (isWxMessage || isWxStringMessage);
}
 
Example 2
Source File: WxStringResponseBodyAdvice.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supports(MethodParameter returnType,
                        Class<? extends HttpMessageConverter<?>> converterType) {
    return StringHttpMessageConverter.class.isAssignableFrom(converterType) &&
            CharSequence.class.isAssignableFrom(returnType.getParameterType()) &&
            returnType.hasMethodAnnotation(WxMapping.class);
}
 
Example 3
Source File: WxSyncMessageReturnValueHandler.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean supportsReturnTypeInternal(MethodParameter returnType) {
    // 是否显式声明为async了,如果是不从这里发送
    boolean isAsyncMessage = returnType.hasMethodAnnotation(WxAsyncMessage.class);
    // 是否是WxMapping,如果声明为wxMapping,则不通过这里而是直接异步发送
    // 理论上可控制顺序来控制这里的判断减少,但是稳妥起见多判断一次
    boolean isWxMapping = returnType.hasMethodAnnotation(WxMapping.class);
    Class realType = getGenericType(returnType);
    // 对于非WxMapping的handler,判断返回类型是否是WxMessage,如果是则同步发送消息
    boolean isWxMessage = WxMessage.class.isAssignableFrom(realType);
    return !isAsyncMessage && !isWxMapping && isWxMessage;
}
 
Example 4
Source File: ResponseBodyResultHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean supports(HandlerResult result) {
	MethodParameter returnType = result.getReturnTypeSource();
	Class<?> containingClass = returnType.getContainingClass();
	return (AnnotatedElementUtils.hasAnnotation(containingClass, ResponseBody.class) ||
			returnType.hasMethodAnnotation(ResponseBody.class));
}
 
Example 5
Source File: SendToMethodReturnValueHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.hasMethodAnnotation(SendTo.class) ||
			AnnotatedElementUtils.hasAnnotation(returnType.getDeclaringClass(), SendTo.class) ||
			returnType.hasMethodAnnotation(SendToUser.class) ||
			AnnotatedElementUtils.hasAnnotation(returnType.getDeclaringClass(), SendToUser.class) ||
			!this.annotationRequired);
}
 
Example 6
Source File: WxMessageReturnValueHandler.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
    if (returnType.hasMethodAnnotation(WxMapping.class)) {
        return false;
    }
    ResolvableType resolvableType = ResolvableType.forMethodParameter(returnType);
    ResolvableType arrayType = ResolvableType.forArrayComponent(ResolvableType.forClass(WxMessage.class));
    ResolvableType iterableType = ResolvableType.forClassWithGenerics(Iterable.class, WxMessage.class);
    return arrayType.isAssignableFrom(resolvableType) || iterableType.isAssignableFrom(resolvableType);
}
 
Example 7
Source File: WxAsyncMessageReturnValueHandler.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean supportsReturnTypeInternal(MethodParameter returnType) {
    // 是否显式声明为async了,如果是则直接异步发送
    boolean isAsyncMessage = returnType.hasMethodAnnotation(WxAsyncMessage.class);
    // 是否是WxMapping,如果声明为wxMapping,则直接异步发送(因为这种类型没有必要同步,报错了还会返回到客户端提示异常,不友好)
    boolean isWxMapping = returnType.hasMethodAnnotation(WxMapping.class);
    return isAsyncMessage || isWxMapping;
}
 
Example 8
Source File: ResponseBodyResultHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean supports(HandlerResult result) {
	MethodParameter returnType = result.getReturnTypeSource();
	Class<?> containingClass = returnType.getContainingClass();
	return (AnnotatedElementUtils.hasAnnotation(containingClass, ResponseBody.class) ||
			returnType.hasMethodAnnotation(ResponseBody.class));
}
 
Example 9
Source File: RequestResponseBodyMethodProcessor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (AnnotatedElementUtils.hasAnnotation(returnType.getContainingClass(), ResponseBody.class) ||
			returnType.hasMethodAnnotation(ResponseBody.class));
}
 
Example 10
Source File: ParamEncryptResponseBodyAdvice.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supports(MethodParameter returnType, Class converterType) {
	return returnType.hasMethodAnnotation(ResponseBody.class);
}
 
Example 11
Source File: ExcelDrivenReadHandler.java    From tools with MIT License 4 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter methodParameter) {
    return methodParameter.hasMethodAnnotation(ExcelRead.class);
}
 
Example 12
Source File: SubscriptionMethodReturnValueHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.hasMethodAnnotation(SubscribeMapping.class) &&
			!returnType.hasMethodAnnotation(SendTo.class) &&
			!returnType.hasMethodAnnotation(SendToUser.class));
}
 
Example 13
Source File: WxMappingReturnValueHandler.java    From FastBootWeixin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
    return returnType.hasMethodAnnotation(WxMapping.class);
}
 
Example 14
Source File: JsonViewResponseBodyAdvice.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
	return super.supports(returnType, converterType) && returnType.hasMethodAnnotation(JsonView.class);
}
 
Example 15
Source File: RequestResponseBodyMethodProcessor.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (AnnotatedElementUtils.hasAnnotation(returnType.getContainingClass(), ResponseBody.class) ||
			returnType.hasMethodAnnotation(ResponseBody.class));
}
 
Example 16
Source File: ModelAttributeMethodProcessor.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return {@code true} if there is a method-level {@code @ModelAttribute}
 * or, in default resolution mode, for any return value type that is not
 * a simple type.
 */
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.hasMethodAnnotation(ModelAttribute.class) ||
			(this.annotationNotRequired && !BeanUtils.isSimpleProperty(returnType.getParameterType())));
}
 
Example 17
Source File: JsonViewResponseBodyAdvice.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
	return super.supports(returnType, converterType) && returnType.hasMethodAnnotation(JsonView.class);
}
 
Example 18
Source File: RequestResponseBodyMethodProcessor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (AnnotatedElementUtils.hasAnnotation(returnType.getContainingClass(), ResponseBody.class) ||
			returnType.hasMethodAnnotation(ResponseBody.class));
}
 
Example 19
Source File: SubscriptionMethodReturnValueHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.hasMethodAnnotation(SubscribeMapping.class) &&
			!returnType.hasMethodAnnotation(SendTo.class) &&
			!returnType.hasMethodAnnotation(SendToUser.class));
}
 
Example 20
Source File: JSONPResponseBodyAdvice.java    From uavstack with Apache License 2.0 3 votes vote down vote up
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {


        return FastJsonHttpMessageConverter.class.isAssignableFrom(converterType)
                &&
                (returnType.getContainingClass().isAnnotationPresent(ResponseJSONP.class) || returnType.hasMethodAnnotation(ResponseJSONP.class));
    }