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.dbasu.robomvvm.componentmodel.ActionManager.java

private ActionDescriptor reallyGetActionDescriptor(Class objectType, final String actionName) {

    Collection<Method> methodList = Collections2.filter(Arrays.asList(objectType.getMethods()),
            new Predicate<Method>() {
                @Override/*from   w ww.  j  a v  a 2  s . co  m*/
                public boolean apply(Method m) {
                    return m.getName().equals(actionName) && m.getReturnType().equals(Void.TYPE)
                            && m.getParameterTypes().length <= 1;
                }
            });

    return new ActionDescriptor(objectType, actionName, methodList);
}

From source file:springfox.documentation.spi.service.contexts.Defaults.java

private void initIgnorableTypes() {
    ignored = newHashSet();/*from w  w  w. j  av  a 2 s  .  c  om*/
    ignored.add(ServletRequest.class);
    ignored.add(Class.class);
    ignored.add(Void.class);
    ignored.add(Void.TYPE);
    ignored.add(HttpHeaders.class);
    ignored.add(ServletResponse.class);
    ignored.add(HttpServletRequest.class);
    ignored.add(HttpServletResponse.class);
    ignored.add(HttpHeaders.class);
    ignored.add(BindingResult.class);
    ignored.add(ServletContext.class);
    ignored.add(UriComponentsBuilder.class);
    ignored.add(ApiIgnore.class);
}

From source file:org.gridgain.grid.util.json.GridJsonDeserializer.java

/**
 * Injects data from one object to another.
 *
 * @param toObj Object for injecting.//w w  w .  j  a v a 2 s .com
 * @param fromObj Object with data.
 * @throws GridException Thrown if any error occurs while data injecting.
 */
private static void objectInject(Object toObj, Object fromObj) throws GridException {
    assert toObj != null;
    assert fromObj != null;

    for (Method fromMtd : fromObj.getClass().getMethods()) {
        String mtdName = fromMtd.getName();

        if (mtdName.startsWith("get") && fromMtd.getParameterTypes().length == 0
                && fromMtd.getReturnType() != Void.TYPE && !"getClass".equals(mtdName)) {

            Object val;

            try {
                val = fromMtd.invoke(fromObj);
            } catch (IllegalAccessException e) {
                throw new GridException("Can't get value with method " + mtdName + ".", e);
            } catch (InvocationTargetException e) {
                throw new GridException("Can't get value with method " + mtdName + ".", e);
            }

            mtdName = "set" + mtdName.substring(3, mtdName.length());

            Method mtd;

            try {
                mtd = toObj.getClass().getMethod(mtdName, fromMtd.getReturnType());
            } catch (NoSuchMethodException ignore) {
                throw new GridException("Method " + mtdName + " not found.");
            }

            if (mtd.getAnnotation(GridSpiConfiguration.class) == null)
                throw new GridException("Method " + mtdName + " not found or not annotated with @"
                        + GridSpiConfiguration.class.getSimpleName() + " in object " + toObj + '.');

            try {
                mtd.invoke(toObj, val);
            } catch (IllegalAccessException e) {
                throw new GridException("Can't set value " + val + " with method " + mtdName + ".", e);
            } catch (InvocationTargetException e) {
                throw new GridException("Can't set value " + val + " with method " + mtdName + ".", e);
            }
        }
    }
}

From source file:org.apache.camel.impl.converter.BaseTypeConverterRegistry.java

@SuppressWarnings("unchecked")
public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
    if (!isRunAllowed()) {
        throw new IllegalStateException(this + " is not started");
    }/*from  w  w w. j  a v  a  2 s  .  co m*/

    Object answer;
    try {
        answer = doConvertTo(type, exchange, value);
    } catch (Exception e) {
        // if its a ExecutionException then we have rethrow it as its not due to failed conversion
        boolean execution = ObjectHelper.getException(ExecutionException.class, e) != null
                || ObjectHelper.getException(CamelExecutionException.class, e) != null;
        if (execution) {
            throw ObjectHelper.wrapCamelExecutionException(exchange, e);
        }

        // we cannot convert so return null
        if (log.isDebugEnabled()) {
            log.debug(NoTypeConversionAvailableException.createMessage(value, type) + " Caused by: "
                    + e.getMessage() + ". Will ignore this and continue.");
        }
        return null;
    }
    if (answer == Void.TYPE) {
        // Could not find suitable conversion
        return null;
    } else {
        return (T) answer;
    }
}

