Example usage for java.lang.reflect Method getReturnType

List of usage examples for java.lang.reflect Method getReturnType

Introduction

In this page you can find the example usage for java.lang.reflect Method getReturnType.

Prototype

public Class<?> getReturnType() 

Source Link

Document

Returns a Class object that represents the formal return type of the method represented by this Method object.

Usage

From source file:com.netflix.hystrix.contrib.javanica.utils.FallbackMethod.java

private void validatePlainReturnType(Method commandMethod, Method fallbackMethod) {
    validatePlainReturnType(commandMethod.getReturnType(), fallbackMethod.getReturnType(), commandMethod,
            fallbackMethod);/*from   ww w  . j  av  a 2s .c  o  m*/
}

From source file:com.sun.faces.el.MethodBindingImpl.java

public Class getType(FacesContext context) {

    Object base = vb.getValue(context);
    Method method = method(base);
    Class returnType = method.getReturnType();
    if (log.isDebugEnabled()) {
        log.debug("Method return type:" + returnType.getName());
    }// www  .j  av a2  s  .  c o m
    if ("void".equals(returnType.getName())) {
        return (Void.class);
    } else {
        return (returnType);
    }

}

From source file:net.arnx.jsonic.web.extension.SpringContainer.java

@Override
public Object getComponent(String className) throws Exception {
    Object component;//from  w  ww . j  ava 2s  .c  om
    try {
        component = appContext.getBean(className);
    } catch (Exception e) {
        throw new ClassNotFoundException("class not found: " + className, e);
    }

    if (component instanceof ApplicationContextAware) {
        ((ApplicationContextAware) component).setApplicationContext(appContext);
    }

    for (Method method : component.getClass().getMethods()) {
        Class<?>[] params = method.getParameterTypes();
        if (void.class.equals(method.getReturnType()) && method.getName().startsWith("set")
                && params.length == 1) {
            Class<?> c = params[0];
            if (HttpServletRequest.class.equals(c)) {
                method.invoke(component, ExternalContext.getRequest());
            } else if (HttpServletResponse.class.equals(c)) {
                method.invoke(component, ExternalContext.getResponse());
            }
        }
    }

    return component;
}

From source file:com.nominanuda.hyperapi.HyperApiWsSkelton.java

protected AnnotatedType getAnnotatedReturnType(Method m) {
    AnnotatedType at = new AnnotatedType(m.getReturnType(), m.getAnnotations());
    return at;//from   w w w. j a  v  a  2 s . c  om
}

From source file:org.vaadin.spring.i18n.Translator.java

private void analyzeMethods(Class<?> clazz) {
    for (Method m : clazz.getDeclaredMethods()) {
        if (m.getParameterTypes().length == 0 && m.getReturnType() != Void.TYPE) {
            if (m.isAnnotationPresent(TranslatedProperty.class)) {
                translatedMethods.put(m.getAnnotation(TranslatedProperty.class), m);
            } else if (m.isAnnotationPresent(TranslatedProperties.class)) {
                for (TranslatedProperty annotation : m.getAnnotation(TranslatedProperties.class).value()) {
                    translatedMethods.put(annotation, m);
                }/*from  w  w w. j a va2  s .  c  om*/
            }
        }
    }
}

From source file:com.swtxml.util.reflector.MethodQuery.java

public MethodQuery returnType(final Class<?> type) {
    filters.add(new IFilter<Method>() {
        public boolean match(Method method) {
            return ObjectUtils.equals(type, method.getReturnType());
        }/* w  ww  . j  a v  a 2 s  .c  om*/

        @Override
        public String toString() {
            return "return type \"" + (type != null ? type.getSimpleName() : "null") + "\"";
        }
    });
    return this;
}

From source file:com.lonepulse.robozombie.response.EntityProcessor.java

