List of usage examples for java.lang.reflect Method getName
@Override
public String getName()
From source file:Main.java
public static Method getMethod(Object o, String methodName, Class<?> returnType, Class<?>... parameters) { for (Method method : o.getClass().getDeclaredMethods()) { if (!method.getName().equals(methodName) || method.getReturnType() != returnType) continue; Class<?>[] pars = method.getParameterTypes(); if (parameters.length != pars.length) continue; boolean found = true; for (int i = 0; i < parameters.length; i++) { if (pars[i] != parameters[i]) { found = false;/*from www. j a v a2 s . co m*/ break; } } if (found) { return method; } } return null; }
From source file:Main.java
public static Method getMethod(Object o, String methodName, String returnType, Class<?>... parameters) { for (Method method : o.getClass().getDeclaredMethods()) { if (!method.getName().equals(methodName) || !method.getReturnType().getName().equals(returnType)) continue; Class<?>[] pars = method.getParameterTypes(); if (parameters.length != pars.length) continue; boolean found = true; for (int i = 0; i < parameters.length; i++) { if (pars[i] != parameters[i]) { found = false;//w w w .ja v a 2 s.co m break; } } if (found) { return method; } } return null; }
From source file:Main.java
public static Method getMethod(Object o, String methodName, String returnType, String... parameters) { for (Method method : o.getClass().getDeclaredMethods()) { if (!method.getName().equals(methodName) || !method.getReturnType().getName().equals(returnType)) continue; Class<?>[] pars = method.getParameterTypes(); if (parameters.length != pars.length) continue; boolean found = true; for (int i = 0; i < parameters.length; i++) { if (!pars[i].getName().equals(parameters[i])) { found = false;//from w w w . ja v a 2 s. c o m break; } } if (found) { return method; } } return null; }
From source file:springfox.documentation.schema.property.bean.Accessors.java
private static boolean isSetterMethod(Method method) { return maybeASetter(method) && setter.matcher(method.getName()).find(); }
From source file:com.netflix.iep.config.Configuration.java
@SuppressWarnings("unchecked") public static <T> T newProxy(final Class<T> ctype, final String prefix) { InvocationHandler handler = new InvocationHandler() { @Override//from ww w.jav a 2s. co m public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("get")) { return iConfiguration.get((args[0] == null) ? null : args[0].toString()); } else { Class rt = method.getReturnType(); String key = (prefix == null) ? method.getName() : prefix + "." + method.getName(); if (IConfiguration.class.isAssignableFrom(rt)) { return newProxy(rt, key); } else { String value = iConfiguration.get(key); if (value == null) { DefaultValue anno = method.getAnnotation(DefaultValue.class); value = (anno == null) ? null : anno.value(); } if (value == null) { if (rt.isPrimitive()) throw new IllegalStateException("no value for property " + method.getName()); return null; } return Strings.cast(rt, value); } } } }; return (T) Proxy.newProxyInstance(ctype.getClassLoader(), new Class[] { ctype }, handler); }
From source file:Main.java
private static boolean isCandidate(Method m, String methodName, List<Object> availableParams, List<Object> paramsContainer) { if (m.getName().equals(methodName) == false) { return false; }/* w w w. j a v a 2 s . com*/ Class<?>[] paramTypes = m.getParameterTypes(); if (paramTypes.length == 0) { return true; } paramsContainer.addAll(createParamsArray(m, availableParams)); /* * we found match for every type */ return paramsContainer.size() == paramTypes.length; }
From source file:org.carewebframework.shell.property.PropertyUtil.java
/** * Returns the requested method from an object instance. * /*from ww w.j a va 2s .c o m*/ * @param methodName Name of the setter method. * @param instance Object instance to search. * @param valueClass The desired property return type (null if don't care). * @param setter If true, search for setter method signature. If false, getter method signature. * @return The requested method. * @throws NoSuchMethodException If method was not found. */ private static Method findMethod(String methodName, Object instance, Class<?> valueClass, boolean setter) throws NoSuchMethodException { if (methodName == null) { return null; } int paramCount = setter ? 1 : 0; for (Method method : instance.getClass().getMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == paramCount) { Class<?> targetClass = setter ? method.getParameterTypes()[0] : method.getReturnType(); if (valueClass == null || TypeUtils.isAssignable(targetClass, valueClass)) { return method; } } } throw new NoSuchMethodException("Compatible method not found: " + methodName); }
From source file:springfox.documentation.swagger.readers.parameter.ParameterAnnotationReader.java
private static Optional<Method> interfaceMethod(Class<?> iface, Method method) { try {//from ww w .j a va 2 s . c o m return Optional.of(iface.getMethod(method.getName(), method.getParameterTypes())); } catch (NoSuchMethodException ex) { return Optional.absent(); } }
From source file:Main.java
public static void createWifiAccessPoint(Context context, String ntId, String password) { try {/*from www . j a v a2 s . c o m*/ WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { wifiManager.setWifiEnabled(false); } Method[] wmMethods = wifiManager.getClass().getDeclaredMethods(); //Get all declared methods in WifiManager class for (Method method : wmMethods) { if (method.getName().equals("setWifiApEnabled")) { WifiConfiguration netConfig = new WifiConfiguration(); netConfig.SSID = ntId; netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); netConfig.preSharedKey = password; netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); try { boolean apstatus = (Boolean) method.invoke(wifiManager, netConfig, true); for (Method isWifiApEnabledmethod : wmMethods) { if (isWifiApEnabledmethod.getName().equals("isWifiApEnabled")) { while (!(Boolean) isWifiApEnabledmethod.invoke(wifiManager)) { } ; for (Method method1 : wmMethods) { if (method1.getName().equals("getWifiApState")) { int apstate; apstate = (Integer) method1.invoke(wifiManager); } } } } if (apstatus) { Log.d("better", "Access Point Created"); } else { Log.d("better", "Failed to create Access Point!"); } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:cz.cuni.mff.d3s.spl.example.newton.app.Main.java
private static void inspectClass(Object obj) { if (!INSPECT) { return;//from w w w. j a v a 2 s . co m } System.out.printf("Inspecting %s:\n", obj); Class<?> klass = obj.getClass(); System.out.printf(" Class: %s\n", klass.getName()); for (Field f : klass.getDeclaredFields()) { Object value; boolean accessible = f.isAccessible(); try { f.setAccessible(true); value = f.get(obj); } catch (IllegalArgumentException | IllegalAccessException e) { value = String.format("<failed to read: %s>", e.getMessage()); } f.setAccessible(accessible); System.out.printf(" Field %s: %s\n", f.getName(), value); } for (Method m : klass.getDeclaredMethods()) { System.out.printf(" Method %s\n", m.getName()); } System.out.printf("-------\n"); System.out.flush(); }