List of usage examples for java.lang Class getMethods
@CallerSensitive public Method[] getMethods() throws SecurityException
From source file:com.bstek.dorado.data.method.MethodAutoMatchingUtils.java
/** * ????/*from www.j av a2 s. c om*/ * * @param cl * * @param methodName * ?? * @return */ public static Method[] getMethodsByName(Class<?> cl, String methodName) { cl = ProxyBeanUtils.getProxyTargetType(cl); Object cacheKey = getCacheKey(cl, methodName); Method[] methods = methodCache.get(cacheKey); if (methods == null) { List<Method> methodList = new ArrayList<Method>(); Method[] allMethods = cl.getMethods(); for (Method method : allMethods) { if (method.getName().equals(methodName)) { methodList.add(method); } } methods = new Method[methodList.size()]; methodList.toArray(methods); methodCache.put(cacheKey, methods); } return methods; }
From source file:mitm.common.hibernate.AutoCommitProxyFactory.java
private void searchForStartTransactionAnnotations(Class<T> clazz) { Method[] methods = clazz.getMethods(); for (Method method : methods) { if (method.isAnnotationPresent(StartTransaction.class)) { addMethod(method);/*from w w w . j av a2 s .com*/ } } }
From source file:de.contentreich.instrumentation.SpringBeansHelper.java
public List<String[]> getPublicMethodSignatures(String className) { logger.debug("Get public method signatures for class " + className); ArrayList<String[]> methodSignatures = new ArrayList<String[]>(); try {/*from w ww .ja v a 2 s .c o m*/ Class clazz = Class.forName(className); List<Method> methods = (List<Method>) Arrays.asList(clazz.getMethods()); // Filtering - a pita in java for (Iterator<Method> iterator = methods.iterator(); iterator.hasNext();) { Method method = iterator.next(); if (!method.getDeclaringClass().getName().startsWith("java") && Modifier.isPublic(method.getModifiers())) { methodSignatures.add(new String[] { method.toString(), method.getDeclaringClass().getName() }); } } Collections.sort(methodSignatures, new Comparator() { @Override public int compare(Object o1, Object o2) { String s1 = ((String[]) o1)[0]; String s2 = ((String[]) o2)[0]; return s1.compareTo(s2); } }); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } return methodSignatures; }
From source file:org.geoserver.wps.jts.SpringBeanProcessFactory.java
@Override protected Method method(String className) { Class c = classMap.get(className); Method lastExecute = null;//from www. ja v a2s . c o m if (c != null) { for (Method m : c.getMethods()) { if (m.getName().equals("execute")) { if (lastExecute != null) { lastExecute = m; } // if annotated return immediately, otherwise keep it aside if (m.getAnnotation(DescribeResult.class) != null || m.getAnnotation(DescribeResults.class) != null) { return m; } } } } return lastExecute; }
From source file:com.metaparadigm.jsonrpc.JSONRPCBridge.java
private static ClassData analyzeClass(Class clazz) { log.info("analyzing " + clazz.getName()); Method methods[] = clazz.getMethods(); ClassData cd = new ClassData(); cd.clazz = clazz;//from w w w.j a v a 2 s.com // Create temporary method map HashMap staticMethodMap = new HashMap(); HashMap methodMap = new HashMap(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method.getDeclaringClass() == Object.class) continue; int mod = methods[i].getModifiers(); if (!Modifier.isPublic(mod)) continue; Class param[] = method.getParameterTypes(); // don't count locally resolved args int argCount = 0; synchronized (localArgResolverMap) { for (int n = 0; n < param.length; n++) { HashSet resolvers = (HashSet) localArgResolverMap.get(param[n]); if (resolvers != null) continue; argCount++; } } MethodKey mk = new MethodKey(method.getName(), argCount); ArrayList marr = (ArrayList) methodMap.get(mk); if (marr == null) { marr = new ArrayList(); methodMap.put(mk, marr); } marr.add(method); if (Modifier.isStatic(mod)) { marr = (ArrayList) staticMethodMap.get(mk); if (marr == null) { marr = new ArrayList(); staticMethodMap.put(mk, marr); } marr.add(method); } } cd.methodMap = new HashMap(); cd.staticMethodMap = new HashMap(); // Convert ArrayLists to arrays Iterator i = methodMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); MethodKey mk = (MethodKey) entry.getKey(); ArrayList marr = (ArrayList) entry.getValue(); if (marr.size() == 1) { cd.methodMap.put(mk, marr.get(0)); } else { cd.methodMap.put(mk, marr.toArray(new Method[0])); } } i = staticMethodMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); MethodKey mk = (MethodKey) entry.getKey(); ArrayList marr = (ArrayList) entry.getValue(); if (marr.size() == 1) { cd.staticMethodMap.put(mk, marr.get(0)); } else { cd.staticMethodMap.put(mk, marr.toArray(new Method[0])); } } return cd; }
From source file:edu.northwestern.bioinformatics.studycalendar.core.StudyCalendarTestCase.java
@SuppressWarnings({ "RawUseOfParameterizedType" }) protected <T extends StudyCalendarDao> T registerDaoMockFor(Class<T> forClass) { List<Method> methods = new LinkedList<Method>(Arrays.asList(forClass.getMethods())); for (Iterator<Method> iterator = methods.iterator(); iterator.hasNext();) { Method method = iterator.next(); if ("domainClass".equals(method.getName())) { iterator.remove();//w w w. j a v a 2 s . co m } } return registerMockFor(forClass, methods.toArray(new Method[methods.size()])); }
From source file:com.urbancode.x2o.xml.XmlWrite.java
public List<Method> findMethodsForClass(String methodPrefix, Class clazz) throws ClassNotFoundException { List<Method> result = new ArrayList<Method>(); for (Method method : clazz.getMethods()) { if (method.getName().startsWith(methodPrefix)) { if (!(method.getName().equals("getClass") || Modifier.isProtected(method.getModifiers()))) { result.add(method);/*from ww w. jav a 2 s. c o m*/ } } } return result; }
From source file:info.sargis.eventbus.config.EventBusHandlerBeanDefinitionParser.java
private boolean isEventBusHandlerCandidate(BeanDefinition component, ParserContext parserContext) { try {/*from w ww .ja v a 2s . c o m*/ String beanClassName = component.getBeanClassName(); Class<?> beanClass = Class.forName(beanClassName); for (Method method : beanClass.getMethods()) { Subscribe annotation = method.getAnnotation(Subscribe.class); if (annotation != null) { return true; } } } catch (ClassNotFoundException e) { logger.error("", e); } return false; }
From source file:com.jredrain.dao.BeanResultTransFormer.java
/** * /*from ww w . ja v a2 s . co m*/ * * @param beanClass */ protected void register(Class beanClass) { Method[] methods = beanClass.getMethods(); //?setter??? for (Method method : methods) { if (filter(method)) { String name = method.getName().toLowerCase().substring(3); if (!setters.containsKey(name)) { setters.put(name, new ArrayList<Setter>()); } //???,?? setters.get(name).add(new Setter(method)); } } }
From source file:com.feedzai.fos.server.remote.impl.RemoteInterfacesTest.java
private void testMatch(Class<?> api, Class<?> remote, int remoteFieldAdditions) { Method[] apiMethods = api.getMethods(); Method[] remoteMethods = remote.getMethods(); Arrays.sort(apiMethods, buildComparator()); Arrays.sort(remoteMethods, buildComparator()); // Checks if @RemoteInterface is different from the class/interface itself. assertNotSame(/*from w w w . ja v a 2 s . c o m*/ String.format("@RemoteInterface cannot be the same for the class name in %s", api.getSimpleName()), api, remote); // Checks if the remote implementation can be assigned to Remote (i.e. if in the hierarchy extends/implements Remote). assertTrue( String.format("'%s' does not implement '%s'", remote.getSimpleName(), Remote.class.getSimpleName()), Remote.class.isAssignableFrom(remote)); assertEquals(desc(api, null, "Number of methods matches"), apiMethods.length, remoteMethods.length); for (int i = 0; i < apiMethods.length; i++) { // Check if the names match Method expected = apiMethods[i]; Method actual = remoteMethods[i]; assertEquals(desc(api, actual, "Names match"), expected.getName(), actual.getName()); assertTrue(desc(api, actual, "Number of arguments matches"), expected.getParameterTypes().length - actual.getParameterAnnotations().length <= remoteFieldAdditions); boolean remoteOrException = false; for (Class klass : actual.getExceptionTypes()) { remoteOrException = Exception.class.equals(klass) || RemoteException.class.equals(klass); if (remoteOrException) { break; } } // Checks if remote implementations throw Exception or RemoteException. assertTrue(desc(remote, actual, String.format("%s does not throw either RemoteException or Exception", actual.getName())), remoteOrException); } }