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 registerOnMessageMethod(Method method, Provider<?> provider) {
    Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length != 1) {
        throw new RuntimeException("Method marked with @" + OnMessage.class.getSimpleName()
                + " must have exactly one argument whose super class is " + JsonMessage.class.getSimpleName());
    }//from  ww w  . ja v a 2s.c  o  m
    Class<?> parameterType = parameterTypes[0];
    if (!JsonMessage.class.isAssignableFrom(parameterType)) {
        throw new RuntimeException("Method marked with @" + OnMessage.class.getSimpleName()
                + " must have exactly one argument whose super class is " + JsonMessage.class.getSimpleName());
    }
    decoderObjectMapper.registerSubtypes(parameterType);
    Class<?> returnType = method.getReturnType();

    if (returnType != Void.TYPE) {
        encoderObjectMapper.registerSubtypes(returnType);
    }
    onMessageMethods.add(new OnMessageMethodMetadata(parameterType, provider, method));
}

From source file:org.dbasu.robomvvm.componentmodel.PropertyManager.java

private PropertyDescriptor reallyGetPropertyDescriptor(Class<?> objectType, String name) {

    final String setName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);

    List<Method> allMethods = Arrays.asList(objectType.getMethods());

    Collection<Method> setMethodCollection = Collections2.filter(allMethods, new Predicate<Method>() {

        @Override/*  ww  w. ja  v a 2s .c  o m*/
        public boolean apply(Method m) {
            Class[] params = m.getParameterTypes();
            return (m.getReturnType().equals(Void.TYPE) && m.getName().equals(setName) && params.length == 1);
        }
    });

    String getName = "get" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
    Method getMethod = null;

    try {
        getMethod = objectType.getMethod(getName);
    } catch (NoSuchMethodException e) {
        getName = "is" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
        try {
            getMethod = objectType.getMethod(getName);
        } catch (NoSuchMethodException e1) {

        }
    }

    if (getMethod == null && setMethodCollection.size() == 0)
        return null;
    return new PropertyDescriptor(objectType, name, setMethodCollection, getMethod);
}

From source file:in.hatimi.nosh.support.CommandExecutor.java

private Method findMainMethod() {
    Method[] methods = cmdCls.getMethods();
    for (Method method : methods) {
        if (!method.getName().equals("execute")) {
            continue; //method name must be 'execute'
        }// www.j  av  a  2 s.  com
        int mod = method.getModifiers();
        if (Modifier.isAbstract(mod)) {
            continue; //method cannot be abstract.
        }
        if (Modifier.isStatic(mod)) {
            continue; //method cannot be static.
        }
        if (Modifier.isSynchronized(mod)) {
            continue; //method cannot be synthetic.
        }
        if (!Modifier.isPublic(mod)) {
            continue; //method must be public.
        }
        if (method.getReturnType() != Void.TYPE) {
            continue; //method must not return a value.
        }
        Class<?>[] paramTypes = method.getParameterTypes();
        if (paramTypes.length > 1) {
            continue; //method can take at most one parameter.
        }
        if (paramTypes.length == 1 && !paramTypes[0].equals(String[].class)) {
            continue; //if single parameter, must be String[]
        }
        return method;
    }
    return null;
}

From source file:gov.nih.nci.caarray.util.CaArrayUtils.java

/**
 * For given class, returns a ReflectionHelper instance with property accessors for the class.
 * //w  w w . java 2 s .  c  o m
 * @param clazz the class
 * @return the ReflectionHelper
 */
