Example usage for java.lang Void TYPE

List of usage examples for java.lang Void TYPE

Introduction

In this page you can find the example usage for java.lang Void TYPE.

Prototype

Class TYPE

To view the source code for java.lang Void TYPE.

Click Source Link

Document

The Class object representing the pseudo-type corresponding to the keyword void .

Usage

From source file:org.atteo.moonshine.websocket.jsonmessages.HandlerDispatcher.java

private void registerSenderMethod(Method method) {
    Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length != 1) {
        throw new RuntimeException("Sender method" + " must have exactly one argument whose super class is "
                + JsonMessage.class.getSimpleName());
    }//from w w w  . j ava 2 s  .  c om
    Class<?> parameterType = parameterTypes[0];
    if (!JsonMessage.class.isAssignableFrom(parameterType)) {
        throw new RuntimeException("Sender method" + " must have exactly one argument whose super class is "
                + JsonMessage.class.getSimpleName());
    }
    encoderObjectMapper.registerSubtypes(parameterType);
    Class<?> returnType = method.getReturnType();
    if (returnType != Void.TYPE) {
        throw new RuntimeException("Sender method must have " + Void.class.getSimpleName() + " return type");
    }
}

From source file:com.haulmont.cuba.core.config.ConfigUtil.java

/**
 * Get the type of a method. If the method has a non-void return
 * type, that type is returned. Otherwise if the method has at least
 * one parameter, the type of the first parameter is returned.
 *
 * @param method The method./*from  www.  j a  va 2 s.co  m*/
 * @return The method type, or else {@link Void#TYPE}.
 */
public static Class<?> getMethodType(Method method) {
    Class<?> methodType = method.getReturnType();
    if (Void.TYPE.equals(methodType)) {
        Class<?>[] parameterTypes = method.getParameterTypes();
        if (parameterTypes.length > 0) {
            methodType = parameterTypes[0];
        }
    }
    return methodType;
}

From source file:org.springframework.statemachine.processor.StateMachineMethodInvokerHelper.java

private StateMachineMethodInvokerHelper(Object targetObject, Class<? extends Annotation> annotationType,
        Method method, Class<?> expectedType) {
    Assert.notNull(method, "method must not be null");
    this.expectedType = expectedType;
    this.requiresReply = expectedType != null;
    if (expectedType != null) {
        Assert.isTrue(method.getReturnType() != Void.class && method.getReturnType() != Void.TYPE,
                "method must have a return type");
    }/* w  w  w . j  a v  a2s .  c o m*/
    Assert.notNull(targetObject, "targetObject must not be null");
    this.targetObject = targetObject;
    this.handlerMethod = new HandlerMethod(method);
    this.handlerMethods = null;
    this.handlerMessageMethods = null;
    this.handlerMethodsList = null;
    this.prepareEvaluationContext(this.getEvaluationContext(false), method, annotationType);
    this.setDisplayString(targetObject, method);
}

From source file:springfox.documentation.spring.web.readers.operation.HandlerMethodResolver.java

private static Function<ResolvedMethod, ResolvedType> toReturnType(final TypeResolver resolver) {
    return new Function<ResolvedMethod, ResolvedType>() {
        @Override/*from w  ww  . ja v a  2s . c o m*/
        public ResolvedType apply(ResolvedMethod input) {
            return fromNullable(input.getReturnType()).or(resolver.resolve(Void.TYPE));
        }
    };
}

From source file:org.springframework.yarn.container.ContainerMethodInvokerHelper.java

private ContainerMethodInvokerHelper(Object targetObject, Class<? extends Annotation> annotationType,
        Method method, Class<?> expectedType) {
    Assert.notNull(method, "method must not be null");
    this.expectedType = expectedType;
    this.requiresReply = expectedType != null;
    if (expectedType != null) {
        Assert.isTrue(method.getReturnType() != Void.class && method.getReturnType() != Void.TYPE,
                "method must have a return type");
    }/* w  w  w. j  a v a2 s. c o m*/
    Assert.notNull(targetObject, "targetObject must not be null");
    this.targetObject = targetObject;
    this.handlerMethod = new HandlerMethod(method);
    this.handlerMethods = null;
    this.handlerMessageMethods = null;
    this.handlerMethodsList = null;
    this.prepareEvaluationContext(this.getEvaluationContext(false), method, annotationType);
    this.setDisplayString(targetObject, method);
}

From source file:springfox.documentation.spring.data.rest.EntitySchemaHandler.java

@Override
public ResolvedType getReturnType() {
    MemberResolver memberResolver = new MemberResolver(resolver);
    ResolvedTypeWithMembers members = memberResolver
            .resolve(resolver.resolve(handlerMethod.getMethod().getDeclaringClass()), null, null);
    for (ResolvedMethod resolvedMethod : members.getMemberMethods()) {
        if (resolvedMethod.getRawMember().equals(handlerMethod.getMethod())) {
            ResolvedType resourceInfo = resolver.resolve(HttpEntity.class, RootResourceInformation.class);
            if (resourceInfo.equals(resolvedMethod.getReturnType())) {
                return resolver.resolve(Alps.class);
            }//w ww  .j  a  v a  2 s  . c o  m
            return resolvedMethod.getReturnType();
        }
    }
    return resolver.resolve(Void.TYPE);
}

From source file:org.mashti.jetson.util.JsonParserUtil.java

/**
 * Reads a field value as the provided type. This method supports parametrised types.
 *
 * @param parser the parser/* w  w w. j a v  a  2  s  . co m*/
 * @param expected_type the expected type of the value
 * @return the value
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static Object readValueAs(final JsonParser parser, final Type expected_type) throws IOException {

    final Object value;
    if (expected_type.equals(Void.TYPE)) {
        expectNullValue(parser);
        value = null;
    } else {
        parser.nextToken();
        value = parser.readValueAs(toTypeReference(expected_type));
    }
    return value;
}

From source file:org.impalaframework.extension.mvc.annotation.handler.ServletHandlerMethodInvoker.java

/**
 * Supports {@link ModelAndView} resolution from:
 * <ul>//from w w w  .  j av a 2s. c o m
 * <li> null - return value is null and return type is Void, uses implicit view
 * <li> null - return value is null and return type is not Void, returns null
 * <li> {@link Model}
 * <li> {@link View}
 * <li> {@link ModelAndView}
 * </ul>
 */
public ModelAndView getModelAndView(Method handlerMethod, Class<? extends Object> handlerType,
        Object returnValue, ExtendedModelMap implicitModel, ServletWebRequest webRequest) {

    //FIXME as with ArgumentCollectors, ideally, these should have a similar return result resolving 
    //interface whose implementation instance could be cached against the method

    if (returnValue instanceof String) {
        return new ModelAndView((String) returnValue).addAllObjects(implicitModel);
    } else if (returnValue == null) {
        if (Void.TYPE.equals(handlerMethod.getReturnType())) {
            return new ModelAndView().addAllObjects(implicitModel);
        } else {
            return null;
        }
    } else if (returnValue instanceof ModelAndView) {
        ModelAndView mav = (ModelAndView) returnValue;
        mav.getModelMap().mergeAttributes(implicitModel);
        return mav;
    } else if (returnValue instanceof Model) {
        return new ModelAndView().addAllObjects(implicitModel).addAllObjects(((Model) returnValue).asMap());
    } else if (returnValue instanceof View) {
        return new ModelAndView((View) returnValue).addAllObjects(implicitModel);
    } else {
        throw new IllegalArgumentException("Invalid handler method return value: " + returnValue);
    }
}

From source file:bboss.org.apache.velocity.runtime.parser.node.ASTMethod.java

/**
 *  invokes the method.  Returns null if a problem, the
 *  actual return if the method returns something, or
 *  an empty string "" if the method returns void
 * @param o/*from www.  j a v  a  2s .co m*/
 * @param context
 * @return Result or null.
 * @throws MethodInvocationException
 */
public Object execute(Object o, InternalContextAdapter context) throws MethodInvocationException {
    /*
     *  new strategy (strategery!) for introspection. Since we want
     *  to be thread- as well as context-safe, we *must* do it now,
     *  at execution time.  There can be no in-node caching,
     *  but if we are careful, we can do it in the context.
     */
    Object[] params = new Object[paramCount];

    /*
     * sadly, we do need recalc the values of the args, as this can
     * change from visit to visit
     */
    final Class[] paramClasses = paramCount > 0 ? new Class[paramCount] : ArrayUtils.EMPTY_CLASS_ARRAY;

    for (int j = 0; j < paramCount; j++) {
        params[j] = jjtGetChild(j + 1).value(context);
        if (params[j] != null) {
            paramClasses[j] = params[j].getClass();
        }
    }

    VelMethod method = ClassUtils.getMethod(methodName, params, paramClasses, o, context, this, strictRef);
    if (method == null)
        return null;

    try {
        /*
         *  get the returned object.  It may be null, and that is
         *  valid for something declared with a void return type.
         *  Since the caller is expecting something to be returned,
         *  as long as things are peachy, we can return an empty
         *  String so ASTReference() correctly figures out that
         *  all is well.
         */

        Object obj = method.invoke(o, params);

        if (obj == null) {
            if (method.getReturnType() == Void.TYPE) {
                return "";
            }
        }

        return obj;
    } catch (InvocationTargetException ite) {
        return handleInvocationException(o, context, ite.getTargetException());
    }

    /** Can also be thrown by method invocation **/
    catch (IllegalArgumentException t) {
        return handleInvocationException(o, context, t);
    }

    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "ASTMethod.execute() : exception invoking method '" + methodName + "' in " + o.getClass();
        log.error(msg, e);
        throw new VelocityException(msg, e);
    }
}

From source file:de.ufinke.cubaja.sql.ObjectFactoryGenerator.java

private void createSetterMap(Class<?> clazz) {

    setterMap = new HashMap<String, SetterEntry>();

    for (Method method : clazz.getMethods()) {

        if (method.getReturnType() == Void.TYPE) {

            String methodName = method.getName();
            SearchEntry searchEntry = searchMap.get(methodName);

            if (searchEntry != null && method.getReturnType() == Void.TYPE) {

                int position = searchEntry.position;
                Class<?>[] parameterTypes = method.getParameterTypes();

                if (parameterTypes.length == 1) {

                    TypeCombination combination = new TypeCombination(searchEntry.sqlType, parameterTypes[0]);
                    ObjectFactoryType type = ObjectFactoryType.getType(combination);

                    if (type != null) {

                        SetterEntry entry = setterMap.get(methodName);

                        if (entry == null || type.getPriority() < entry.type.getPriority()) {
                            setterMap.put(methodName, new SetterEntry(methodName, type, position));
                            searchEntry.setterFound = true;
                        }//from w w w.j a v a 2s  .c  om
                    }
                }
            }
        }
    }
}