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.bonitasoft.engine.business.data.generator.CodeGenerator.java

public JMethod addListSetter(final JDefinedClass definedClass, final JFieldVar field) {
    final JMethod method = definedClass.method(JMod.PUBLIC, Void.TYPE, getSetterName(field));
    method.param(field.type(), field.name());
    final JFieldRef thisField = JExpr._this().ref(field.name());
    final JConditional ifListIsNull = method.body()._if(thisField.eq(JExpr._null()));

    ifListIsNull._then().assign(JExpr._this().ref(field.name()), JExpr.ref(field.name()));

    final JBlock elseBlock = ifListIsNull._else();
    final JVar copyVar = elseBlock.decl(field.type(), "copy",
            JExpr._new(getModel().ref(ArrayList.class)).arg(field));
    elseBlock.invoke(JExpr._this().ref(field.name()), "clear");
    elseBlock.invoke(JExpr._this().ref(field.name()), "addAll").arg(copyVar);

    return method;
}

From source file:org.unitils.mock.core.MockFactory.java

public Mock<?> createChainedMock(MatchingInvocation matchingInvocation) {
    Object matchingProxy = matchingInvocation.getProxy();
    Map<Method, Mock<?>> chainedMocksForProxy = chainedMocks.get(matchingProxy);
    if (chainedMocksForProxy == null) {
        chainedMocksForProxy = new HashMap<Method, Mock<?>>();
        chainedMocks.put(matchingProxy, chainedMocksForProxy);
    }//from www.j  a v a  2  s  .  c o  m
    Method method = matchingInvocation.getMethod();
    Mock<?> chainedMock = chainedMocksForProxy.get(method);
    if (chainedMock != null) {
        return chainedMock;
    }
    String name = matchingInvocation.getInnerMockName();
    Class<?> mockedType = matchingInvocation.getReturnType();
    if (mockedType == Void.TYPE) {
        return null;
    }
    if (mockedType.isPrimitive() || mockedType.isArray() || Modifier.isFinal(mockedType.getModifiers())) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unable to create chained mock " + name + " for return type +" + mockedType
                    + ". Chaining not supported for primitive, arrays or final types, returning null.");
        }
        return null;
    }
    try {
        chainedMock = createMockObject(name, mockedType, true);
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unable to create chained mock " + name + " for return type +" + mockedType
                    + ". Chaining not supported, returning null.");
        }
        return null;
    }
    chainedMocksForProxy.put(method, chainedMock);
    return chainedMock;
}

From source file:org.callimachusproject.webdriver.helpers.BrowserFunctionalTestCase.java

public static TestSuite suite(Class<? extends BrowserFunctionalTestCase> testcase) throws Exception {
    TestSuite suite = new TestSuite(testcase.getName());
    for (Method method : testcase.getMethods()) {
        if (method.getName().startsWith("test") && method.getParameterTypes().length == 0
                && method.getReturnType().equals(Void.TYPE)) {
            addTests(testcase, suite, method);
        }/*www .ja v  a2s.co m*/
    }
    if (suite.countTestCases() == 0) {
        suite.addTest(TestSuite.warning(testcase.getName() + " has no public test methods"));
    }
    return suite;
}

From source file:com.mcapanel.plugin.PluginConnector.java

@SuppressWarnings("unchecked")
private void doMethodAndRespond(String method, String paramStr) {
    JSONObject out = new JSONObject();

    out.put("plugin", "McAdminPanel");
    out.put("type", "response");
    out.put("method", method);

    String[] params = paramStr.length() != 0 ? paramStr.split(", ") : new String[0];

    try {//from w  ww  .j  a v a  2 s. c o m
        Class<?>[] paramClasses = new Class<?>[params.length];

        for (int i = 0; i < params.length; i++)
            paramClasses[i] = Class.forName("java.lang.String");

        Method m = methodHandler.getClass().getDeclaredMethod(method, paramClasses);

        String ret = (String) m.invoke(methodHandler, (Object[]) params);

        if (m.getReturnType().equals(Void.TYPE))
            return;

        out.put("response", ret);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }

    if (!out.containsKey("response"))
        out.put("response", "No such method");

    String cmd = "mcadminpanelplugincmd " + out.toJSONString();

    OutputStream writer = server.getWriter();

    try {
        writer.write((cmd + "\n").getBytes());
        writer.flush();
    } catch (IOException e) {
    }
}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupResolver.java

/**
 * Fallback used to load the methods from classloader
 *
 * @param clazzname//w w w  .j  a  va  2s .  co  m
 * @param variable
 * @return set with all methods, can be empty
 */
