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.springframework.cloud.stream.reactive.StreamEmitterAnnotationBeanPostProcessor.java

private static void validateStreamEmitterMethod(Method method, int outputAnnotationCount,
        String methodAnnotatedOutboundName) {

    if (StringUtils.hasText(methodAnnotatedOutboundName)) {
        Assert.isTrue(outputAnnotationCount == 0, StreamEmitterErrorMessages.INVALID_OUTPUT_METHOD_PARAMETERS);
    } else {//w w w  .  j a va2  s  . c o m
        Assert.isTrue(outputAnnotationCount > 0, StreamEmitterErrorMessages.NO_OUTPUT_SPECIFIED);
    }

    if (!method.getReturnType().equals(Void.TYPE)) {
        Assert.isTrue(StringUtils.hasText(methodAnnotatedOutboundName),
                StreamEmitterErrorMessages.RETURN_TYPE_NO_OUTBOUND_SPECIFIED);
        Assert.isTrue(method.getParameterCount() == 0, StreamEmitterErrorMessages.RETURN_TYPE_METHOD_ARGUMENTS);
    } else {
        if (!StringUtils.hasText(methodAnnotatedOutboundName)) {
            int methodArgumentsLength = method.getParameterTypes().length;
            for (int parameterIndex = 0; parameterIndex < methodArgumentsLength; parameterIndex++) {
                MethodParameter methodParameter = new MethodParameter(method, parameterIndex);
                if (methodParameter.hasParameterAnnotation(Output.class)) {
                    String outboundName = (String) AnnotationUtils
                            .getValue(methodParameter.getParameterAnnotation(Output.class));
                    Assert.isTrue(StringUtils.hasText(outboundName),
                            StreamEmitterErrorMessages.INVALID_OUTBOUND_NAME);
                } else {
                    throw new IllegalArgumentException(
                            StreamEmitterErrorMessages.OUTPUT_ANNOTATION_MISSING_ON_METHOD_PARAMETERS_VOID_RETURN_TYPE);
                }
            }
        }
    }
}

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

@Override
public ResolvedType getReturnType() {
    if (resourceType() == ResourceType.ITEM) {
        MemberResolver memberResolver = new MemberResolver(resolver);
        ResolvedTypeWithMembers members = memberResolver
                .resolve(resolver.resolve(searchResource.getMethod().getDeclaringClass()), null, null);
        for (ResolvedMethod resolvedMethod : members.getMemberMethods()) {
            if (resolvedMethod.getRawMember().equals(searchResource.getMethod())) {
                return resolvedMethod.getReturnType();
            }//from  www . ja v  a2 s  .  c  o  m
        }
        return resolver.resolve(Void.TYPE);
    } else {
        return resolver.resolve(handlerMethod.getReturnType().getParameterType());
    }
}

From source file:r.jvmi.binding.JvmMethod.java

/**
 * Invokes the method with the given arguments and converts the return value to
 * an R {@code SEXP} and wraps the {@code SEXP} in a {@code EvalResult}.
 *//*  ww w  .  j  ava2  s .  c  o m*/
public SEXP invokeAndWrap(Context context, Object... arguments) {
    Object result = invoke(arguments);

    if (method.getReturnType() == Void.TYPE) {
        context.setInvisibleFlag();
        return Null.INSTANCE;
    } else {
        return SEXPFactory.fromJava(result);
    }
}

From source file:org.oddjob.framework.WrapDynaClass.java

/**
 * Introspect our bean class to identify the supported properties.
 *///w ww.  ja  v a  2 s.c  o m
