List of usage examples for java.lang.reflect Method getParameterTypes
@Override
public Class<?>[] getParameterTypes()
From source file:org.atteo.moonshine.websocket.jsonmessages.HandlerDispatcher.java
private void registerSenderMethod(Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1) { throw new RuntimeException("Sender method" + " must have exactly one argument whose super class is " + JsonMessage.class.getSimpleName()); }/*from w w w .j av a 2 s .co m*/ Class<?> parameterType = parameterTypes[0]; if (!JsonMessage.class.isAssignableFrom(parameterType)) { throw new RuntimeException("Sender method" + " must have exactly one argument whose super class is " + JsonMessage.class.getSimpleName()); } encoderObjectMapper.registerSubtypes(parameterType); Class<?> returnType = method.getReturnType(); if (returnType != Void.TYPE) { throw new RuntimeException("Sender method must have " + Void.class.getSimpleName() + " return type"); } }
From source file:org.zkoss.zkgrails.GrailsComposer.java
/** * <p>Overrides GenericEventListener to use InvokerHelper to call methods. Because of this the events are now * part of groovy's dynamic methods, e.g. metaClass.invokeMethod works for event methods. Without this the default java code * don't call the overriden invokeMethod</p> * * @param evt/*from w w w. ja va 2 s .c om*/ * @throws Exception */ @Override public void onEvent(Event evt) throws Exception { final Object controller = getController(); final Method mtd = ComponentsCtrl.getEventMethod(controller.getClass(), evt.getName()); if (mtd != null) { if (mtd.getParameterTypes().length == 0) { InvokerHelper.invokeMethod(controller, mtd.getName(), null); } else if (evt instanceof ForwardEvent) { //ForwardEvent final Class paramcls = (Class) mtd.getParameterTypes()[0]; //paramcls is ForwardEvent || Event if (ForwardEvent.class.isAssignableFrom(paramcls) || Event.class.equals(paramcls)) { InvokerHelper.invokeMethod(controller, mtd.getName(), new Object[] { evt }); } else { do { evt = ((ForwardEvent) evt).getOrigin(); } while (evt instanceof ForwardEvent); InvokerHelper.invokeMethod(controller, mtd.getName(), new Object[] { evt }); } } else { InvokerHelper.invokeMethod(controller, mtd.getName(), new Object[] { evt }); } } }
From source file:com.sinosoft.one.data.jade.statement.JdbcStatement.java
public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters, Querier querier) {/* w w w. j a va2 s. c o m*/ this.metaData = statementMetaData; this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters; this.querier = querier; this.sqlType = sqlType; if (sqlType == SQLType.WRITE) { Method method = statementMetaData.getMethod(); Class<?>[] types = method.getParameterTypes(); Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } if (types.length > 0 && List.class.isAssignableFrom(types[0])) { this.batchUpdate = true; if (returnType != void.class && returnType != int[].class && returnType != Integer[].class && returnType != Integer.class) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } else { this.batchUpdate = false; if (returnType != void.class && returnType != Boolean.class && !Number.class.isAssignableFrom(returnType)) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } } else { this.batchUpdate = false; } }
From source file:net.paoding.rose.jade.statement.JdbcStatement.java
public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters, Querier querier) {// ww w . j a v a 2 s. c o m this.metaData = statementMetaData; this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters; this.querier = querier; this.sqlType = sqlType; if (sqlType == SQLType.WRITE) { Method method = statementMetaData.getMethod(); Class<?>[] types = method.getParameterTypes(); Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } if (types.length > 0 && List.class.isAssignableFrom(types[0])) { this.batchUpdate = true; if (returnType != void.class && returnType != int[].class && returnType != Integer[].class && returnType != Integer.class) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } else { this.batchUpdate = false; if (Number.class.isAssignableFrom(returnType)) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } } else { this.batchUpdate = false; } }
From source file:hsa.awp.common.util.StaticInitializerBeanFactoryPostProcessor.java
/** * Finds the parameter types from the first argument of the given method. * * @param setter the method to find out the parameter types * @return the parameter type of the first argument */// w w w . j ava 2 s .c o m private Class<?> getPropertyType(Method setter) { Class<?>[] params = setter.getParameterTypes(); if (params.length != 1) { throw new StaticInitializerBeansException("bad write method arg count: " + setter); } return params[0]; }
From source file:org.vaadin.spring.i18n.Translator.java
private void analyzeMethods(Class<?> clazz) { for (Method m : clazz.getDeclaredMethods()) { if (m.getParameterTypes().length == 0 && m.getReturnType() != Void.TYPE) { if (m.isAnnotationPresent(TranslatedProperty.class)) { translatedMethods.put(m.getAnnotation(TranslatedProperty.class), m); } else if (m.isAnnotationPresent(TranslatedProperties.class)) { for (TranslatedProperty annotation : m.getAnnotation(TranslatedProperties.class).value()) { translatedMethods.put(annotation, m); }/*from w w w. j a v a 2 s . c o m*/ } } } }
From source file:com.ankang.report.pool.AbstractReportAliasPool.java
private void mountPrams(LinkedHashMap<String, Class<?>> paramsType, Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); Annotation[][] annotations = method.getParameterAnnotations(); for (int i = 0; i < parameterTypes.length; i++) { if (annotations.length < i) { throw new ReportException( "Please add an effective note for the argument, such as: HTTPParam, RequestParam"); }/*from ww w . j av a2 s. c om*/ if ((ReportRequest.class.isAssignableFrom(parameterTypes[i])) || (!parameterTypes[i].isPrimitive() && !parameterTypes[i].toString().matches("^.+java\\..+$") && parameterTypes[i].toString().matches("^class.+$"))) { Field[] fields = parameterTypes[i].getDeclaredFields(); for (Field field : fields) { if (!Modifier.isFinal(field.getModifiers()) || !Modifier.isStatic(field.getModifiers())) { paramsType.put(field.getName(), field.getType()); } } } else { if (annotations.length >= i && annotations[i].length > 0) { paramsType.put(matchPrams(annotations[i][0]), parameterTypes[i]); } } } }
From source file:com.openteach.diamond.provider.impl.DefaultServiceProvider.java
/** * // w w w.j ava 2 s . co m * @param method * @return */ private String getKey(Method method) { Class[] cs = method.getParameterTypes(); String[] names = new String[cs.length + 1]; names[0] = method.getName(); for (int i = 0; i < cs.length; i++) { names[i + 1] = cs[i].getName(); } return StringUtils.join(names, "-"); }
From source file:com.springframework.core.annotation.AnnotationUtils.java
private static <A extends Annotation> A searchOnInterfaces(Method method, Class<A> annotationType, Class<?>... ifcs) { A annotation = null;/*from w w w . j a v a 2s . c om*/ for (Class<?> iface : ifcs) { if (isInterfaceWithAnnotatedMethods(iface)) { try { Method equivalentMethod = iface.getMethod(method.getName(), method.getParameterTypes()); annotation = getAnnotation(equivalentMethod, annotationType); } catch (NoSuchMethodException ex) { // Skip this interface - it doesn't have the method... } if (annotation != null) { break; } } } return annotation; }
From source file:io.stallion.reflection.PropertyUtils.java
/** * Build a map of direct javabeans properties of the target object. Only read/write properties (ie: those who have * both a getter and a setter) are returned. * @param target the target object from which to get properties names. * @return a Map of String with properties names as key and their values * @throws PropertyException if an error happened while trying to get a property. *///from ww w.ja va2s. c o m public static Map<String, Object> getProperties(Object target, Class<? extends Annotation>... excludeAnnotations) throws PropertyException { Map<String, Object> properties = new HashMap<String, Object>(); Class clazz = target.getClass(); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; String name = method.getName(); Boolean hasExcludeAnno = false; if (excludeAnnotations.length > 0) { for (Class<? extends Annotation> anno : excludeAnnotations) { if (method.isAnnotationPresent(anno)) { hasExcludeAnno = true; } } } if (hasExcludeAnno) { continue; } if (method.getModifiers() == Modifier.PUBLIC && method.getParameterTypes().length == 0 && (name.startsWith("get") || name.startsWith("is")) && containsSetterForGetter(clazz, method)) { String propertyName; if (name.startsWith("get")) propertyName = Character.toLowerCase(name.charAt(3)) + name.substring(4); else if (name.startsWith("is")) propertyName = Character.toLowerCase(name.charAt(2)) + name.substring(3); else throw new PropertyException( "method '" + name + "' is not a getter, thereof no setter can be found"); try { Object propertyValue = method.invoke(target, (Object[]) null); // casting to (Object[]) b/c of javac 1.5 warning if (propertyValue != null && propertyValue instanceof Properties) { Map propertiesContent = getNestedProperties(propertyName, (Properties) propertyValue); properties.putAll(propertiesContent); } else { properties.put(propertyName, propertyValue); } } catch (IllegalAccessException ex) { throw new PropertyException("cannot set property '" + propertyName + "' - '" + name + "' is null and cannot be auto-filled", ex); } catch (InvocationTargetException ex) { throw new PropertyException("cannot set property '" + propertyName + "' - '" + name + "' is null and cannot be auto-filled", ex); } } // if } // for return properties; }