/**
 * <p>Accepts the {@link InvocationContext} along with the {@link HttpResponse} and retrieves the 
 * {@link HttpEntity} form the response. This is then converted to an instance of the required request 
 * return type by consulting the @{@link Deserialize} metadata on the endpoint definition.</p>
 * /*from w ww .jav a  2 s . co  m*/
 * <p>If the desired return type is {@link HttpResponse} or {@link HttpEntity} the response or entity 
 * is simply returned without any further processing.</p>
 * 
 * <p><b>Note</b> that this processor returns {@code null} for successful responses with the status 
 * codes {@code 205} or {@code 205}.</p>
 * 
 * @param context
 *          the {@link InvocationContext} which is used to discover deserializer metadata 
 * <br><br>
 * @param response
 *          the {@link HttpResponse} whose response content is deserialized to the desired output type
 * <br><br>
 * @return the deserialized response content which conforms to the expected type
 * <br><br> 
 * @throws ResponseProcessorException
 *          if deserializer instantiation or execution failed for the response entity
 * <br><br>
 * @since 1.3.0
 */
@Override
protected Object process(InvocationContext context, HttpResponse response, Object content) {

    if (response.getEntity() == null) {

        return content;
    }

    HttpEntity entity = response.getEntity();

    Method request = context.getRequest();
    Class<?> responseType = request.getReturnType();

    try {

        if (successful(response) && !status(response, 204, 205)) { //omit successful status codes without response content 

            if (HttpResponse.class.isAssignableFrom(responseType)) {

                return response;
            }

            if (HttpEntity.class.isAssignableFrom(responseType)) {

                return response.getEntity();
            }

            boolean responseExpected = !(responseType.equals(void.class) || responseType.equals(Void.class));
            boolean handleAsync = async(context);

            if (handleAsync || responseExpected) {

                Class<?> endpoint = context.getEndpoint();
                AbstractDeserializer<?> deserializer = null;

                Deserialize metadata = (metadata = request.getAnnotation(Deserialize.class)) == null
                        ? endpoint.getAnnotation(Deserialize.class)
                        : metadata;

                if (metadata != null & !isDetached(context, Deserialize.class)) {

                    deserializer = (metadata.value() == ContentType.UNDEFINED)
                            ? Deserializers.resolve(metadata.type())
                            : Deserializers.resolve(metadata.value());
                } else if (handleAsync || CharSequence.class.isAssignableFrom(responseType)) {

                    deserializer = Deserializers.resolve(ContentType.PLAIN);
                } else {

                    throw new DeserializerUndefinedException(endpoint, request);
                }

                return deserializer.run(context, response);
            }
        }
    } catch (Exception e) {

        throw (e instanceof ResponseProcessorException) ? (ResponseProcessorException) e
                : new ResponseProcessorException(getClass(), context, e);
    } finally {

        if (!(HttpResponse.class.isAssignableFrom(responseType)
                || HttpEntity.class.isAssignableFrom(responseType))) {

            EntityUtils.consumeQuietly(entity);
        }
    }

    return content;
}

From source file:ca.quadrilateral.btester.discovery.ParentInclusiveTestableMethodDiscoverer.java

@Override
public Method getAssociatedSetter(final Class<?> clazz, final Method getter) throws NoSuchMethodException {
    final String setterName = super.getSetterEquivalent(getter);
    final Class<?> returnType = getter.getReturnType();

    return getMethod(clazz, setterName, returnType);
}

From source file:com.eviware.soapui.impl.GenericPanelBuilderTest.java

private boolean isEnum(String key) {
    try {//w ww.  j  a v  a  2 s. c o m
        Method getter = modelItem.getClass().getMethod("get" + StringUtils.capitalize(key));
        boolean isEnum = getter.getReturnType().isEnum();
        return isEnum;
    } catch (NoSuchMethodException e) {
        return false;
    }
}

From source file:com.jredrain.dao.BeanResultTransFormer.java

/**
 * Setter/*  w w  w. j a v a 2s. com*/
 *
 * @param method
 * @return
 */
boolean filter(Method method) {
    if (method.getReturnType() == Void.TYPE && method.getParameterTypes().length == 1) {
        String methodName = method.getName();
        return methodName.startsWith("set") && methodName.length() > 3;
    }
    return false;
}