List of usage examples for java.lang.reflect Method getParameterTypes
@Override
public Class<?>[] getParameterTypes()
From source file:com.sourceallies.beanoh.spring.wrapper.BeanohBeanFactoryMethodInterceptor.java
/** * Intercepts method calls to the proxy and calls the corresponding method * on the delegate.//w ww.j a v a2 s . c o m * * Collects bean definitions that are registered for later inspection. */ @Override public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Method delegateMethod = delegateClass.getMethod(method.getName(), method.getParameterTypes()); if ("registerBeanDefinition".equals(method.getName())) { if (beanDefinitionMap.containsKey(args[0])) { List<BeanDefinition> definitions = beanDefinitionMap.get(args[0]); definitions.add((BeanDefinition) args[1]); } else { List<BeanDefinition> beanDefinitions = new ArrayList<BeanDefinition>(); beanDefinitions.add((BeanDefinition) args[1]); beanDefinitionMap.put((String) args[0], beanDefinitions); } } return delegateMethod.invoke(delegate, args); }
From source file:com.laxser.blitz.web.paramresolver.ParameterNameDiscovererImpl.java
public String[] getParameterNames(Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); String[] names = new String[parameterTypes.length]; Map<String, Integer> counts = new HashMap<String, Integer>(); for (int i = 0; i < names.length; i++) { Annotation[] annotations = parameterAnnotations[i]; for (Annotation annotation : annotations) { String name = null;/*from w w w . jav a2 s . c om*/ if (annotation instanceof Param) { name = ((Param) annotation).value(); } else if (annotation instanceof FlashParam) { name = ((FlashParam) annotation).value(); } if (name != null) { if (StringUtils.isNotEmpty(name)) { names[i] = name; if ((parameterTypes[i] == BindingResult.class || parameterTypes[i] == Errors.class) && !name.endsWith("BindingResult")) { names[i] = name + "BindingResult"; } } break; } } if (names[i] != null) { continue; } if (parameterTypes[i] == BindingResult.class || parameterTypes[i] == Errors.class) { if (i > 0 && names[i - 1] != null) { names[i] = names[i - 1] + "BindingResult"; continue; } } String rawName = getParameterRawName(parameterTypes[i]); if (rawName == null) { continue; } names[i] = rawName; Integer count = counts.get(rawName); if (count == null) { counts.put(rawName, 1); } else { counts.put(rawName, count + 1); if (count == 1) { for (int j = 0; j < i; j++) { if (names[j] != null && names[j].equals(rawName)) { names[j] = rawName + "1"; break; } } } if (names[i] == rawName) { names[i] = names[i] + (count + 1); } } } Set<String> uniques = new HashSet<String>(); for (String name : names) { if (name == null) { continue; } if (uniques.contains(name)) { // action????@Param? throw new IllegalArgumentException("params with same name: '" + name + "'"); } uniques.add(name); } return names; }
From source file:com.fluidops.iwb.api.CommunicationServiceImpl.java
/** * lookup getter method for a given property * @param ifc the ontology class/*from w ww. j a v a2s . c o m*/ * @param prop the prop / method name * @return the method getting the prop name * @throws NoSuchMethodException */ public static Method getGetter(Class<?> ifc, String prop) throws NoSuchMethodException { for (Method method : ifc.getMethods()) if (method.getParameterTypes().length == 0) { if (method.getName().equals(StringUtil.beanifyField(prop, "get"))) return method; if (method.getName().equals(StringUtil.beanifyField(prop, "is"))) return method; if (method.getName().equals(prop)) return method; OWLProperty p = AnnotationProcessor.getOWLProperty(ifc, method); if (p != null) { if (p.propName().equals(prop)) return method; if (EndpointImpl.api().getNamespaceService().guessURIOrCreateInDefaultNS(p.propName()) .equals(EndpointImpl.api().getNamespaceService().guessURIOrCreateInDefaultNS(prop))) return method; } } return null; }
From source file:org.traccar.web.CsvBuilder.java
public void addHeaderLine(Object object) { SortedSet<Method> methods = getSortedMethods(object); for (Method method : methods) { if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) { String name = Introspector.decapitalize(method.getName().substring(3)); if (!name.equals("class")) { builder.append(name);/*w w w . ja v a 2 s .c o m*/ addSeparator(); } } } addLineEnding(); }
From source file:com.fusesource.forge.jmstest.executor.AbstractBenchmarkExecutor.java
protected Method getSetterByName(String propName) { log().debug("Trying to find setter method for: " + propName); String methodName = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1); for (Method m : this.getClass().getMethods()) { if (m.getName().equals(methodName)) { if (m.getParameterTypes().length == 1) { return m; }/*from w ww . ja v a 2s . c o m*/ } } return null; }
From source file:it.unibo.alchemist.language.protelis.util.ProtelisLoader.java
private static MethodCall parseMethod(final JvmOperation jvmOp, final List<Expression> args, final Map<FasterString, FunctionDefinition> nameToFun, final Map<FunctionDef, FunctionDefinition> funToFun, final AtomicInteger id) { final boolean ztatic = jvmOp.isStatic(); final List<AnnotatedTree<?>> arguments = parseArgs(args, nameToFun, funToFun, id); final String classname = jvmOp.getDeclaringType().getQualifiedName(); try {/*from w w w. j a v a2 s .com*/ final Class<?> clazz = Class.forName(classname); /* * TODO: Check for return type and params: if param is Field and * return type is not then L.warn() */ List<Method> tempList = new ArrayList<>(); for (Method m : clazz.getMethods()) { if (ztatic) { if (Modifier.isStatic(m.getModifiers())) { tempList.add(m); } } } /* * Same number of arguments */ final int parameterCount = jvmOp.getParameters().size(); List<Method> tempList2 = new ArrayList<>(); for (Method m : tempList) { // TODO: Workaround for different Method API if (m.getParameterTypes().length == parameterCount) { tempList2.add(m); } } /* * Same name */ final String methodName = jvmOp.getSimpleName(); List<Method> res = new ArrayList<>(); for (Method m : tempList2) { if (m.getName().equals(methodName)) { res.add(m); } } /* * There should be only one left - otherwise we have overloading, * and to properly deal with that we need type checking. The * following collection operation is for debug and warning purposes, * and should be removed as soon as we have a proper way to deal * with overloading in place. TODO */ if (res.size() > 1) { final StringBuilder sb = new StringBuilder(64); sb.append("Method "); sb.append(jvmOp.getQualifiedName()); sb.append('/'); sb.append(parameterCount); sb.append(" is overloaded by:\n"); for (Method m : res) { sb.append(m.toString()); sb.append('\n'); // NOPMD } sb.append("Protelis can not (yet) properly deal with that."); L.warn(sb.toString()); } if (res.isEmpty()) { throw new IllegalStateException("Can not bind any method that satisfies the name " + jvmOp.getQualifiedName() + "/" + parameterCount + "."); } return new MethodCall(res.get(0), arguments, ztatic); } catch (ClassNotFoundException e) { throw new IllegalStateException("Class " + classname + " could not be found in classpath."); } catch (SecurityException e) { throw new IllegalStateException( "Class " + classname + " could not be loaded due to security permissions."); } catch (Error e) { throw new IllegalStateException("An error occured while loading class " + classname + "."); } }
From source file:com.autentia.tnt.tracking.annotation.ChangesHistoryAspect.java
/** * returns an array with the classes of the arguments of the setter method * @param call/*from w ww . ja va 2s .c o m*/ * @return */ private Class[] getSetterArgsClass(JoinPoint call) { Method metodo = getCallMethod(call); Class[] params = metodo.getParameterTypes(); return params; }
From source file:com.googlecode.android_scripting.rpc.MethodDescriptorTest.java
private void assertDefaultThrows(Method m, int param) { try {// www .j av a2 s . com MethodDescriptor.getDefaultValue(m.getParameterTypes()[param], m.getParameterAnnotations()[param]); } catch (Exception expected) { } }
From source file:com.swtxml.util.reflector.MethodQuery.java
public MethodQuery optionalParameter(final Class<?> type) { Assert.isNotNull(type, "type"); filters.add(new IFilter<Method>() { public boolean match(Method method) { return method.getParameterTypes().length == 0 || (method.getParameterTypes().length == 1 && type == method.getParameterTypes()[0]); }/*from ww w . j a va 2 s . co m*/ @Override public String toString() { return "optional parameter \"" + type.getSimpleName() + "\""; } }); return this; }
From source file:org.atteo.moonshine.websocket.jsonmessages.HandlerDispatcher.java
private void registerOnMessageMethod(Method method, Provider<?> provider) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1) { throw new RuntimeException("Method marked with @" + OnMessage.class.getSimpleName() + " must have exactly one argument whose super class is " + JsonMessage.class.getSimpleName()); }//from w ww . j av a 2 s . c o m Class<?> parameterType = parameterTypes[0]; if (!JsonMessage.class.isAssignableFrom(parameterType)) { throw new RuntimeException("Method marked with @" + OnMessage.class.getSimpleName() + " must have exactly one argument whose super class is " + JsonMessage.class.getSimpleName()); } decoderObjectMapper.registerSubtypes(parameterType); Class<?> returnType = method.getReturnType(); if (returnType != Void.TYPE) { encoderObjectMapper.registerSubtypes(returnType); } onMessageMethods.add(new OnMessageMethodMetadata(parameterType, provider, method)); }