Search in sources :

Example 1 with ArgumentValue

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);
}
Also used : Path(javax.validation.Path) Argument(io.micronaut.core.type.Argument) MutableArgumentValue(io.micronaut.core.type.MutableArgumentValue) ArgumentValue(io.micronaut.core.type.ArgumentValue) InjectionPoint(io.micronaut.inject.InjectionPoint) Constraint(javax.validation.Constraint) NonNull(io.micronaut.core.annotation.NonNull)

Example 2 with ArgumentValue

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;
}
Also used : MethodExecutionHandle(io.micronaut.inject.MethodExecutionHandle) MutableArgumentValue(io.micronaut.core.type.MutableArgumentValue) ArgumentValue(io.micronaut.core.type.ArgumentValue) MutableArgumentValue(io.micronaut.core.type.MutableArgumentValue)

Aggregations

ArgumentValue (io.micronaut.core.type.ArgumentValue)2 MutableArgumentValue (io.micronaut.core.type.MutableArgumentValue)2 NonNull (io.micronaut.core.annotation.NonNull)1 Argument (io.micronaut.core.type.Argument)1 InjectionPoint (io.micronaut.inject.InjectionPoint)1 MethodExecutionHandle (io.micronaut.inject.MethodExecutionHandle)1 Constraint (javax.validation.Constraint)1 Path (javax.validation.Path)1