use of java.lang.reflect.Parameter in project quarkus by quarkusio.
the class QuarkusRestClientBuilder method verifyInterface.
private <T> void verifyInterface(Class<T> typeDef) {
Method[] methods = typeDef.getMethods();
// multiple verbs
for (Method method : methods) {
boolean hasHttpMethod = false;
for (Annotation annotation : method.getAnnotations()) {
boolean isHttpMethod = (annotation.annotationType().getAnnotation(HttpMethod.class) != null);
if (!hasHttpMethod && isHttpMethod) {
hasHttpMethod = true;
} else if (hasHttpMethod && isHttpMethod) {
throw new RestClientDefinitionException("Ambiguous @HttpMethod definition on type " + typeDef);
}
}
}
// invalid parameter
Path classPathAnno = typeDef.getAnnotation(Path.class);
ResteasyUriBuilder template = null;
for (Method method : methods) {
Path methodPathAnno = method.getAnnotation(Path.class);
if (methodPathAnno != null) {
template = classPathAnno == null ? (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(methodPathAnno.value()) : (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(classPathAnno.value() + "/" + methodPathAnno.value());
} else if (classPathAnno != null) {
template = (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(classPathAnno.value());
} else {
template = null;
}
if (template == null) {
continue;
}
// it's not executed, so this can be anything - but a hostname needs to present
template.host("localhost");
Set<String> allVariables = new HashSet<>(template.getPathParamNamesInDeclarationOrder());
Map<String, Object> paramMap = new HashMap<>();
for (Parameter p : method.getParameters()) {
PathParam pathParam = p.getAnnotation(PathParam.class);
if (pathParam != null) {
paramMap.put(pathParam.value(), "foobar");
} else if (p.isAnnotationPresent(org.jboss.resteasy.annotations.jaxrs.PathParam.class)) {
org.jboss.resteasy.annotations.jaxrs.PathParam rePathParam = p.getAnnotation(org.jboss.resteasy.annotations.jaxrs.PathParam.class);
String name = rePathParam.value() == null || rePathParam.value().length() == 0 ? p.getName() : rePathParam.value();
paramMap.put(name, "foobar");
} else if (p.isAnnotationPresent(BeanParam.class)) {
verifyBeanPathParam(p.getType(), paramMap);
}
}
if (allVariables.size() != paramMap.size()) {
throw new RestClientDefinitionException("Parameters and variables don't match on " + typeDef + "::" + method.getName());
}
try {
template.resolveTemplates(paramMap, false).build();
} catch (IllegalArgumentException ex) {
throw new RestClientDefinitionException("Parameter names don't match variable names on " + typeDef + "::" + method.getName(), ex);
}
}
}
use of java.lang.reflect.Parameter in project today-infrastructure by TAKETODAY.
the class ResolvableTypeTests method forParameter.
@Test
void forParameter() throws Exception {
Method method = Methods.class.getMethod("charSequenceParameter", List.class);
final Parameter parameter = method.getParameters()[0];
ResolvableType type = ResolvableType.fromParameter(parameter);
assertThat(type.getType()).isEqualTo(method.getGenericParameterTypes()[0]);
}
use of java.lang.reflect.Parameter in project today-infrastructure by TAKETODAY.
the class ResolvableTypeTests method resolveTypeVariableFromMethodParameterTypeWithImplementsClass.
@Test
@SuppressWarnings("deprecation")
void resolveTypeVariableFromMethodParameterTypeWithImplementsClass() throws Exception {
Method method = Methods.class.getMethod("typedParameter", Object.class);
final Parameter[] parameters = method.getParameters();
ResolvableType type = ResolvableType.fromParameter(parameters[0], TypedMethods.class);
assertThat(type.resolve()).isEqualTo(String.class);
assertThat(type.getType().toString()).isEqualTo("T");
}
use of java.lang.reflect.Parameter in project today-infrastructure by TAKETODAY.
the class TypeDescriptorTests method getSource.
@Test
public void getSource() throws Exception {
Field field = getClass().getField("fieldScalar");
final Method testParameterPrimitive = getClass().getMethod("testParameterPrimitive", int.class);
final Parameter[] parameters = testParameterPrimitive.getParameters();
final Parameter parameter = parameters[0];
final TypeDescriptor descriptor = TypeDescriptor.forParameter(testParameterPrimitive, 0);
assertThat(new TypeDescriptor(field).getSource()).isEqualTo(field);
assertThat(descriptor.getSource()).isEqualTo(parameter);
assertThat(TypeDescriptor.valueOf(Integer.class).getSource()).isEqualTo(Integer.class);
}
use of java.lang.reflect.Parameter in project today-infrastructure by TAKETODAY.
the class ParameterResolutionDelegateTests method assertAutowirableParameters.
private void assertAutowirableParameters(Executable executable) {
int startIndex = (executable instanceof Constructor) && ClassUtils.isInnerClass(executable.getDeclaringClass()) ? 1 : 0;
Parameter[] parameters = executable.getParameters();
for (int parameterIndex = startIndex; parameterIndex < parameters.length; parameterIndex++) {
Parameter parameter = parameters[parameterIndex];
assertThat(ParameterResolutionDelegate.isAutowirable(parameter, parameterIndex)).as("Parameter " + parameter + " must be autowirable").isTrue();
}
}
Aggregations