use of io.micronaut.core.type.ArgumentValue in project micronaut-core by micronaut-projects.
the class DefaultValidator method validateParameters.
@NonNull
@Override
public <T> Set<ConstraintViolation<T>> validateParameters(@NonNull T object, @NonNull ExecutableMethod method, @NonNull Collection<MutableArgumentValue<?>> argumentValues, @Nullable Class<?>... groups) {
ArgumentUtils.requireNonNull("object", object);
ArgumentUtils.requireNonNull("method", method);
ArgumentUtils.requireNonNull("parameterValues", argumentValues);
final Argument[] arguments = method.getArguments();
final int argLen = arguments.length;
if (argLen != argumentValues.size()) {
throw new IllegalArgumentException("The method parameter array must have exactly " + argLen + " elements.");
}
DefaultConstraintValidatorContext context = new DefaultConstraintValidatorContext(object, groups);
Set overallViolations = new HashSet<>(5);
final Path.Node node = context.addMethodNode(method);
try {
@SuppressWarnings("unchecked") final Class<T> rootClass = (Class<T>) object.getClass();
validateParametersInternal(rootClass, object, argumentValues.stream().map(ArgumentValue::getValue).toArray(), arguments, argLen, context, overallViolations, node);
} finally {
context.removeLast();
}
// noinspection unchecked
return Collections.unmodifiableSet(overallViolations);
}
use of io.micronaut.core.type.ArgumentValue in project micronaut-core by micronaut-projects.
the class TraceInterceptor method intercept.
@Override
public Object intercept(InvocationContext context) {
if (LOG.isTraceEnabled() && context instanceof MethodExecutionHandle) {
MethodExecutionHandle handle = (MethodExecutionHandle) context;
Collection<MutableArgumentValue<?>> values = context.getParameters().values();
LOG.trace("Invoking method {}#{}(..) with arguments {}", context.getTarget().getClass().getName(), handle.getMethodName(), values.stream().map(ArgumentValue::getValue).collect(Collectors.toList()));
}
Object result = context.proceed();
if (LOG.isTraceEnabled() && context instanceof MethodExecutionHandle) {
MethodExecutionHandle handle = (MethodExecutionHandle) context;
LOG.trace("Method {}#{}(..) returned result {}", context.getTarget().getClass().getName(), handle.getMethodName(), result);
}
return result;
}
Aggregations