List of usage examples for java.lang Void TYPE
Class TYPE
To view the source code for java.lang Void TYPE.
Click Source Link
From source file:tiemens.util.instancer.antlr.InstancerCode.java
private Class<?>[] getParameterTypesFromArgObj(Object[] parameters, List<Object> arglist) { if ((arglist == null) || (arglist.size() == 0)) { return null; } else {//from w w w . j a v a 2s . c om List<Class<?>> ret = new ArrayList<Class<?>>(); for (Object p : parameters) { if (p != null) { ret.add(p.getClass()); } else { ret.add(Void.TYPE); } } return ret.toArray(new Class[0]); } }
From source file:com.hablutzel.cmdline.CommandLineApplication.java
/** * Validate a Method to be a command line option methods. * * Methods with more than 1 argument are not allowed. Methods with return types * other than boolean are not allowed. Methods that throw an exception other than * org.apache.commons.cli.CommandLineException are not allowed, * * @param method the method to validate/*w w w. j av a2s . c om*/ * @param commandLineOption the options on that method * @return A new method helper for the method */ private CommandLineMethodHelper getHelperForCommandOption(Method method, CommandLineOption commandLineOption) throws CommandLineException { // Validate that the return type is a boolean or void if (!method.getReturnType().equals(Boolean.TYPE) && !method.getReturnType().equals(Void.TYPE)) { throw new CommandLineException( "For method " + method.getName() + ", the return type is not boolean or void"); } // Validate the exceptions throws by the method for (Class<?> clazz : method.getExceptionTypes()) { if (!clazz.equals(CommandLineException.class)) { throw new CommandLineException("For method " + method.getName() + ", there is an invalid exception class " + clazz.getName()); } } // In order to get ready to create the configuration instance, // we will need to know the command line option type // and the element type. Class<?> elementClass = null; MethodType methodType; Converter converter; // Get the parameters of the method. We'll use these to // determine what type of option we have - scalar, boolean, etc. Class<?> parameterClasses[] = method.getParameterTypes(); // See what the length tells us switch (parameterClasses.length) { case 0: methodType = MethodType.Boolean; converter = null; break; case 1: { // For a method with one argument, we have to look // more closely at the argument. It has to be a simple // scalar object, an array, or a list. Class<?> parameterClass = parameterClasses[0]; if (parameterClass.isArray()) { // For an array, we get the element class based on the // underlying component type methodType = MethodType.Array; elementClass = parameterClass.getComponentType(); } else if (List.class.isAssignableFrom(parameterClass)) { // For a list, we get the element class from the command // line options annotation methodType = MethodType.List; elementClass = commandLineOption.argumentType(); } else { // For a scalar, we get the element type from the // type of the parameter. methodType = MethodType.Scalar; elementClass = parameterClass.getClass(); } // Now that we have the element type, make sure it's convertable converter = ConvertUtils.lookup(String.class, elementClass); if (converter == null) { throw new CommandLineException("Cannot find a conversion from String to " + elementClass.getName() + " for method " + method.getName()); } break; } default: { // Other method types not allowed. throw new CommandLineException("Method " + method.getName() + " has too many arguments"); } } // Now we can return the configuration for this method return new CommandLineMethodHelper(method, methodType, elementClass, converter); }
From source file:org.unitils.spring.SpringModule.java
/** * Gets the application context for this class and sets it on the fields and setter methods that are * annotated with {@link SpringApplicationContext}. If no application context could be created, an * UnitilsException will be raised.// w ww . j a v a2 s. c om * * @param testObject The test instance, not null */ public void injectApplicationContext(Object testObject) { // inject into fields annotated with @SpringApplicationContext Set<Field> fields = getFieldsAnnotatedWith(testObject.getClass(), SpringApplicationContext.class); for (Field field : fields) { try { setFieldValue(testObject, field, getApplicationContext(testObject)); } catch (UnitilsException e) { throw new UnitilsException("Unable to assign the application context to field annotated with @" + SpringApplicationContext.class.getSimpleName(), e); } } // inject into setter methods annotated with @SpringApplicationContext Set<Method> methods = getMethodsAnnotatedWith(testObject.getClass(), SpringApplicationContext.class, false); for (Method method : methods) { // ignore custom create methods if (method.getReturnType() != Void.TYPE) { continue; } try { invokeMethod(testObject, method, getApplicationContext(testObject)); } catch (Exception e) { throw new UnitilsException("Unable to assign the application context to setter annotated with @" + SpringApplicationContext.class.getSimpleName(), e); } } }
From source file:se.unlogic.hierarchy.core.servlets.CoreServlet.java
@Override public void init(boolean throwExceptions) throws ServletException { try {//w w w . ja v a2 s . c o m // Store starttime long startTime = System.currentTimeMillis(); //Get application file system path this.applicationFileSystemPath = this.getServletContext().getRealPath("/"); // Search for config File configurationFile; String configPrefix = System.getenv("OpenHierarchy_configPrefix"); if (!StringUtils.isEmpty(configPrefix) && FileUtils .fileExists(this.applicationFileSystemPath + "WEB-INF/" + configPrefix + ".config.xml")) { configurationFile = new File( this.applicationFileSystemPath + "WEB-INF/" + configPrefix + ".config.xml"); } else { configurationFile = new File(this.applicationFileSystemPath + "WEB-INF/config.xml"); } // Check if config exists if (!configurationFile.exists()) { setSystemStatus(SystemStatus.CONFIG_NOT_FOUND); return; } else { setSystemStatus(SystemStatus.STARTING); // Store relative paths RelativePathHandler.setPath("webroot", this.applicationFileSystemPath + "WEB-INF" + File.separator); // Initialize logging if (!StringUtils.isEmpty(configPrefix) && FileUtils .fileExists(this.applicationFileSystemPath + "WEB-INF/" + configPrefix + ".log4j.xml")) { DOMConfigurator .configure(this.applicationFileSystemPath + "WEB-INF/" + configPrefix + ".log4j.xml"); } else { DOMConfigurator.configure(this.applicationFileSystemPath + "WEB-INF/log4j.xml"); } this.log = Logger.getLogger(CoreServlet.class); this.log.fatal("***** " + VERSION + " starting... *****"); // Parse configuration SettingNode config = new XMLParser(configurationFile); // Set system data source dataSourceType = DataSourceType.valueOf(config.getString("/Config/DataSource/Type")); if (dataSourceType == DataSourceType.SystemManaged) { SimpleDataSourceDescriptor dataSourceDescriptor = new SimpleDataSourceDescriptor(); dataSourceDescriptor.setUrl(config.getString("/Config/DataSource/Url")); dataSourceDescriptor.setDriver(config.getString("/Config/DataSource/Driver")); dataSourceDescriptor.setUsername(config.getString("/Config/DataSource/Username")); dataSourceDescriptor.setPassword(config.getString("/Config/DataSource/Password")); dataSourceDescriptor .setRemoveAbandoned(config.getPrimitiveBoolean("/Config/DataSource/RemoveAbandoned")); dataSourceDescriptor .setRemoveTimeout(config.getInteger("/Config/DataSource/RemoveAbandonedTimeout")); dataSourceDescriptor .setTestOnBorrow(config.getPrimitiveBoolean("/Config/DataSource/TestOnBorrow")); dataSourceDescriptor.setValidationQuery(config.getString("/Config/DataSource/ValidationQuery")); dataSourceDescriptor.setMaxActive(config.getInteger("/Config/DataSource/MaxActive")); dataSourceDescriptor.setMaxIdle(config.getInteger("/Config/DataSource/MaxIdle")); dataSourceDescriptor .setLogAbandoned(config.getPrimitiveBoolean("/Config/DataSource/LogAbandoned")); dataSourceDescriptor.setMinIdle(config.getInteger("/Config/DataSource/MinIdle")); dataSourceDescriptor.setMaxWait(config.getInteger("/Config/DataSource/MaxWait")); this.dataSource = DBCPUtils.createConnectionPool(dataSourceDescriptor); } else if (dataSourceType == DataSourceType.ContainerManaged) { this.dataSource = DBUtils.getDataSource(config.getString("/Config/DataSource/Url")); } else { throw new RuntimeException("Unknown datasource type " + dataSourceType + " in config.xml"); } this.encoding = config.getString("/Config/Encoding"); if (StringUtils.isEmpty(encoding)) { throw new RuntimeException("No encoding found in config.xml"); } String defaultLanguage = config.getString("/Config/DefaultLanguage"); if (StringUtils.isEmpty(defaultLanguage) || (this.defaultLanguage = EnumUtils.toEnum(Language.class, defaultLanguage)) == null) { throw new RuntimeException("No or invalid default language specified in config.xml"); } this.xsltCacheHandler = new CoreXSLTCacheHandler(config, this.defaultLanguage, getApplicationFileSystemPath()); this.userHandler = new UserHandler(); this.groupHandler = new GroupHandler(); String coreDAOFactoryClassString = config.getString("/Config/CoreDAOFactory"); if (StringUtils.isEmpty(coreDAOFactoryClassString)) { throw new RuntimeException("No core DAO factory class specified in config.xml"); } Class<?> coreDAOFactoryClass = Class.forName(coreDAOFactoryClassString); if (!CoreDaoFactory.class.isAssignableFrom(coreDAOFactoryClass)) { throw new RuntimeException( "The core DAO factory class specified in config.xml is not a valid. The specified class must extend se.unlogic.hierarchy.core.daos.factories.CoreDaoFactory."); } coreDaoFactory = (CoreDaoFactory) coreDAOFactoryClass.newInstance(); coreDaoFactory.init(dataSource); this.dataSourceCache = new DataSourceCache(coreDaoFactory); this.stopableEmailHandler = new StopableEmailHandler(); this.moduleXMLDebug = config.getPrimitiveBoolean("/Config/ModuleXMLDebug"); this.moduleXMLDebugFile = config.getString("/Config/ModuleXMLDebugFile"); this.systemXMLDebug = config.getPrimitiveBoolean("/Config/SystemXMLDebug"); this.systemXMLDebugFile = config.getString("/Config/SystemXMLDebugFile"); this.backgroundModuleXMLDebug = config.getPrimitiveBoolean("/Config/BackgroundModuleXMLDebug"); this.backgroundModuleXMLDebugFile = config.getString("/Config/BackgroundModuleXMLDebugFile"); this.globalSectionCacheListener = new GlobalSectionCacheListener(); this.globalForegroundModuleCacheListener = new GlobalForegroundModuleCacheListener(); this.globalBackgroundModuleCacheListener = new GlobalBackgroundModuleCacheListener(); this.sectionMap = new ConcurrentHashMap<Integer, Section>(); this.systemInstanceHandler = new SystemInstanceHandler(); this.eventHandler = new SystemEventHandler(); this.loginHandler = new LoginHandler(); this.startupListeners = new ArrayList<SystemStartupListener>(); Method addListenerMethod = ReflectionUtils.getMethod(ServletContext.class, "addListener", Void.TYPE, EventListener.class); if (addListenerMethod != null) { try { SystemSessionListenerHandler systemSessionListenerHandler = new SystemSessionListenerHandler(); addListenerMethod.invoke(this.getServletContext(), systemSessionListenerHandler); this.systemSessionListenerHandler = systemSessionListenerHandler; } catch (Exception e) { log.error("Error adding session listener handler to servlet context", e); } } //Cache filter modules this.filterModuleCache = new FilterModuleCache(this); try { filterModuleCache.cacheModules(false); } catch (Exception e) { log.error("Error caching filter modules", e); } // Get root sectionDescriptor SimpleSectionDescriptor simpleSectionDescriptor = coreDaoFactory.getSectionDAO() .getRootSection(false); // Instantiate root section rootSection = new Section(simpleSectionDescriptor, null, this); rootSection.cacheModuleAndSections(); setSystemStatus(SystemStatus.STARTED); triggerStartupListeners(); this.log.fatal(VERSION + " successfully started in " + TimeUtils.millisecondsToString(System.currentTimeMillis() - startTime) + " ms"); } } catch (Throwable e) { setSystemStatus(SystemStatus.FAIL_SAFE); if (this.log != null) { this.log.error(VERSION + " startup failed!", e); this.log.fatal(VERSION + " is in failsafe mode"); } else { System.out.println(VERSION + " startup failed!"); e.printStackTrace(); System.out.println(VERSION + " is in failsafe mode!"); } if (throwExceptions) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RuntimeException(e); } } } }
From source file:org.apache.hadoop.ipc.RPC.java
/** Expert: Make multiple, parallel calls to a set of servers. */ public static Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, UserGroupInformation ticket, 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 w w w. ja va 2 s. c o m Writable[] wrappedValues = client.call(invocations, addrs, method.getDeclaringClass(), ticket, conf); 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:org.evosuite.testcase.statements.FunctionalMockStatement.java
/** * Based on most recent test execution, update the mocking configuration. * After calling this method, it is <b>necessary</b> to provide the missing * VariableReferences, if any, using addMissingInputs. * * @return a ordered, non-null list of types of missing new inputs that will need to be provided * *///from w ww .j av a2 s .c o m public List<Type> updateMockedMethods() throws ConstructionFailedException { logger.debug("Executing updateMockedMethods. Parameter size: " + parameters.size()); List<Type> list = new ArrayList<>(); assert !super.parameters.contains(null); assert mockedMethods.size() == methodParameters.size(); List<VariableReference> copy = new ArrayList<>(super.parameters); assert copy.size() == super.parameters.size(); super.parameters.clear(); mockedMethods.clear(); //important to remove all the no longer used calls Map<String, int[]> mpCopy = new LinkedHashMap<>(); List<MethodDescriptor> executed = listener.getCopyOfMethodDescriptors(); int mdIndex = 0; for (MethodDescriptor md : executed) { mockedMethods.add(md); if (!md.shouldBeMocked() || md.getCounter() == 0) { //void method or not called, so no parameter needed for it mpCopy.put(md.getID(), null); continue; } int added = 0; logger.debug("Method called on mock object: " + md.getMethod()); //infer parameter mapping of current vars from previous execution, if any int[] minMax = methodParameters.get(md.getID()); int existingParameters; //total number of existing parameters if (minMax == null) { //before it was not called minMax = new int[] { -1, -1 }; existingParameters = 0; } else { assert minMax[1] >= minMax[0] && minMax[0] >= 0; assert minMax[1] < copy.size() : "Max=" + minMax[1] + " but n=" + copy.size(); existingParameters = 1 + (minMax[1] - minMax[0]); } assert existingParameters <= Properties.FUNCTIONAL_MOCKING_INPUT_LIMIT; //check if less calls if (existingParameters > md.getCounter()) { //now the method has been called less times, //so remove the last calls, ie decrease counter minMax[1] -= (existingParameters - md.getCounter()); } if (existingParameters > 0) { for (int i = minMax[0]; i <= minMax[1]; i++) { //align super class data structure super.parameters.add(copy.get(i)); added++; } } //check if rather more calls if (existingParameters < md.getCounter()) { for (int i = existingParameters; i < md.getCounter() && i < Properties.FUNCTIONAL_MOCKING_INPUT_LIMIT; i++) { // Create a copy as the typemap is stored in the class during generic instantiation // but we might want to have a different type for each call of the same method invocation GenericClass calleeClass = new GenericClass(retval.getGenericClass()); Type returnType = md.getGenericMethodFor(calleeClass).getGeneratedType(); assert !returnType.equals(Void.TYPE); logger.debug("Return type: " + returnType + " for retval " + retval.getGenericClass()); list.add(returnType); super.parameters.add(null); //important place holder for following updates added++; } } minMax[0] = mdIndex; minMax[1] = (mdIndex + added - 1); //max is inclusive assert minMax[1] >= minMax[0] && minMax[0] >= 0; //max >= min assert super.parameters.size() == minMax[1] + 1; mpCopy.put(md.getID(), minMax); mdIndex += added; } methodParameters.clear(); methodParameters.putAll(mpCopy); for (MethodDescriptor md : mockedMethods) { if (!methodParameters.containsKey(md.getID())) { methodParameters.put(md.getID(), null); } } return list; }
From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java
@Test public void methodWithNonRequiredCookieValue() { ControllerUtil.sendAndReceive(mockMvc, null, Collections.singletonList(new Cookie("stringCookie", "aString")), "remoteProviderSimple", "method30", "aString", (Object[]) null); ControllerUtil.sendAndReceive(mockMvc, null, null, "remoteProviderSimple", "method30", Void.TYPE, (Object[]) null);//from w w w . j a v a 2s . c om }
From source file:org.springframework.aop.framework.CglibAopProxy.java
/** * Process a return value. Wraps a return of {@code this} if necessary to be the * {@code proxy} and also verifies that {@code null} is not returned as a primitive. *//*from w w w. jav a 2s. c o m*/ @Nullable private static Object processReturnType(Object proxy, @Nullable Object target, Method method, @Nullable Object returnValue) { // Massage return value if necessary if (returnValue != null && returnValue == target && !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) { // Special case: it returned "this". Note that we can't help // if the target sets a reference to itself in another returned object. returnValue = proxy; } Class<?> returnType = method.getReturnType(); if (returnValue == null && returnType != Void.TYPE && returnType.isPrimitive()) { throw new AopInvocationException( "Null return value from advice does not match primitive return type for: " + method); } return returnValue; }
From source file:de.codesourcery.springmass.springmass.SimulationParamsBuilder.java
private boolean isParameterSetter(Method m) { return isPartOfPublicInterface(m) && m.getParameterTypes() != null && m.getParameterTypes().length == 1 && m.getName().startsWith("set") && m.getReturnType() == Void.TYPE; }
From source file:org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.java
@Override public CompiledChain compileChain(Class<?> inputType, OperationParameters... operations) throws OperationException { return CompiledChainImpl.buildChain(this, inputType == null ? Void.TYPE : inputType, operations); }