Search in sources :

Example 41 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 42 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 43 with Parameter

use of java.lang.reflect.Parameter in project core by weld.

the class ObserverMethodConfiguratorImpl method read.

@Override
public ObserverMethodConfigurator<T> read(Method method) {
    checkArgumentNotNull(method);
    Set<Parameter> eventParameters = Configurators.getAnnotatedParameters(method, Observes.class, ObservesAsync.class);
    checkEventParams(eventParameters, method);
    Parameter eventParameter = eventParameters.iterator().next();
    Observes observesAnnotation = eventParameter.getAnnotation(Observes.class);
    if (observesAnnotation != null) {
        reception(observesAnnotation.notifyObserver());
        transactionPhase(observesAnnotation.during());
    } else {
        reception(eventParameter.getAnnotation(ObservesAsync.class).notifyObserver());
    }
    Priority priority = method.getAnnotation(Priority.class);
    if (priority != null) {
        priority(priority.value());
    }
    beanClass(eventParameter.getDeclaringExecutable().getDeclaringClass());
    observedType(eventParameter.getType());
    qualifiers(Configurators.getQualifiers(eventParameter));
    return this;
}
Also used : Observes(javax.enterprise.event.Observes) Priority(javax.annotation.Priority) Parameter(java.lang.reflect.Parameter) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter)

Example 44 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)

Example 45 with Parameter

use of java.lang.reflect.Parameter in project vertx-zero by silentbalanceyh.

the class Verifier method verify.

public static void verify(final Event event) {
    final Method method = event.getAction();
    Fn.flingUp(null == method, LOGGER, EventActionNoneException.class, Verifier.class, event);
    /**
     * Specification *
     */
    verify(method, BodyParam.class);
    verify(method, StreamParam.class);
    /**
     * Field Specification *
     */
    for (final Parameter parameter : method.getParameters()) {
        verify(parameter);
    }
}
Also used : Parameter(java.lang.reflect.Parameter) Method(java.lang.reflect.Method)

Aggregations

Parameter (java.lang.reflect.Parameter)165 Method (java.lang.reflect.Method)74 ArrayList (java.util.ArrayList)31 Annotation (java.lang.annotation.Annotation)25 Type (java.lang.reflect.Type)21 List (java.util.List)20 Test (org.junit.Test)18 Constructor (java.lang.reflect.Constructor)16 Map (java.util.Map)11 Executable (java.lang.reflect.Executable)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 HashMap (java.util.HashMap)9 PathParam (javax.ws.rs.PathParam)9 FormParameter (io.swagger.models.parameters.FormParameter)7 IOException (java.io.IOException)7 Arrays (java.util.Arrays)7 SqlStatementCustomizerFactory (org.jdbi.v3.sqlobject.customizer.SqlStatementCustomizerFactory)7 SqlStatementParameterCustomizer (org.jdbi.v3.sqlobject.customizer.SqlStatementParameterCustomizer)7 RequestPart (org.springframework.web.bind.annotation.RequestPart)7 HashSet (java.util.HashSet)6