From source file:org.jabsorb.client.Client.java

private Object invoke(String objectTag, String methodName, Object[] args, Class returnType) throws Exception {
    final int id = getId();
    JSONObject message = new JSONObject();
    String methodTag = objectTag == null ? "" : objectTag + ".";
    methodTag += methodName;//from   w  ww  . ja v  a  2 s  .  c o m
    message.put("method", methodTag);

    {
        SerializerState state = new SerializerState();

        if (args != null) {

            JSONArray params = (JSONArray) serializer.marshall(state, /* parent */
                    null, args, "params");

            if ((state.getFixUps() != null) && (state.getFixUps().size() > 0)) {
                JSONArray fixups = new JSONArray();
                for (Iterator i = state.getFixUps().iterator(); i.hasNext();) {
                    FixUp fixup = (FixUp) i.next();
                    fixups.put(fixup.toJSONArray());
                }
                message.put("fixups", fixups);
            }
            message.put("params", params);
        } else {
            message.put("params", new JSONArray());
        }
    }
    message.put("id", id);

    JSONObject responseMessage = session.sendAndReceive(message);

    if (!responseMessage.has("result")) {
        processException(responseMessage);
    }
    Object rawResult = responseMessage.get("result");
    if (rawResult == null) {
        processException(responseMessage);
    }
    if (returnType.equals(Void.TYPE)) {
        return null;
    }

    {
        JSONArray fixups = responseMessage.optJSONArray("fixups");

        if (fixups != null) {
            for (int i = 0; i < fixups.length(); i++) {
                JSONArray assignment = fixups.getJSONArray(i);
                JSONArray fixup = assignment.getJSONArray(0);
                JSONArray original = assignment.getJSONArray(1);
                JSONRPCBridge.applyFixup(rawResult, fixup, original);
            }
        }
    }
    return serializer.unmarshall(new SerializerState(), returnType, rawResult);
}

From source file: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 ww  w  .j av  a  2s  .c om*/
 * @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();
        Logger.error(this, msg, e);
        throw new VelocityException(msg, e);
    }
}

From source file:org.apache.cactus.integration.maven.CactusScanner.java

/**
 * @param theClassName the fully qualified name of the class to check
 * @param theClasspath the classpaths needed to load the test classes
 * @return true if the class is a JUnit test case
 */// www .  j  a v  a  2  s  .c o  m
private boolean isJUnitTestCase(String theClassName, Path theClasspath) {
    Class clazz = loadClass(theClassName, theClasspath);
    if (clazz == null) {
        return false;
    }

    Class testCaseClass = null;
    try {
        testCaseClass = clazz.getClassLoader().loadClass(TestCase.class.getName());
    } catch (ClassNotFoundException e) {
        log.debug("Cannot load class", e);
        return false;
    }

    if (!testCaseClass.isAssignableFrom(clazz)) {
        log.debug("Not a JUnit test as class [" + theClassName + "] does " + "not inherit from ["
                + TestCase.class.getName() + "]");
        return false;
    }

    // the class must not be abstract
    if (Modifier.isAbstract(clazz.getModifiers())) {
        log.debug("Not a JUnit test as class [" + theClassName + "] is " + "abstract");
        return false;
    }

    // the class must have at least one test, i.e. a public method
    // starting with "test" and that takes no parameters
    boolean hasTestMethod = false;
    Method[] methods = clazz.getMethods();
    for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().startsWith("test") && (methods[i].getReturnType() == Void.TYPE)
                && (methods[i].getParameterTypes().length == 0)) {
            hasTestMethod = true;
            break;
        }
    }

    if (!hasTestMethod) {
        log.debug("Not a JUnit test as class [" + theClassName + "] has "
                + "no method that start with \"test\", returns void and has " + "no parameters");
        return false;
    }

    return true;
}

From source file:org.cloudifysource.rest.interceptors.ApiVersionValidationAndRestResponseBuilderInterceptor.java

