Search in sources :

Example 76 with Parameter

use of java.lang.reflect.Parameter in project completable-reactor by ru-fix.

the class LambdaReflector method signature.

static String signature(Method method) {
    StringBuilder signature = new StringBuilder();
    Parameter[] parameters = method.getParameters();
    signature.append("(");
    for (Parameter parameter : parameters) {
        signature.append(signatureMapType(parameter.getType()));
    }
    signature.append(")");
    signature.append(signatureMapType(method.getReturnType()));
    return signature.toString();
}
Also used : Parameter(java.lang.reflect.Parameter)

Example 77 with Parameter

use of java.lang.reflect.Parameter in project tutorials by eugenp.

the class SpringExtension method resolveParameter.

@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
    Parameter parameter = parameterContext.getParameter();
    Class<?> testClass = extensionContext.getTestClass().get();
    ApplicationContext applicationContext = getApplicationContext(extensionContext);
    return ParameterAutowireUtils.resolveDependency(parameter, testClass, applicationContext);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Parameter(java.lang.reflect.Parameter)

Example 78 with Parameter

use of java.lang.reflect.Parameter in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_CodeStructureTest method shouldGenerateClassContainingMethodWithThreePathParamsAndOneBodyParam.

@Test
public void shouldGenerateClassContainingMethodWithThreePathParamsAndOneBodyParam() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(defaultPostResource().withRelativeUri("/some/path/{paramA}/{paramB}/{paramC}").withPathParam("paramA").withPathParam("paramB").withPathParam("paramC")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathParamAParamBParamCResource");
    assertThat(clazz.isInterface(), is(false));
    final List<Method> methods = methodsOf(clazz);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    assertThat(method.getParameterCount(), is(4));
    final Parameter pathParam1 = method.getParameters()[0];
    assertThat(pathParam1.getType(), equalTo(String.class));
    assertThat(pathParam1.getAnnotations(), emptyArray());
    final Parameter pathParam2 = method.getParameters()[1];
    assertThat(pathParam2.getType(), equalTo(String.class));
    assertThat(pathParam2.getAnnotations(), emptyArray());
    final Parameter pathParam3 = method.getParameters()[2];
    assertThat(pathParam3.getType(), equalTo(String.class));
    assertThat(pathParam3.getAnnotations(), emptyArray());
    final Parameter bodyParam = method.getParameters()[3];
    assertThat(bodyParam.getType(), equalTo(JsonObject.class));
    assertThat(bodyParam.getAnnotations(), emptyArray());
}
Also used : Parameter(java.lang.reflect.Parameter) JsonObject(javax.json.JsonObject) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 79 with Parameter

use of java.lang.reflect.Parameter in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_MultipartCodeStructureTest method shouldGenerateInterfaceThatContainsMethodWithTwoPathParamsAndMultipartParameter.

@Test
public void shouldGenerateInterfaceThatContainsMethodWithTwoPathParamsAndMultipartParameter() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpAction().withHttpActionType(POST).withMediaTypeWithoutSchema(multipartWithFileFormParameter("photoId")).with(mapping().withName("upload").withRequestType(MULTIPART_FORM_DATA))).withRelativeUri("/some/path/{paramA}/abc/{paramB}").withPathParam("paramA").withPathParam("paramB")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> interfaceClass = compiler.compiledInterfaceOf(RESOURCE_PACKAGE);
    final List<Method> methods = methodsOf(interfaceClass);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    assertThat(method.getParameterCount(), is(3));
    final Parameter methodParam1 = method.getParameters()[0];
    assertThat(methodParam1.getType(), equalTo(String.class));
    assertThat(methodParam1.getAnnotations(), arrayWithSize(1));
    assertThat(methodParam1.getAnnotations()[0].annotationType(), equalTo(PathParam.class));
    assertThat(methodParam1.getAnnotation(PathParam.class).value(), is("paramA"));
    final Parameter methodParam2 = method.getParameters()[1];
    assertThat(methodParam2.getType(), equalTo(String.class));
    assertThat(methodParam2.getAnnotations(), arrayWithSize(1));
    assertThat(methodParam2.getAnnotations()[0].annotationType(), equalTo(PathParam.class));
    assertThat(methodParam2.getAnnotation(PathParam.class).value(), is("paramB"));
    final Parameter methodParam3 = method.getParameters()[2];
    assertThat(methodParam3.getType(), equalTo(MultipartFormDataInput.class));
    assertThat(methodParam3.getAnnotation(MultipartForm.class), not(nullValue()));
}
Also used : MultipartFormDataInput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput) MimeTypeBuilder.multipartWithFileFormParameter(uk.gov.justice.services.generators.test.utils.builder.MimeTypeBuilder.multipartWithFileFormParameter) Parameter(java.lang.reflect.Parameter) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) MultipartForm(org.jboss.resteasy.annotations.providers.multipart.MultipartForm) Method(java.lang.reflect.Method) PathParam(javax.ws.rs.PathParam) Test(org.junit.Test)