public static ReflectionHelper createReflectionHelper(Class<?> clazz) {
    final List<PropertyAccessor> accessors = new ArrayList<PropertyAccessor>();

    Class<?> currentClass = clazz;
    while (currentClass != null) {
        final Method[] methods = currentClass.getDeclaredMethods();
        for (final Method getter : methods) {
            if (getter.getName().startsWith("get") && getter.getParameterTypes().length == 0) {
                for (final Method setter : methods) {
                    if (setter.getName().equals('s' + getter.getName().substring(1))
                            && setter.getParameterTypes().length == 1
                            && Void.TYPE.equals(setter.getReturnType())
                            && getter.getReturnType().equals(setter.getParameterTypes()[0])) {
                        getter.setAccessible(true);
                        setter.setAccessible(true);
                        accessors.add(new PropertyAccessor(getter, setter));
                    }
                }
            }
        }

        currentClass = currentClass.getSuperclass();
    }

    return new ReflectionHelper(accessors.toArray(new PropertyAccessor[accessors.size()]));
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java

@Test
public void testResultNull() {
    ControllerUtil.sendAndReceive(mockMvc, "remoteProviderSimple", "method5", Void.TYPE, "martin");

}

From source file:org.apache.pig.scripting.groovy.GroovyScriptEngine.java

@Override
protected Map<String, List<PigStats>> main(PigContext context, String scriptFile) throws IOException {

    PigServer pigServer = new PigServer(context, false);

    ///*from www.ja  va 2  s. c  o  m*/
    // Register dependencies
    //

    String groovyJar = getJarPath(groovy.util.GroovyScriptEngine.class);

    if (null != groovyJar) {
        pigServer.registerJar(groovyJar);
    }

    //
    // Register UDFs
    //

    registerFunctions(scriptFile, null, context);

    try {

        //
        // Load the script
        //

        Class c = gse.loadScriptByName(new File(scriptFile).toURI().toString());

        //
        // Extract the main method
        //

        Method main = c.getMethod("main", String[].class);

        if (null == main || !Modifier.isStatic(main.getModifiers()) || !Modifier.isPublic(main.getModifiers())
                || !Void.TYPE.equals(main.getReturnType())) {
            throw new IOException("No method 'public static void main(String[] args)' was found.");
        }

        //
        // Invoke the main method
        //

        Object[] args = new Object[1];
        String[] argv = (String[]) ObjectSerializer
                .deserialize(context.getProperties().getProperty(PigContext.PIG_CMD_ARGS_REMAINDERS));
        args[0] = argv;

        main.invoke(null, args);

    } catch (Exception e) {
        throw new IOException(e);
    }

    return getPigStatsMap();
}

From source file:MethodHashing.java

static String getTypeString(Class cl) {
    if (cl == Byte.TYPE) {
        return "B";
    } else if (cl == Character.TYPE) {
        return "C";
    } else if (cl == Double.TYPE) {
        return "D";
    } else if (cl == Float.TYPE) {
        return "F";
    } else if (cl == Integer.TYPE) {
        return "I";
    } else if (cl == Long.TYPE) {
        return "J";
    } else if (cl == Short.TYPE) {
        return "S";
    } else if (cl == Boolean.TYPE) {
        return "Z";
    } else if (cl == Void.TYPE) {
        return "V";
    } else if (cl.isArray()) {
        return "[" + getTypeString(cl.getComponentType());
    } else {//ww  w.  ja  va  2s  . c  o  m
        return "L" + cl.getName().replace('.', '/') + ";";
    }
}

From source file:org.nuxeo.ecm.automation.core.impl.InvokableMethod.java

/**
 * Return 0 for no match./*from   w w w.j  a  va2 s .co m*/
 */
public int inputMatch(Class<?> in) {
    if (consume == in) {
        return priority > 0 ? priority : EXACT_MATCH_PRIORITY;
    }
    if (consume.isAssignableFrom(in)) {
        return priority > 0 ? priority : ISTANCE_OF_PRIORITY;
    }
    if (op.getService().isTypeAdaptable(in, consume)) {
        return priority > 0 ? priority : ADAPTABLE_PRIORITY;
    }
    if (consume == Void.TYPE) {
        return priority > 0 ? priority : VOID_PRIORITY;
    }
    return 0;
}

From source file:com.vilt.minium.impl.BaseWebElementsImpl.java

public Object invoke(Method method, Object... args) {
    if (method.isVarArgs()) {
        args = expandVarArgs(args);/* w w w .j av  a2  s.c  o m*/
    }
    String expression = computeExpression(this, isAsyncMethod(method), method.getName(), args);

    if (method.getReturnType() != Object.class && method.getReturnType().isAssignableFrom(this.getClass())) {
        T webElements = WebElementsFactoryHelper.createExpressionWebElements(factory, myself, expression);
        return webElements;
    } else {
        Object result = null;

        boolean async = isAsyncMethod(method);

        Iterable<WebElementsDriver<T>> webDrivers = candidateWebDrivers();

        if (method.getReturnType() == Void.TYPE) {
            for (WebElementsDriver<T> wd : webDrivers) {
                factory.getInvoker().invokeExpression(wd, async, expression);
            }
        } else {
            if (Iterables.size(webDrivers) == 0) {
                throw new WebElementsException("The expression has no frame or window to be evaluated to");
            } else if (Iterables.size(webDrivers) == 1) {
                WebElementsDriver<T> wd = Iterables.get(webDrivers, 0);
                result = factory.getInvoker().invokeExpression(wd, async, expression);
            } else {
                String sizeExpression = computeExpression(this, false, "size");
                WebElementsDriver<T> webDriverWithResults = null;

                for (WebElementsDriver<T> wd : webDrivers) {
                    long size = (Long) factory.getInvoker().invokeExpression(wd, async, sizeExpression);
                    if (size > 0) {
                        if (webDriverWithResults == null) {
                            webDriverWithResults = wd;
                        } else {
                            throw new WebElementsException(
                                    "Several frames or windows match the same expression, so value cannot be computed");
                        }
                    }
                }

                if (webDriverWithResults != null) {
                    result = factory.getInvoker().invokeExpression(webDriverWithResults, async, expression);
                }
            }
        }

        if (logger.isDebugEnabled()) {
            String val;
            if (method.getReturnType() == Void.TYPE) {
                val = "void";
            } else {
                val = StringUtils.abbreviate(argToStringFunction.apply(result), 40);
                if (val.startsWith("'") && !val.endsWith("'"))
                    val += "(...)'";
            }
            logger.debug("[Value: {}] {}", argToStringFunction.apply(result), expression);
        }

        // let's handle numbers when return type is int
        if (method.getReturnType() == Integer.TYPE) {
            return result == null ? 0 : ((Number) result).intValue();
        } else {
            return result;
        }
    }
}

From source file:org.batoo.jpa.core.impl.criteria.QueryImpl.java

/**
 * @param q/*w  w  w . j a va2  s .  c  o m*/
 *            the criteria query
 * @param entityManager
 *            the entity manager
 * 
 * @since 2.0.0
 */
public QueryImpl(BaseQuery<X> q, EntityManagerImpl entityManager) {
    super();

    this.em = entityManager;
    this.q = q;
    this.sql = this.q.getSql();

    for (final ParameterExpression<?> p : this.q.getParameters()) {
        this.parameters.put((ParameterExpressionImpl<?>) p, Void.TYPE);
    }

    this.pmdBroken = entityManager.getJdbcAdaptor().isPmdBroken();
}