protected void introspect(Class<?> beanClass) {
    Set<String> mismatched = new HashSet<String>();

    // first find simple and indexed properties via usual means.
    PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(beanClass);
    for (int i = 0; i < descriptors.length; ++i) {
        PropertyDescriptor descriptor = descriptors[i];

        String propertyName = descriptor.getName();

        DynaProperty dynaProperty;
        // indexed property?
        if (descriptor instanceof IndexedPropertyDescriptor) {
            dynaProperty = new DynaProperty(propertyName, descriptor.getPropertyType(),
                    ((IndexedPropertyDescriptor) descriptor).getIndexedPropertyType());
        }
        // else a simple property.
        else {
            dynaProperty = new DynaProperty(propertyName, descriptor.getPropertyType());
        }

        propertiesMap.put(propertyName, dynaProperty);

        // update readable writable
        if (MethodUtils.getAccessibleMethod(descriptor.getReadMethod()) != null) {
            readableProperties.add(propertyName);
        }
        if (MethodUtils.getAccessibleMethod(descriptor.getWriteMethod()) != null) {
            writableProperties.add(propertyName);
        }
    }

    // now find mapped properties.
    Method[] methods = beanClass.getMethods();
    for (int i = 0; i < methods.length; ++i) {
        Method method = methods[i];

        // methods beginning with get could be properties.          
        if (!method.getName().startsWith("get") && !method.getName().startsWith("set")) {
            continue;
        }

        String propertyName = method.getName().substring(3);
        // get on it's own is not a property
        if (propertyName.length() == 0) {
            continue;
        }

        // lowercase first letter
        propertyName = propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1);

        Class<?>[] args = method.getParameterTypes();

        DynaProperty dynaProperty = null;

        boolean readable = false;
        boolean writable = false;

        // is mapped property?
        if (method.getName().startsWith("get") && Void.TYPE != method.getReturnType() && args.length == 1
                && args[0] == String.class) {
            DynaProperty existing = (DynaProperty) propertiesMap.get(propertyName);
            if (existing != null && !existing.isMapped()) {
                mismatched.add(propertyName);
                continue;
            }
            dynaProperty = new DynaProperty(propertyName, Map.class, method.getReturnType());
            readable = true;
        } else if (args.length == 2 && args[0] == String.class && Void.TYPE == method.getReturnType()) {
            DynaProperty existing = (DynaProperty) propertiesMap.get(propertyName);
            if (existing != null && !existing.isMapped()) {
                mismatched.add(propertyName);
                continue;
            }
            dynaProperty = new DynaProperty(propertyName, Map.class, args[1]);
            writable = true;
        } else {
            continue;
        }
        propertiesMap.put(propertyName, dynaProperty);

        // update readable writable
        if (readable) {
            readableProperties.add(propertyName);
        }
        if (writable) {
            writableProperties.add(propertyName);
        }
    }

    for (String element : mismatched) {
        propertiesMap.remove(element);
        readableProperties.remove(element);
        writableProperties.remove(element);
    }

    properties = (DynaProperty[]) propertiesMap.values().toArray(new DynaProperty[0]);

}

From source file:net.sf.ehcache.config.BeanHandler.java

/**
 * Finds a setter method.// w ww . jav  a  2s. c o m
 */
private Method findSetMethod(final Class objClass, final String prefix, final String name) throws Exception {
    final String methodName = makeMethodName(prefix, name);
    final Method[] methods = objClass.getMethods();
    Method candidate = null;
    for (int i = 0; i < methods.length; i++) {
        final Method method = methods[i];
        if (!method.getName().equals(methodName)) {
            continue;
        }
        if (Modifier.isStatic(method.getModifiers())) {
            continue;
        }
        if (method.getParameterTypes().length != 1) {
            continue;
        }
        if (!method.getReturnType().equals(Void.TYPE)) {
            continue;
        }
        if (candidate != null) {
            throw new Exception("Multiple " + methodName + "() methods in class " + objClass.getName() + ".");
        }
        candidate = method;
    }

    return candidate;
}

From source file:ipc.WritableRpcEngine.java

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

    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 www  . j  a va2 s.  co  m
        Writable[] wrappedValues = client.call(invocations, addrs, method.getDeclaringClass());

        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.netspective.commons.lang.ValueBeanGeneratorClassLoader.java

/**
 * Convert runtime java.lang.Class to BCEL Type object.
 *
 * @param cl Java class// www. j a va  2s.c  o  m
 *
 * @return corresponding Type object
 */
public static Type getBCELType(java.lang.Class cl) {
    if (cl == null) {
        throw new IllegalArgumentException("Class must not be null");
    }

    /* That's an amzingly easy case, because getName() returns
     * the signature. That's what we would have liked anyway.
     */
    if (cl.isArray()) {
        return Type.getType(cl.getName());
    } else if (cl.isPrimitive()) {
        if (cl == Integer.TYPE) {
            return Type.INT;
        } else if (cl == Void.TYPE) {
            return Type.VOID;
        } else if (cl == Double.TYPE) {
            return Type.DOUBLE;
        } else if (cl == Float.TYPE) {
            return Type.FLOAT;
        } else if (cl == Boolean.TYPE) {
            return Type.BOOLEAN;
        } else if (cl == Byte.TYPE) {
            return Type.BYTE;
        } else if (cl == Short.TYPE) {
            return Type.SHORT;
        } else if (cl == Long.TYPE) {
            return Type.LONG;
        } else if (cl == Character.TYPE) {
            return Type.CHAR;
        } else {
            throw new IllegalStateException("Ooops, what primitive type is " + cl);
        }
    } else { // "Real" class
        return new ObjectType(cl.getName());
    }
}

From source file:org.springframework.aop.framework.JdkDynamicAopProxy.java

