For IntelliJ IDEA and
Android Studio


private void myMethod () {MethodDescriptor m =
BeanDescriptor beanDescriptor;beanDescriptor.getConstraintsForMethod(method.getName(), method2.getParameterTypes())
- Smart code suggestions by Codota
}
@Override public void onValidate(final ValidationInterceptorContext ctx) { final Object resource = ctx.getResource(); final Invocable resourceMethod = ctx.getInvocable(); final Object[] args = ctx.getArgs(); final Set<ConstraintViolation<Object>> constraintViolations = new HashSet<>(); final BeanDescriptor beanDescriptor = getConstraintsForClass(resource.getClass()); // Resource validation. if (beanDescriptor.isBeanConstrained()) { constraintViolations.addAll(validate(resource)); } if (resourceMethod != null && configuration.getBootstrapConfiguration().isExecutableValidationEnabled()) { final Method handlingMethod = resourceMethod.getHandlingMethod(); // Resource method validation - input parameters. final MethodDescriptor methodDescriptor = beanDescriptor.getConstraintsForMethod(handlingMethod.getName(), handlingMethod.getParameterTypes()); if (methodDescriptor != null && methodDescriptor.hasConstrainedParameters() && validateOnExecutionHandler.validateMethod(resource.getClass(), resourceMethod.getDefinitionMethod(), resourceMethod.getHandlingMethod())) { constraintViolations.addAll(forExecutables().validateParameters(resource, handlingMethod, args)); } } if (!constraintViolations.isEmpty()) { throw new ConstraintViolationException(constraintViolations); } }
@Override public MethodDescriptor getConstraintsForMethod(final String methodName, final Class<?>... parameterTypes) { if (methodName == null) { throw new IllegalArgumentException("Method name can't be null"); } final MethodDescriptor methodDescriptor = meta.methodConstraints.get(methodName + Arrays.toString(parameterTypes)); if (methodDescriptor != null && (methodDescriptor.hasConstrainedParameters() || methodDescriptor.hasConstrainedReturnValue())) { return methodDescriptor; } return null; }
/** * Only accepts if method isn't parameterless and have at least one constraint. */ private boolean hasConstraints(ControllerMethod controllerMethod) { Method method = controllerMethod.getMethod(); if (method.getParameterTypes().length == 0) { logger.debug("method {} has no parameters, skipping", controllerMethod); return false; } BeanDescriptor bean = bvalidator.getConstraintsForClass(controllerMethod.getController().getType()); if(bean == null) { return false; } MethodDescriptor descriptor = bean.getConstraintsForMethod(method.getName(), method.getParameterTypes()); return descriptor != null && descriptor.hasConstrainedParameters(); }
/** * Only accepts if method isn't parameterless and have at least one constraint. */ private boolean hasConstraints(ControllerMethod controllerMethod) { Method method = controllerMethod.getMethod(); if (method.getParameterTypes().length == 0) { logger.debug("method {} has no parameters, skipping", controllerMethod); return false; } BeanDescriptor bean = bvalidator.getConstraintsForClass(controllerMethod.getController().getType()); if(bean == null) { return false; } MethodDescriptor descriptor = bean.getConstraintsForMethod(method.getName(), method.getParameterTypes()); return descriptor != null && descriptor.hasConstrainedParameters(); }
@Override public void onValidate(final ValidationInterceptorContext ctx) { final Object resource = ctx.getResource(); final Invocable resourceMethod = ctx.getInvocable(); final Object[] args = ctx.getArgs(); final Set<ConstraintViolation<Object>> constraintViolations = new HashSet<>(); final BeanDescriptor beanDescriptor = getConstraintsForClass(resource.getClass()); // Resource validation. if (beanDescriptor.isBeanConstrained()) { constraintViolations.addAll(validate(resource)); } if (resourceMethod != null && configuration.getBootstrapConfiguration().isExecutableValidationEnabled()) { final Method handlingMethod = resourceMethod.getHandlingMethod(); // Resource method validation - input parameters. final MethodDescriptor methodDescriptor = beanDescriptor.getConstraintsForMethod(handlingMethod.getName(), handlingMethod.getParameterTypes()); if (methodDescriptor != null && methodDescriptor.hasConstrainedParameters() && validateOnExecutionHandler.validateMethod(resource.getClass(), resourceMethod.getDefinitionMethod(), resourceMethod.getHandlingMethod())) { constraintViolations.addAll(forExecutables().validateParameters(resource, handlingMethod, args)); } } if (!constraintViolations.isEmpty()) { throw new ConstraintViolationException(constraintViolations); } }