use of org.springframework.core.annotation.MergedAnnotation in project spring-data-commons by spring-projects.
the class QuerydslPredicateArgumentResolverSupport method getPredicate.
Predicate getPredicate(MethodParameter parameter, MultiValueMap<String, String> queryParameters) {
MergedAnnotations annotations = MergedAnnotations.from(parameter.getParameter());
MergedAnnotation<QuerydslPredicate> predicateAnnotation = annotations.get(QuerydslPredicate.class);
TypeInformation<?> domainType = extractTypeInfo(parameter, predicateAnnotation).getRequiredActualType();
Optional<Class<? extends QuerydslBinderCustomizer<?>>> bindingsAnnotation = //
predicateAnnotation.getValue("bindings").map(CastUtils::cast);
QuerydslBindings bindings = //
bindingsAnnotation.map(//
it -> bindingsFactory.createBindingsFor(domainType, it)).orElseGet(() -> bindingsFactory.createBindingsFor(domainType));
return predicateBuilder.getPredicate(domainType, queryParameters, bindings);
}
use of org.springframework.core.annotation.MergedAnnotation in project spring-boot by spring-projects.
the class AnnotationsPropertySource method getProperties.
private void getProperties(Class<?> source, Map<String, Object> properties) {
MergedAnnotations.from(source, SearchStrategy.SUPERCLASS).stream().filter(MergedAnnotationPredicates.unique(MergedAnnotation::getType)).forEach((annotation) -> {
Class<Annotation> type = annotation.getType();
MergedAnnotation<?> typeMapping = MergedAnnotations.from(type).get(PropertyMapping.class, MergedAnnotation::isDirectlyPresent);
String prefix = typeMapping.getValue(MergedAnnotation.VALUE, String.class).orElse("");
SkipPropertyMapping defaultSkip = typeMapping.getValue("skip", SkipPropertyMapping.class).orElse(SkipPropertyMapping.YES);
for (Method attribute : type.getDeclaredMethods()) {
collectProperties(prefix, defaultSkip, annotation, attribute, properties);
}
});
if (TestContextAnnotationUtils.searchEnclosingClass(source)) {
getProperties(source.getEnclosingClass(), properties);
}
}
use of org.springframework.core.annotation.MergedAnnotation in project spring-integration by spring-projects.
the class MethodAnnotationPublisherMetadataSource method getExpressionForPayload.
@Override
public Expression getExpressionForPayload(Method method) {
return this.payloadExpressions.computeIfAbsent(method, method1 -> {
Expression payloadExpression = null;
MergedAnnotation<Payload> payloadMergedAnnotation = MergedAnnotations.from(method, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY).get(Payload.class);
if (payloadMergedAnnotation.isPresent()) {
String payloadExpressionString = payloadMergedAnnotation.getString("expression");
if (!StringUtils.hasText(payloadExpressionString)) {
payloadExpression = RETURN_VALUE_EXPRESSION;
} else {
payloadExpression = EXPRESSION_PARSER.parseExpression(payloadExpressionString);
}
}
Annotation[][] annotationArray = method.getParameterAnnotations();
for (int i = 0; i < annotationArray.length; i++) {
Annotation[] parameterAnnotations = annotationArray[i];
payloadMergedAnnotation = MergedAnnotations.from(parameterAnnotations).get(Payload.class);
if (payloadMergedAnnotation.isPresent()) {
Assert.state(payloadExpression == null, "@Payload can be used at most once on a @Publisher method, " + "either at method-level or on a single parameter");
Assert.state("".equals(payloadMergedAnnotation.getString("expression")), "@Payload on a parameter for a @Publisher method may not contain an 'expression'");
payloadExpression = EXPRESSION_PARSER.parseExpression("#" + ARGUMENT_MAP_VARIABLE_NAME + "[" + i + "]");
}
}
if (payloadExpression == null || RETURN_VALUE_EXPRESSION.getExpressionString().equals(payloadExpression.getExpressionString())) {
Assert.isTrue(!void.class.equals(method.getReturnType()), "When defining @Publisher on a void-returning method, an explicit payload " + "expression that does not rely upon a #return value is required.");
}
return payloadExpression;
});
}
Aggregations