private Set<MemberLookupResult> getMethodsFromClassLoader(String clazzname, String variable) {
    final Set<MemberLookupResult> ret = new LinkedHashSet<>();
    try {
        Class clazz = classPath.getClassLoader(true).loadClass(clazzname);
        for (Method method : clazz.getMethods()) {
            if (method.getReturnType() != Void.TYPE && GETTER_PATTERN.matcher(method.getName()).matches()) {
                ret.add(new MemberLookupResult(variable, method.getName(), method.getReturnType().getName()));
            }
        }
        for (Field field : clazz.getFields()) {
            ret.add(new MemberLookupResult(variable, field.getName(), field.getType().getName()));
        }
    } catch (ClassNotFoundException cnfe) {
        LOGGER.log(Level.FINE, "Could not resolve class " + clazzname + "defined for variable " + variable,
                cnfe);
    }
    return ret;
}

From source file:nz.ac.otago.psyanlab.common.model.util.ModelUtils.java

/**
 * Checks to see the given ored set of return types intersects with the
 * given method's return type./*from www .  ja va 2s.  c  o m*/
 * 
 * @param method Method to test.
 * @param returnTypes Ored set of return types.
 * @return True if intersection.
 */
public static boolean returnTypeIntersects(Method method, int returnTypes) {
    if ((returnTypes & Type.TYPE_BOOLEAN) != 0 && method.getReturnType().equals(Boolean.TYPE)) {
        return true;
    }
    if ((returnTypes & Type.TYPE_INTEGER) != 0 && method.getReturnType().equals(Integer.TYPE)) {
        return true;
    }
    if ((returnTypes & Type.TYPE_FLOAT) != 0 && method.getReturnType().equals(Float.TYPE)) {
        return true;
    }
    if ((returnTypes & Type.TYPE_STRING) != 0 && method.getReturnType().equals(String.class)) {
        return true;
    }
    if (returnTypes == 0 && method.getReturnType().equals(Void.TYPE)) {
        return true;
    }
    return false;
}

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

/**
 * @since 5.7.2/*from ww w  .  j a v a2  s . c  o m*/
 * @param ctx the operation context.
 * @param operationType a chain or an operation.
 * @param params The chain parameters.
 */
public Object run(OperationContext ctx, OperationType operationType, Map<String, Object> params)
        throws OperationException {
    Boolean mainChain = true;
    CompiledChainImpl chain;
    if (params == null) {
        params = new HashMap<>();
    }
    ctx.put(Constants.VAR_RUNTIME_CHAIN, params);
    // Put Chain parameters into the context - even for cached chains
    if (!params.isEmpty()) {
        ctx.put(Constants.VAR_RUNTIME_CHAIN, params);
    }
    OperationCallback tracer;
    TracerFactory tracerFactory = Framework.getLocalService(TracerFactory.class);
    if (ctx.getChainCallback() == null) {
        tracer = tracerFactory.newTracer(operationType.getId());
        ctx.addChainCallback(tracer);
    } else {
        // Not logging at output if success for a child chain
        mainChain = false;
        tracer = ctx.getChainCallback();
    }
    try {
        Object input = ctx.getInput();
        Class<?> inputType = input == null ? Void.TYPE : input.getClass();
        tracer.onChain(operationType);
        if (ChainTypeImpl.class.isAssignableFrom(operationType.getClass())) {
            ctx.put(Constants.VAR_IS_CHAIN, true);
            CacheKey cacheKey = new CacheKey(operationType.getId(), inputType.getName());
            chain = compiledChains.get(cacheKey);
            if (chain == null) {
                chain = (CompiledChainImpl) operationType.newInstance(ctx, params);
                // Registered Chains are the only ones that can be cached
                // Runtime ones can update their operations, model...
                if (hasOperation(operationType.getId())) {
                    compiledChains.put(cacheKey, chain);
                }
            }
        } else {
            chain = CompiledChainImpl.buildChain(inputType, toParams(operationType.getId()));
        }
        Object ret = chain.invoke(ctx);
        tracer.onOutput(ret);
        if (ctx.getCoreSession() != null && ctx.isCommit()) {
            // auto save session if any.
            ctx.getCoreSession().save();
        }
        // Log at the end of the main chain execution.
        if (mainChain && tracer.getTrace() != null && tracerFactory.getRecordingState()) {
            log.info(tracer.getFormattedText());
        }
        return ret;
    } catch (OperationException oe) {
        // Record trace
        tracer.onError(oe);
        // Handle exception chain and rollback
        String operationTypeId = operationType.getId();
        if (hasChainException(operationTypeId)) {
            // Rollback is handled by chain exception
            return run(ctx, getChainExceptionToRun(ctx, operationTypeId, oe));
        } else if (oe.isRollback()) {
            ctx.setRollback();
        }
        // Handle exception
        if (mainChain) {
            throw new TraceException(tracer, oe);
        } else {
            throw new TraceException(oe);
        }
    } finally {
        ctx.dispose();
    }
}