/**
 * Implementation of {@code InvocationHandler.invoke}.
 * <p>Callers will see exactly the exception thrown by the target,
 * unless a hook method throws an exception.
 *///  www  . j a  v a 2 s .  c o m
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    MethodInvocation invocation;
    Object oldProxy = null;
    boolean setProxyContext = false;

    TargetSource targetSource = this.advised.targetSource;
    Object target = null;

    try {
        if (!this.equalsDefined && AopUtils.isEqualsMethod(method)) {
            // The target does not implement the equals(Object) method itself.
            return equals(args[0]);
        } else if (!this.hashCodeDefined && AopUtils.isHashCodeMethod(method)) {
            // The target does not implement the hashCode() method itself.
            return hashCode();
        } else if (method.getDeclaringClass() == DecoratingProxy.class) {
            // There is only getDecoratedClass() declared -> dispatch to proxy config.
            return AopProxyUtils.ultimateTargetClass(this.advised);
        } else if (!this.advised.opaque && method.getDeclaringClass().isInterface()
                && method.getDeclaringClass().isAssignableFrom(Advised.class)) {
            // Service invocations on ProxyConfig with the proxy config...
            return AopUtils.invokeJoinpointUsingReflection(this.advised, method, args);
        }

        Object retVal;

        if (this.advised.exposeProxy) {
            // Make invocation available if necessary.
            oldProxy = AopContext.setCurrentProxy(proxy);
            setProxyContext = true;
        }

        // Get as late as possible to minimize the time we "own" the target,
        // in case it comes from a pool.
        target = targetSource.getTarget();
        Class<?> targetClass = (target != null ? target.getClass() : null);

        // Get the interception chain for this method.
        List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);

        // Check whether we have any advice. If we don't, we can fallback on direct
        // reflective invocation of the target, and avoid creating a MethodInvocation.
        if (chain.isEmpty()) {
            // We can skip creating a MethodInvocation: just invoke the target directly
            // Note that the final invoker must be an InvokerInterceptor so we know it does
            // nothing but a reflective operation on the target, and no hot swapping or fancy proxying.
            Object[] argsToUse = AopProxyUtils.adaptArgumentsIfNecessary(method, args);
            retVal = AopUtils.invokeJoinpointUsingReflection(target, method, argsToUse);
        } else {
            // We need to create a method invocation...
            invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
            // Proceed to the joinpoint through the interceptor chain.
            retVal = invocation.proceed();
        }

        // Massage return value if necessary.
        Class<?> returnType = method.getReturnType();
        if (retVal != null && retVal == target && returnType != Object.class && returnType.isInstance(proxy)
                && !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
            // Special case: it returned "this" and the return type of the method
            // is type-compatible. Note that we can't help if the target sets
            // a reference to itself in another returned object.
            retVal = proxy;
        } else if (retVal == null && returnType != Void.TYPE && returnType.isPrimitive()) {
            throw new AopInvocationException(
                    "Null return value from advice does not match primitive return type for: " + method);
        }
        return retVal;
    } finally {
        if (target != null && !targetSource.isStatic()) {
            // Must have come from TargetSource.
            targetSource.releaseTarget(target);
        }
        if (setProxyContext) {
            // Restore old proxy.
            AopContext.setCurrentProxy(oldProxy);
        }
    }
}

From source file:salvatejero.cordova.liferay.LiferayPlugin.java