Example 80 with Parameter

use of java.lang.reflect.Parameter in project kalang by kasonyang.

the class JvmClassNode method getDeclaredMethodNodes.

@Override
public MethodNode[] getDeclaredMethodNodes() {
    if (!this.methodsInitialized) {
        this.methodsInitialized = true;
        List<Executable> methods = new LinkedList();
        methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
        methods.addAll(Arrays.asList(clazz.getDeclaredConstructors()));
        for (Executable m : methods) {
            NullableKind nullable = getNullable(m.getAnnotations());
            Type mType;
            String mName;
            int mModifier;
            if (m instanceof Method) {
                mType = getType(((Method) m).getGenericReturnType(), getGenericTypeMap(), ((Method) m).getReturnType(), nullable);
                mName = m.getName();
                mModifier = m.getModifiers();
            } else if (m instanceof Constructor) {
                mName = "<init>";
                // getType(clz);
                mType = Types.VOID_TYPE;
                // | Modifier.STATIC;
                mModifier = m.getModifiers();
            } else {
                throw Exceptions.unexceptedValue(m);
            }
            MethodNode methodNode = createMethodNode(mType, mName, mModifier);
            for (Parameter p : m.getParameters()) {
                NullableKind pnullable = getNullable(p.getAnnotations());
                methodNode.createParameter(getType(p.getParameterizedType(), getGenericTypeMap(), p.getType(), pnullable), p.getName());
            }
            for (Class e : m.getExceptionTypes()) {
                methodNode.addExceptionType(getType(e, getGenericTypeMap(), e, NullableKind.NONNULL));
            }
        }
    }
    return super.getDeclaredMethodNodes();
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) Type(kalang.core.Type) ObjectType(kalang.core.ObjectType) GenericType(kalang.core.GenericType) WildcardType(kalang.core.WildcardType) ClassType(kalang.core.ClassType) MethodNode(kalang.ast.MethodNode) NullableKind(kalang.core.NullableKind) Constructor(java.lang.reflect.Constructor) Parameter(java.lang.reflect.Parameter) Method(java.lang.reflect.Method) Executable(java.lang.reflect.Executable) LinkedList(java.util.LinkedList)

Aggregations

Parameter (java.lang.reflect.Parameter)722 Method (java.lang.reflect.Method)261 ArrayList (java.util.ArrayList)133 Annotation (java.lang.annotation.Annotation)89 List (java.util.List)84 Type (java.lang.reflect.Type)72 HashMap (java.util.HashMap)72 Map (java.util.Map)68 Constructor (java.lang.reflect.Constructor)58 Test (org.junit.jupiter.api.Test)58 Executable (java.lang.reflect.Executable)50 Arrays (java.util.Arrays)49 InvocationTargetException (java.lang.reflect.InvocationTargetException)46 Field (java.lang.reflect.Field)43 Collectors (java.util.stream.Collectors)43 ParameterizedType (java.lang.reflect.ParameterizedType)42 Test (org.junit.Test)42 Optional (java.util.Optional)39 Set (java.util.Set)36 Modifier (java.lang.reflect.Modifier)28