From source file:org.springframework.messaging.handler.HandlerMethod.java

/**
 * Return {@code true} if the method return type is void, {@code false} otherwise.
 *///from  w  w  w  .ja v  a2s .c om
public boolean isVoid() {
    return Void.TYPE.equals(getReturnType().getParameterType());
}

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

@SuppressWarnings("unchecked")
protected Object doConvertTo(final Class type, final Exchange exchange, final Object value) {
    if (log.isTraceEnabled()) {
        log.trace("Converting " + (value == null ? "null" : value.getClass().getCanonicalName()) + " -> "
                + type.getCanonicalName() + " with value: " + value);
    }/*from w  ww.j a  va 2  s  .  c  om*/

    if (value == null) {
        // lets avoid NullPointerException when converting to boolean for null values
        if (boolean.class.isAssignableFrom(type)) {
            return Boolean.FALSE;
        }
        return null;
    }

    // same instance type
    if (type.isInstance(value)) {
        return type.cast(value);
    }

    // check if we have tried it before and if its a miss
    TypeMapping key = new TypeMapping(type, value.getClass());
    if (misses.containsKey(key)) {
        // we have tried before but we cannot convert this one
        return Void.TYPE;
    }

    // try to find a suitable type converter
    TypeConverter converter = getOrFindTypeConverter(type, value);
    if (converter != null) {
        if (log.isTraceEnabled()) {
            log.trace("Using converter: " + converter + " to convert " + key);
        }
        Object rc = converter.convertTo(type, exchange, value);
        if (rc != null) {
            return rc;
        }
    }

    // fallback converters
    for (FallbackTypeConverter fallback : fallbackConverters) {
        Object rc = fallback.getFallbackTypeConverter().convertTo(type, exchange, value);

        if (Void.TYPE.equals(rc)) {
            // it cannot be converted so give up
            return Void.TYPE;
        }

        if (rc != null) {
            // if fallback can promote then let it be promoted to a first class type converter
            if (fallback.isCanPromote()) {
                // add it as a known type converter since we found a fallback that could do it
                if (log.isDebugEnabled()) {
                    log.debug("Promoting fallback type converter as a known type converter to convert from: "
                            + type.getCanonicalName() + " to: " + value.getClass().getCanonicalName()
                            + " for the fallback converter: " + fallback.getFallbackTypeConverter());
                }
                addTypeConverter(type, value.getClass(), fallback.getFallbackTypeConverter());
            }

            if (log.isTraceEnabled()) {
                log.trace("Fallback type converter " + fallback.getFallbackTypeConverter()
                        + " converted type from: " + type.getCanonicalName() + " to: "
                        + value.getClass().getCanonicalName());
            }

            // return converted value
            return rc;
        }
    }

    // not found with that type then if it was a primitive type then try again with the wrapper type
    if (type.isPrimitive()) {
        Class primitiveType = ObjectHelper.convertPrimitiveTypeToWrapperType(type);
        if (primitiveType != type) {
            return convertTo(primitiveType, exchange, value);
        }
    }

    // Could not find suitable conversion, so remember it
    synchronized (misses) {
        misses.put(key, key);
    }

    // Could not find suitable conversion, so return Void to indicate not found
    return Void.TYPE;
}

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

@Override
public ResolvedType getReturnType() {
    if (resourceType == ResourceType.COLLECTION) {
        if (COLLECTION_COMPACT_MEDIA_TYPES
                .containsAll(requestMapping.getProducesCondition().getProducibleMediaTypes())) {
            return resolver.resolve(Resources.class, Link.class);
        } else if (requestMapping.getMethodsCondition().getMethods().contains(RequestMethod.HEAD)
                || requestMapping.getMethodsCondition().getMethods().contains(RequestMethod.OPTIONS)) {
            return resolver.resolve(Void.TYPE);
        } else if (requestMapping.getMethodsCondition().getMethods().contains(RequestMethod.POST)) {
            return resolver.resolve(Resource.class, domainType);
        }/*from   w ww .  java2 s  . c  om*/
        return resolver.resolve(Resources.class, domainType);
    } else {
        if (requestMapping.getMethodsCondition().getMethods().contains(RequestMethod.GET)
                || requestMapping.getMethodsCondition().getMethods().contains(RequestMethod.PUT)
                || requestMapping.getMethodsCondition().getMethods().contains(RequestMethod.PATCH)) {
            return resolver.resolve(Resource.class, domainType);
        }
    }
    return resolver.resolve(Void.TYPE);
}