private void getObjectModel(final CallbackContext callbackContext, String className, String methodName,
        JSONArray values) throws Exception {

    JSONArray jsonArrayInstance = new JSONArray();
    JSONObject jsonObjectInstance = new JSONObject();

    JSONObjectAsyncTaskCallback callBackJSONObject = new JSONObjectAsyncTaskCallback() {

        @Override//from   w  ww.  jav  a 2s  .  c  o m
        public void onFailure(Exception arg0) {
            callbackContext.error(arg0.getMessage());
        }

        @Override
        public void onSuccess(JSONObject arg0) {
            // TODO Auto-generated method stub
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, arg0);
            pluginResult.setKeepCallback(true);
            callbackContext.sendPluginResult(pluginResult);
        }

    };

    JSONArrayAsyncTaskCallback callbackJSONArray = new JSONArrayAsyncTaskCallback() {

        @Override
        public void onFailure(Exception arg0) {
            callbackContext.error(arg0.getMessage());
        }

        @Override
        public void onSuccess(JSONArray arg0) {
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, arg0);
            pluginResult.setKeepCallback(true);
            callbackContext.sendPluginResult(pluginResult);

        }
    };

    Method methodToExecute = null;
    Object[] params = null;
    BaseService service = getService(className);

    if (service == null) {
        throw new LiferayPluginException("Service not implemented");
    }
    Method[] methods = service.getClass().getMethods();
    for (Method m : methods) {
        if (m.getName().toLowerCase().equals(methodName.toLowerCase())) {

            if (values.length() != m.getParameterTypes().length) {
                throw new LiferayPluginException("Number of params error for the method " + methodName);
            }
            params = getListOfParam(m, values);
            if (m.getReturnType().isInstance(jsonArrayInstance)) {
                session.setCallback(callbackJSONArray);
            } else if (m.getReturnType().isInstance(jsonObjectInstance)) {
                session.setCallback(callBackJSONObject);
            } else if (m.getReturnType().equals(Void.TYPE)) {
                callbackContext.success();
            }

            methodToExecute = m;
            break;
        }
    }
    if (methodToExecute == null) {
        for (Method m : methods) {
            if (methodName.indexOf(m.getName().toLowerCase()) >= 0) {

                if (values.length() != m.getParameterTypes().length) {
                    throw new LiferayPluginException("Number of params error for the method " + methodName);
                }
                params = getListOfParam(m, values);
                if (m.getReturnType().isInstance(jsonArrayInstance)) {
                    session.setCallback(callbackJSONArray);
                } else if (m.getReturnType().isInstance(jsonObjectInstance)) {
                    session.setCallback(callBackJSONObject);
                } else if (m.getReturnType().equals(Void.TYPE)) {
                    callbackContext.success();
                }

                methodToExecute = m;
                break;
            }
        }
    }
    if (methodToExecute == null) {
        throw new LiferayPluginException("Method " + methodName + "not found");
    }

    try {
        methodToExecute.invoke(service, params);
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new LiferayPluginException("Error invoking -- " + e.getMessage());
    }

}

From source file:com.mystudy.source.spring.aop.JdkDynamicAopProxy.java

/**
 * // w w  w  .j av a2 s  .c o m
 */
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    MethodInvocation invocation;
    Object oldProxy = null;
    boolean setProxyContext = false;

    TargetSource targetSource = this.advised.targetSource;
    Class<?> targetClass = null;
    Object target = null;

    try {//eqal
        if (!this.equalsDefined && AopUtils.isEqualsMethod(method)) {
            // The target does not implement the equals(Object) method itself.
            return equals(args[0]);
        }
        //hashcode
        if (!this.hashCodeDefined && AopUtils.isHashCodeMethod(method)) {
            // The target does not implement the hashCode() method itself.
            return hashCode();
        }

        if (!this.advised.opaque && method.getDeclaringClass().isInterface()
                && method.getDeclaringClass().isAssignableFrom(Advised.class)) {
            // Service invocations on ProxyConfig with the proxy config...
            return AopUtils.invokeJoinpointUsingReflection(this.advised, method, args);
        }

        Object retVal;

        if (this.advised.exposeProxy) {
            // Make invocation available if necessary.
            oldProxy = AopContext.setCurrentProxy(proxy);
            setProxyContext = true;
        }

        // May be null. Get as late as possible to minimize the time we "own" the target,
        // in case it comes from a pool.
        target = targetSource.getTarget();
        if (target != null) {
            targetClass = target.getClass();
        }

        // Get the interception chain for this method.
        List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);

        // Check whether we have any advice. If we don't, we can fallback on direct
        // reflective invocation of the target, and avoid creating a MethodInvocation.
        if (chain.isEmpty()) {
            // We can skip creating a MethodInvocation: just invoke the target directly
            // Note that the final invoker must be an InvokerInterceptor so we know it does
            // nothing but a reflective operation on the target, and no hot swapping or fancy proxying.
            retVal = AopUtils.invokeJoinpointUsingReflection(target, method, args);
        } else {
            //chain????
            // We need to create a method invocation...
            invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
            // Proceed to the joinpoint through the interceptor chain.
            retVal = invocation.proceed();
        }

        // Massage return value if necessary.
        Class<?> returnType = method.getReturnType();
        if (retVal != null && retVal == target && returnType.isInstance(proxy)
                && !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
            // Special case: it returned "this" and the return type of the method
            // is type-compatible. Note that we can't help if the target sets
            // a reference to itself in another returned object.
            retVal = proxy;
        } else if (retVal == null && returnType != Void.TYPE && returnType.isPrimitive()) {
            throw new AopInvocationException(
                    "Null return value from advice does not match primitive return type for: " + method);
        }
        return retVal;
    } finally {
        if (target != null && !targetSource.isStatic()) {
            // Must have come from TargetSource.
            targetSource.releaseTarget(target);
        }
        if (setProxyContext) {
            // Restore old proxy.
            AopContext.setCurrentProxy(oldProxy);
        }
    }
}