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:play.modules.swagger.PlayReader.java

private static boolean isVoid(Type type) {
    final Class<?> cls = Json.mapper().getTypeFactory().constructType(type).getRawClass();
    return Void.class.isAssignableFrom(cls) || Void.TYPE.isAssignableFrom(cls);
}

From source file:com.taobao.adfs.distributed.rpc.RPC.java

/** Expert: Make multiple, parallel calls to a set of servers. */
public static Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, Configuration conf)
        throws IOException {

    Invocation[] invocations = new Invocation[params.length];
    for (int i = 0; i < params.length; i++)
        invocations[i] = new Invocation(method, params[i]);
    Client client = CLIENTS.getClient(conf);
    try {/*from   w w w  . j ava  2s .c  o m*/
        Writable[] wrappedValues = client.call(invocations, addrs);

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

        Object[] values = (Object[]) Array.newInstance(method.getReturnType(), wrappedValues.length);
        for (int i = 0; i < values.length; i++)
            if (wrappedValues[i] != null)
                values[i] = ((ObjectWritable) wrappedValues[i]).get();

        return values;
    } finally {
        CLIENTS.stopClient(client);
    }
}

From source file:com.gargoylesoftware.htmlunit.CodeStyleTest.java

private void testTests(final File dir) throws Exception {
    for (final File file : dir.listFiles()) {
        if (file.isDirectory()) {
            if (!".svn".equals(file.getName())) {
                testTests(file);/*from w w  w  . j a  va  2 s  .  c o  m*/
            }
        } else {
            if (file.getName().endsWith(".java")) {
                final int index = new File("src/test/java").getAbsolutePath().length();
                String name = file.getAbsolutePath();
                name = name.substring(index + 1, name.length() - 5);
                name = name.replace(File.separatorChar, '.');
                final Class<?> clazz;
                try {
                    clazz = Class.forName(name);
                } catch (final Exception e) {
                    continue;
                }
                name = file.getName();
                if (name.endsWith("Test.java") || name.endsWith("TestCase.java")) {
                    for (final Constructor<?> ctor : clazz.getConstructors()) {
                        if (ctor.getParameterTypes().length == 0) {
                            for (final Method method : clazz.getDeclaredMethods()) {
                                if (Modifier.isPublic(method.getModifiers())
                                        && method.getAnnotation(Before.class) == null
                                        && method.getAnnotation(BeforeClass.class) == null
                                        && method.getAnnotation(After.class) == null
                                        && method.getAnnotation(AfterClass.class) == null
                                        && method.getAnnotation(Test.class) == null
                                        && method.getReturnType() == Void.TYPE
                                        && method.getParameterTypes().length == 0) {
                                    fail("Method '" + method.getName() + "' in " + name
                                            + " does not declare @Test annotation");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:org.apache.axis.description.JavaServiceDesc.java

/**
 * Is this method from ServiceLifeCycle interface?
 * @param m//from   ww w. j  a v a2  s.c o  m
 * @return true if this method is from ServiceLifeCycle interface
 */
private boolean isServiceLifeCycleMethod(Class implClass, Method m) {
    if (javax.xml.rpc.server.ServiceLifecycle.class.isAssignableFrom(implClass)) {
        String methodName = m.getName();

        if (methodName.equals("init")) {
            // Check if the method signature is 
            // "public abstract void init(Object context) throws ServiceException;"
            Class[] classes = m.getParameterTypes();
            if (classes != null && classes.length == 1 && classes[0] == Object.class
                    && m.getReturnType() == Void.TYPE) {
                return true;
            }
        } else if (methodName.equals("destroy")) {
            // Check if the method signature is 
            // "public abstract void destroy();"
            Class[] classes = m.getParameterTypes();
            if (classes != null && classes.length == 0 && m.getReturnType() == Void.TYPE) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.netspective.commons.xdm.XmlDataModelSchema.java

private XmlDataModelSchema(final Class bean) {
    propertyNames = new HashMap();
    attributeTypes = new HashMap();
    attributeSetters = new HashMap();
    attributeSetterMethods = new HashMap();
    attributeAccessors = new HashMap();
    flagsAttributeAccessors = new HashMap();
    nestedTypes = new HashMap();
    nestedCreators = new HashMap();
    nestedAltClassNameCreators = new HashMap();
    nestedAdders = new HashMap();
    nestedStorers = new HashMap();

    this.bean = bean;

    Options customOptions = (Options) getStaticFieldValue(bean, XMLDATAMODEL_SCHEMA_OPTIONS_FIELD_NAME);
    options = customOptions != null ? customOptions : new Options();

    Method[] methods = bean.getMethods();
    for (int i = 0; i < methods.length; i++) {
        final Method m = methods[i];
        final String name = m.getName();
        Class returnType = m.getReturnType();
        Class[] args = m.getParameterTypes();

        if (name.equals(options.pcDataHandlerMethodName) && java.lang.Void.TYPE.equals(returnType)
                && args.length == 1 && java.lang.String.class.equals(args[0])) {
            addText = methods[i];//  w ww  .j a  v a 2  s .  c om
        } else if (name.startsWith("get") && args.length == 0) {
            String[] propNames = getPropertyNames(name, "get");
            for (int pn = 0; pn < propNames.length; pn++) {
                if (propNames[pn].length() == 0)
                    continue;

                AttributeAccessor aa = createAttributeAccessor(m, propNames[pn], returnType);
                if (aa != null)
                    attributeAccessors.put(propNames[pn], aa);
            }
        } else if (name.startsWith("is") && args.length == 0) {
            String[] propNames = getPropertyNames(name, "is");
            for (int pn = 0; pn < propNames.length; pn++) {
                if (propNames[pn].length() == 0)
                    continue;

                AttributeAccessor aa = createAttributeAccessor(m, propNames[pn], returnType);
                if (aa != null)
                    attributeAccessors.put(propNames[pn], aa);
            }
        } else if (name.startsWith("set") && java.lang.Void.TYPE.equals(returnType) && args.length == 1
                && (!args[0].isArray() || java.lang.String[].class.equals(args[0]))) {
            String[] propNames = getPropertyNames(name, "set");
            for (int pn = 0; pn < propNames.length; pn++) {
                if (propNames[pn].length() == 0)
                    continue;

                attributeSetterMethods.put(propNames[pn], m);
                AttributeSetter as = createAttributeSetter(m, propNames[pn], args[0]);
                if (as != null) {
                    attributeTypes.put(propNames[pn], args[0]);
                    attributeSetters.put(propNames[pn], as);
                }
            }
        } else if (name.startsWith("create") && !returnType.isArray() && !returnType.isPrimitive()
                && (args.length == 0)) {
            // prevent infinite recursion for nested recursive elements
            if (!returnType.getClass().equals(bean.getClass()))
                getSchema(returnType);
            String[] propNames = getPropertyNames(name, "create");
            for (int pn = 0; pn < propNames.length; pn++) {
                if (propNames[pn].length() == 0)
                    continue;

                nestedTypes.put(propNames[pn], returnType);
                nestedCreators.put(propNames[pn], new NestedCreator() {
                    public Object create(Object parent)
                            throws InvocationTargetException, IllegalAccessException {
                        return m.invoke(parent, new Object[] {});
                    }

                    public boolean isInherited() {
                        return !m.getDeclaringClass().equals(bean);
                    }

                    public Class getDeclaringClass() {
                        return m.getDeclaringClass();
                    }
                });
            }
        } else if (name.startsWith("create") && !returnType.isArray() && !returnType.isPrimitive()
                && (args.length == 1 && args[0] == Class.class)) {
            // prevent infinite recursion for nested recursive elements
            if (!returnType.getClass().equals(bean.getClass()))
                getSchema(returnType);
            String[] propNames = getPropertyNames(name, "create");
            for (int pn = 0; pn < propNames.length; pn++) {
                if (propNames[pn].length() == 0)
                    continue;

                nestedTypes.put(propNames[pn], returnType);
                nestedAltClassNameCreators.put(propNames[pn], new NestedAltClassCreator() {
                    public Object create(Object parent, Class cls)
                            throws InvocationTargetException, IllegalAccessException {
                        return m.invoke(parent, new Object[] { cls });
                    }

                    public boolean isInherited() {
                        return !m.getDeclaringClass().equals(bean);
                    }

                    public Class getDeclaringClass() {
                        return m.getDeclaringClass();
                    }
                });
            }
        } else if (name.startsWith("add") && java.lang.Void.TYPE.equals(returnType) && args.length == 1
                && !java.lang.String.class.equals(args[0]) && !args[0].isArray() && !args[0].isPrimitive()) {
            String[] propNames = getPropertyNames(name, "add");
            try {
                final Constructor c = args[0].getConstructor(new Class[] {});
                for (int pn = 0; pn < propNames.length; pn++) {
                    if (propNames[pn].length() == 0)
                        continue;

                    if (!nestedCreators.containsKey(propNames[pn])) {
                        nestedTypes.put(propNames[pn], args[0]);
                        nestedCreators.put(propNames[pn], new NestedCreator() {
                            public boolean allowAlternateClass() {
                                return false;
                            }

                            public Object create(Object parent) throws InvocationTargetException,
                                    IllegalAccessException, InstantiationException {
                                return c.newInstance(new Object[] {});
                            }

                            public Object create(Object parent, Class cls) throws InvocationTargetException,
                                    IllegalAccessException, InstantiationException {
                                return c.newInstance(new Object[] { cls });
                            }

                            public boolean isInherited() {
                                return !m.getDeclaringClass().equals(bean);
                            }

                            public Class getDeclaringClass() {
                                return m.getDeclaringClass();
                            }
                        });
                    }
                }
            } catch (NoSuchMethodException nse) {
                //log.warn("Unable to create nestedCreator for " + name + " " + args[0] + ", registering type only without a creator.", nse);
                for (int pn = 0; pn < propNames.length; pn++) {
                    if (propNames[pn].length() > 0)
                        nestedTypes.put(propNames[pn], args[0]);
                }
            }

            // prevent infinite recursion for nested recursive elements
            if (!args[0].getClass().equals(bean.getClass()))
                getSchema(args[0]);
            for (int pn = 0; pn < propNames.length; pn++) {
                if (propNames[pn].length() == 0)
                    continue;

                nestedStorers.put(propNames[pn], new NestedStorer() {
                    public void store(Object parent, Object child)
                            throws InvocationTargetException, IllegalAccessException {
                        m.invoke(parent, new Object[] { child });
                    }

                    public boolean isInherited() {
                        return !m.getDeclaringClass().equals(bean);
                    }

                    public Class getDeclaringClass() {
                        return m.getDeclaringClass();
                    }
                });
            }
        }
    }
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedProxyClassGenerator.java

private void writeDelegatedMethod(ClassVisitor visitor, Type generatedType, Class<?> delegateTypeClass,
        Method method) {//from w ww  . j  av  a  2 s. co m
    MethodVisitor methodVisitor = declareMethod(visitor, method.getName(), Type.getMethodDescriptor(method),
            AsmClassGeneratorUtils.signature(method));
    invokeDelegateMethod(methodVisitor, generatedType, delegateTypeClass, method);
    final Class<?> returnType = method.getReturnType();
    if (returnType == Void.TYPE) {
        finishVisitingMethod(methodVisitor);
    } else {
        finishVisitingMethod(methodVisitor, returnCode(returnType));
    }
}

From source file:com.googlecode.wicketwebbeans.model.BeanMetaData.java

/**
 * Find action methods for a class. //from  w  w  w.  j  a va 2s.c om
 *
 * @param aClass the class.
 * 
 * @return an List of sorted action methods, possibly empty.
 */
private List<Method> getActionMethods(Class<? extends Component> aClass) {
    List<Method> result = new ArrayList<Method>();
    for (Method method : aClass.getMethods()) {
        Class<?>[] params = method.getParameterTypes();
        Class<?> returnType = method.getReturnType();
        if (returnType.equals(Void.TYPE) && params.length == 3 && params[0] == AjaxRequestTarget.class
                && params[1] == Form.class && (params[2] == beanClass || params[2] == Object.class)) {
            result.add(method);
        }
    }

    Collections.sort(result, new Comparator<Method>() {
        public int compare(Method o1, Method o2) {
            return o1.getName().compareTo(o2.getName());
        }

    });
    return result;
}

From source file:com.github.javalbert.reflection.ClassAccessFactory.java

private void visitMethodAccessInvokeMethod() {
    mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, "invoke",
            "(" + classTypeDescriptor + "I[Ljava/lang/Object;)Ljava/lang/Object;", null, null);
    mv.visitCode();/*  w  w w.jav  a  2  s .  c o m*/
    Label firstLabel = new Label();
    mv.visitLabel(firstLabel);
    mv.visitVarInsn(ILOAD, 2);

    Label defaultCaseLabel = new Label();

    if (methodInfoList == null || methodInfoList.isEmpty()) {
        mv.visitInsn(POP);
        mv.visitLabel(defaultCaseLabel);
        visitMethodAccessInvokeMethodLastPart(firstLabel);
        return;
    }

    Label[] labels = getTableSwitchLabelsForAccess(defaultCaseLabel, methodInfoList);

    // Always use a table switch because there are no gaps between method indices
    mv.visitTableSwitchInsn(methodInfoList.get(0).memberIndex,
            methodInfoList.get(methodInfoList.size() - 1).memberIndex, defaultCaseLabel, labels);

    for (int i = 0; i < methodInfoList.size(); i++) {
        MethodInfo methodInfo = methodInfoList.get(i);

        mv.visitLabel(labels[i]);
        mv.visitFrame(F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, 1);

        List<ParameterInfo> parameters = methodInfo.parameters;
        for (int j = 0; j < parameters.size(); j++) {
            ParameterInfo parameter = parameters.get(j);

            mv.visitVarInsn(ALOAD, 3);
            AsmUtils.visitZeroOperandInt(mv, j);
            mv.visitInsn(AALOAD);

            checkCast(parameter);
        }

        mv.visitMethodInsn(methodInfo.invokeOpcode, internalName, methodInfo.name, methodInfo.descriptor, true);
        if (methodInfo.method.getReturnType() == Void.TYPE) {
            mv.visitLabel(new Label());
            mv.visitInsn(ACONST_NULL);
        }
        mv.visitInsn(ARETURN);
    }

    mv.visitLabel(defaultCaseLabel);
    mv.visitFrame(F_SAME, 0, null, 0, null);

    visitMethodAccessInvokeMethodLastPart(firstLabel);
}

From source file:org.apache.bval.jsr.ClassValidator.java

public <T> Set<ConstraintViolation<T>> validateParameters(T object, Method method, Object[] parameterValues,
        Class<?>... groups) {
    {//from w  w w  . ja va 2 s  .  c o  m
        notNull("Object", object);
        notNull("Parameters", parameterValues);
        notNull("Method", method);
        notNull("Groups", groups);
        for (final Class<?> g : groups) {
            notNull("Each group", g);
        }
    }

    final MethodDescriptorImpl methodDescriptor = findMethodDescriptor(object, method);
    if (methodDescriptor == null
            || !(methodDescriptor.hasConstrainedParameters() || methodDescriptor.hasConstrainedReturnValue())) { // no constraint
        return Collections.emptySet();
    }

    if (!methodDescriptor.isValidated(method)) {
        if (method.getParameterTypes().length > 0 && method.getReturnType() != Void.TYPE) {
            checkValidationAppliesTo(Collections.singleton(methodDescriptor.getCrossParameterDescriptor()),
                    ConstraintTarget.IMPLICIT);
            checkValidationAppliesTo(methodDescriptor.getParameterDescriptors(), ConstraintTarget.IMPLICIT);
        } else if (method.getParameterTypes().length == 0) {
            checkValidationAppliesTo(Collections.singleton(methodDescriptor.getCrossParameterDescriptor()),
                    ConstraintTarget.PARAMETERS);
            checkValidationAppliesTo(methodDescriptor.getParameterDescriptors(), ConstraintTarget.PARAMETERS);
        }
        methodDescriptor.setValidated(method);
    }

    return validateInvocationParameters(method, parameterValues, methodDescriptor, groups,
            new NodeImpl.MethodNodeImpl(method.getName(), Arrays.asList(method.getParameterTypes())), object);
}

From source file:com.github.javalbert.reflection.ClassAccessFactory.java

private void visitMethodAccessMethod(int parameterCount) {
    List<MethodInfo> methodsWithParamCount = paramCountMethodsMap.get(parameterCount);

    mv = cw.visitMethod(ACC_PUBLIC, "call", getMethodAccessMethodDescriptor(parameterCount), null, null);
    mv.visitCode();//from   w ww  .  ja  v  a  2s.  c  om
    Label firstLabel = new Label();
    mv.visitLabel(firstLabel);
    mv.visitVarInsn(ILOAD, 2);

    Label defaultCaseLabel = new Label();

    if (methodsWithParamCount == null || methodsWithParamCount.isEmpty()) {
        mv.visitInsn(POP);
        mv.visitLabel(defaultCaseLabel);
        visitMethodAccessLastPart(firstLabel, parameterCount);
        return;
    }

    boolean useTableSwitch = useTableSwitch(methodsWithParamCount);
    Label[] labels = useTableSwitch ? getTableSwitchLabelsForAccess(defaultCaseLabel, methodsWithParamCount)
            : newLabelArray(methodsWithParamCount.size());

    if (useTableSwitch) {
        mv.visitTableSwitchInsn(methodsWithParamCount.get(0).memberIndex,
                methodsWithParamCount.get(methodsWithParamCount.size() - 1).memberIndex, defaultCaseLabel,
                labels);
    } else {
        mv.visitLookupSwitchInsn(defaultCaseLabel,
                methodsWithParamCount.stream().mapToInt(f -> f.memberIndex).toArray(), labels);
    }

    for (int i = 0; i < methodsWithParamCount.size(); i++) {
        MethodInfo methodInfo = methodsWithParamCount.get(i);

        mv.visitLabel(labels[i]);
        mv.visitFrame(F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, 1);

        List<ParameterInfo> parameters = methodInfo.parameters;
        for (int j = 0; j < parameters.size(); j++) {
            ParameterInfo parameter = parameters.get(j);

            mv.visitVarInsn(ALOAD, 3 + j);

            checkCast(parameter);
        }

        mv.visitMethodInsn(methodInfo.invokeOpcode, internalName, methodInfo.name, methodInfo.descriptor, true);
        if (methodInfo.method.getReturnType() == Void.TYPE) {
            mv.visitLabel(new Label());
            mv.visitInsn(ACONST_NULL);
        }
        mv.visitInsn(ARETURN);
    }

    mv.visitLabel(defaultCaseLabel);
    mv.visitFrame(F_SAME, 0, null, 0, null);

    visitMethodAccessLastPart(firstLabel, parameterCount);
}