/**
 * Filters the modelAndView object and retrieves the actual object returned by the controller.
 * This implementation assumes the model consists of just one returned object and a BindingResult.
 * If the model is empty, the supported return types are String (the view name) or void.
 *//*ww  w  .  j  a v a  2s  . c  om*/
private Object filterModel(final ModelAndView modelAndView, final Object handler) throws RestErrorException {

    Object methodReturnObject = null;
    Map<String, Object> model = modelAndView.getModel();

    if (MapUtils.isNotEmpty(model)) {
        // the model is not empty. The return value is the first value that is not a BindingResult
        for (Map.Entry<String, Object> entry : model.entrySet()) {
            Object value = entry.getValue();
            if (!(value instanceof BindingResult)) {
                methodReturnObject = value;
                break;
            }
        }
        if (methodReturnObject == null) {
            logger.warning("return object not found in model: " + model.toString());
            throw new RestErrorException("return object not found in model: " + model.toString());
        }
    } else {
        // the model is empty, this means the return type is String or void
        if (handler instanceof HandlerMethod) {
            Class<?> returnType = ((HandlerMethod) handler).getMethod().getReturnType();
            if (returnType == Void.TYPE) {
                methodReturnObject = null;
            } else if (returnType == String.class) {
                String viewName = modelAndView.getViewName();
                methodReturnObject = viewName;
            } else {
                logger.warning("return type not supported: " + returnType);
                throw new RestErrorException("return type not supported: " + returnType);
            }
        } else {
            logger.warning("handler object is not a HandlerMethod: " + handler);
            throw new RestErrorException("handler object is not a HandlerMethod: " + handler);
        }
    }

    return methodReturnObject;
}

From source file:org.kuali.kra.logging.TraceLogProxyFactory.java

/**
 * Called by cglib. This is the method that is called by the proxy. All the trace stuff goes in here. 
 *  //from  w  w w  .j a va2 s.co  m
 * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
 */
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    trace(TRACE_START, method.getDeclaringClass().getSimpleName(), method.getName());
    /*
    String enterMessage = ENTERING_METH_MSG;
            
    if (args.length < 1) {
    enterMessage = ENTERING_METH_MSG_2;
    }
            
    info(enterMessage, method.getName());
    */

    Class[] paramTypes = method.getParameterTypes();

    for (int i = 0; i < args.length; i++) {
        Class paramType = paramTypes[i];
        Object arg = args[i];

        trace(METHOD_PARAM_MSG, paramType.getSimpleName(), getArgValue(paramType, arg));
    }
    trace(LINE);

    Object retval = null;

    if (archetype != null) {
        retval = proxy.invoke(archetype, args);
    } else {
        retval = proxy.invokeSuper(obj, args);
    }

    if (method.getReturnType() != Void.TYPE) {
        trace(RETURN_METH_MSG, method.getName(), retval);
    } else {
        trace(RETURN_METH_MSG_2, method.getName());
    }
    trace(LINE);
    trace(TRACE_END, method.getName());

    return retval;
}

From source file:org.evosuite.testcase.fm.MethodDescriptor.java

/**
 * For example, do not mock methods with no return value
 *
 * @return//w ww  .  j  a  v  a 2 s.  c  om
 */
public boolean shouldBeMocked() {

    int modifiers = method.getMethod().getModifiers();

    if (method.getReturnType().equals(Void.TYPE) || method.getName().equals("equals")
            || method.getName().equals("hashCode") || Modifier.isPrivate(modifiers)) {

        return false;
    }

    if (Properties.hasTargetClassBeenLoaded()) {
        //null can happen in some unit tests

        if (!Modifier.isPublic(modifiers)) {
            assert !Modifier.isPrivate(modifiers); //previous checks

            String sutName = Properties.TARGET_CLASS;

            int lastIndexMethod = className.lastIndexOf('.');
            int lastIndexSUT = sutName.lastIndexOf('.');

            boolean samePackage;
            if (lastIndexMethod != lastIndexSUT) {
                samePackage = false;
            } else if (lastIndexMethod < 0) {
                samePackage = true; //default package
            } else {
                samePackage = className.substring(0, lastIndexMethod)
                        .equals(sutName.substring(0, lastIndexSUT));
            }

            if (!samePackage) {
                return false;
            }
        }
    } else {
        logger.warn("The target class should be loaded before invoking this method");
    }

    return true;
}