List of usage examples for java.lang.reflect Method getParameterTypes
@Override
public Class<?>[] getParameterTypes()
From source file:kilim.Task.java
private static Method getWovenMethod(Method m) { Class<?>[] ptypes = m.getParameterTypes(); if (!(ptypes.length > 0 && ptypes[ptypes.length - 1].getName().equals("kilim.Fiber"))) { // The last param is not "Fiber", so m is not woven. // Get the woven method corresponding to m(..., Fiber) boolean found = false; LOOP: for (Method wm : m.getDeclaringClass().getDeclaredMethods()) { if (wm != m && wm.getName().equals(m.getName())) { // names match. Check if the wm has the exact parameter types as m, plus a fiber. Class<?>[] wptypes = wm.getParameterTypes(); if (wptypes.length != ptypes.length + 1 || !(wptypes[wptypes.length - 1].getName().equals("kilim.Fiber"))) continue LOOP; for (int i = 0; i < ptypes.length; i++) { if (ptypes[i] != wptypes[i]) continue LOOP; }/* w ww . j a v a 2 s .co m*/ m = wm; found = true; break; } } if (!found) { throw new IllegalArgumentException( "Found no pausable method corresponding to supplied method: " + m); } } return m; }
From source file:com.github.dozermapper.core.util.ReflectionUtils.java
private static boolean isNonVoidSetter(Method method, String setterMethodName) { return method.getName().equals(setterMethodName) && method.getParameterTypes().length == 1 && method.getReturnType() != Void.TYPE; }
From source file:com.revolsys.record.io.format.xml.XmlProcessor.java
/** * Create the cache of process methods from the specified class. * * @param processorClass The XmlPorcessor class. * @return The map of method names to process methods. *//*from w w w . ja v a 2 s. c om*/ private static Map<String, Method> getMethodCache(final Class<?> processorClass) { Map<String, Method> methodCache = PROCESSOR_METHOD_CACHE.get(processorClass); if (methodCache == null) { methodCache = new HashMap<>(); PROCESSOR_METHOD_CACHE.put(processorClass, methodCache); final Method[] methods = processorClass.getMethods(); for (final Method method : methods) { final String methodName = method.getName(); if (methodName.startsWith("process")) { if (Arrays.equals(method.getParameterTypes(), PROCESS_METHOD_ARGS)) { final String name = methodName.substring(7); methodCache.put(name, method); } } } } return methodCache; }
From source file:ReflectionTest.java
/** * Prints all methods of a class/*from w w w .ja va 2s. c o m*/ * @param cl a class */ public static void printMethods(Class cl) { Method[] methods = cl.getDeclaredMethods(); for (Method m : methods) { Class retType = m.getReturnType(); String name = m.getName(); System.out.print(" "); // print modifiers, return type and method name String modifiers = Modifier.toString(m.getModifiers()); if (modifiers.length() > 0) System.out.print(modifiers + " "); System.out.print(retType.getName() + " " + name + "("); // print parameter types Class[] paramTypes = m.getParameterTypes(); for (int j = 0; j < paramTypes.length; j++) { if (j > 0) System.out.print(", "); System.out.print(paramTypes[j].getName()); } System.out.println(");"); } }
From source file:io.dyn.core.handler.Handlers.java
public static <A extends Annotation> A find(Class<A> anno, Method method) { if (null == method) { return null; }//from w w w .j av a 2 s .c om A on = AnnotationUtils.findAnnotation(method, anno); if (null != on) { return on; } Class<?>[] implClasses = method.getDeclaringClass().getInterfaces(); for (Class<?> cl : implClasses) { try { Method m = cl.getDeclaredMethod(method.getName(), method.getParameterTypes()); if (null != m) { on = find(anno, m); if (null != on) { return on; } } } catch (NoSuchMethodException e) { } } return null; }
From source file:com.github.dozermapper.core.util.ReflectionUtils.java
private static boolean isAutoboxingSetter(Method method, String setterMethodName, Field field) { return method.getName().equals(setterMethodName) && method.getParameterTypes().length == 1 && canBeAutoboxed(method.getParameterTypes()[0], field.getType()); }
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); }/*from w ww .j av a 2 s .co m*/ } if (suite.countTestCases() == 0) { suite.addTest(TestSuite.warning(testcase.getName() + " has no public test methods")); } return suite; }
From source file:com.zenesis.qx.remote.ProxyTypeImpl.java
protected static boolean hasSameSignature(Method method, Method existing) { Class[] epts = existing.getParameterTypes(); Class[] mpts = method.getParameterTypes(); if (epts.length == mpts.length) { for (int i = 0; i < epts.length; i++) if (epts[i] != mpts[i]) return false; return true; }/*from w ww . ja va2 s. co m*/ return false; }
From source file:org.fusesource.meshkeeper.util.internal.IntrospectionSupport.java
public static boolean setProperty(Object target, String name, Object value) { try {/*from w w w. j a v a 2 s . co m*/ Class<?> clazz = target.getClass(); Method setter = findSetterMethod(clazz, name); if (setter == null) { return false; } // If the type is null or it matches the needed type, just use the // value directly if (value == null || value.getClass() == setter.getParameterTypes()[0]) { setter.invoke(target, new Object[] { value }); } else { // We need to convert it setter.invoke(target, new Object[] { convert(value, setter.getParameterTypes()[0]) }); } return true; } catch (Throwable ignore) { return false; } }
From source file:com.bstek.dorado.core.el.DefaultExpressionHandler.java
protected synchronized static Object createDoradoExpressionUtilsBean(Map<String, Method> utilMethods) throws Exception { if (doradoExpressionUtilsBean == null) { ClassPool pool = ClassPool.getDefault(); CtClass ctClass = null;//www . ja v a 2 s . co m try { ctClass = pool.get(DORADO_EXPRESSION_UTILS_TYPE); } catch (Exception e) { // do nothing } if (ctClass == null) { ctClass = pool.makeClass(DORADO_EXPRESSION_UTILS_TYPE); } for (Map.Entry<String, Method> entry : utilMethods.entrySet()) { String name = entry.getKey(); Method method = entry.getValue(); int methodIndex = ArrayUtils.indexOf(method.getDeclaringClass().getMethods(), method); StringBuffer buf = new StringBuffer(); StringBuffer args = new StringBuffer(); buf.append("public ").append("Object").append(' ').append(name).append('('); Class<?>[] parameterTypes = method.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { if (i > 0) { buf.append(','); args.append(','); } buf.append("Object").append(' ').append("p" + i); args.append("p" + i); } buf.append(")"); if (method.getExceptionTypes().length > 0) { buf.append(" throws "); int i = 0; for (Class<?> exceptionType : method.getExceptionTypes()) { if (i > 0) buf.append(','); buf.append(exceptionType.getName()); i++; } } buf.append("{\n").append("return Class.forName(\"" + method.getDeclaringClass().getName()) .append("\").getMethods()[").append(methodIndex).append("].invoke(null, new Object[]{") .append(args).append("});").append("\n}"); CtMethod delegator = CtNewMethod.make(buf.toString(), ctClass); delegator.setName(name); ctClass.addMethod(delegator); } Class<?> cl = ctClass.toClass(); doradoExpressionUtilsBean = cl.newInstance(); } return doradoExpressionUtilsBean; }