public static Method findDeclaredMethod(final Class type, final String methodName, final Class[] parameterTypes) throws NoSuchMethodException { Class cl = type; while (cl != null) { try { return cl.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { cl = cl.getSuperclass(); } } throw new NoSuchMethodException(methodName); }
@SuppressWarnings("unchecked") public static <T> T invoke(Method method, Object obj, Object... args) throws NoSuchMethodException { if (method == null) { throw new NoSuchMethodException(); } try { return (T) method.invoke(obj, args); } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) { // fall through } throw new NoSuchMethodException(method.getName()); } }
public static Method findDeclaredMethod(final Class type, final String methodName, final Class[] parameterTypes) throws NoSuchMethodException { Class cl = type; while (cl != null) { try { return cl.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { cl = cl.getSuperclass(); } } throw new NoSuchMethodException(methodName); }
public static Method findDeclaredMethod(final Class type, final String methodName, final Class[] parameterTypes) throws NoSuchMethodException { Class cl = type; while (cl != null) { try { return cl.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { cl = cl.getSuperclass(); } } throw new NoSuchMethodException(methodName); }
public static Method findDeclaredMethod(final Class type, final String methodName, final Class[] parameterTypes) throws NoSuchMethodException { Class cl = type; while (cl != null) { try { return cl.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { cl = cl.getSuperclass(); } } throw new NoSuchMethodException(methodName); }
@Override public Object invoke(String name, Object[] args, String[] sig) throws MBeanException, ReflectionException { throw new ReflectionException(new NoSuchMethodException(name)); }
public static Method searchMethod(Class<?> currentClass, String name, Class<?>[] parameterTypes) throws NoSuchMethodException { if (currentClass == null) { throw new NoSuchMethodException("class == null"); } try { return currentClass.getMethod(name, parameterTypes); } catch (NoSuchMethodException e) { for (Method method : currentClass.getMethods()) { if (method.getName().equals(name) && parameterTypes.length == method.getParameterTypes().length && Modifier.isPublic(method.getModifiers())) { if (parameterTypes.length > 0) { Class<?>[] types = method.getParameterTypes(); boolean match = true; for (int i = 0; i < parameterTypes.length; i++) { if (!types[i].isAssignableFrom(parameterTypes[i])) { match = false; break; } } if (!match) { continue; } } return method; } } throw e; } }
public static Method searchMethod(Class<?> currentClass, String name, Class<?>[] parameterTypes) throws NoSuchMethodException { if (currentClass == null) { throw new NoSuchMethodException("class == null"); } try { return currentClass.getMethod(name, parameterTypes); } catch (NoSuchMethodException e) { for (Method method : currentClass.getMethods()) { if (method.getName().equals(name) && parameterTypes.length == method.getParameterTypes().length && Modifier.isPublic(method.getModifiers())) { if (parameterTypes.length > 0) { Class<?>[] types = method.getParameterTypes(); boolean match = true; for (int i = 0; i < parameterTypes.length; i++) { if (!types[i].isAssignableFrom(parameterTypes[i])) { match = false; break; } } if (!match) { continue; } } return method; } } throw e; } }
@Override public Object invoke(String name, Object[] args, String[] signature) throws MBeanException, ReflectionException { if (name.equals("reset")) { reset(); return null; } throw new ReflectionException(new NoSuchMethodException(name)); }
/** @param name the name of the method * @param parameterTypes the types of the parameters of the method * @return the public method that matches the name and parameter types of this type or one of its super interfaces. * @throws NoSuchMethodException */ public Method getMethod (String name, Class... parameterTypes) throws NoSuchMethodException { for (Method m : getMethods()) { if (m.match(name, parameterTypes)) return m; } throw new NoSuchMethodException(); }
public Object invoke(String operationName, Object params[], String signature[]) throws MBeanException, ReflectionException { if (operationName == null) { throw new RuntimeOperationsException( new IllegalArgumentException("Operation name cannot be null"), "Cannot invoke a null operation in " + dClassName); } // Check for a recognized operation name and call the corresponding operation if(operationName.equals("addLoggerMBean")) { return addLoggerMBean((String)params[0]); } else { throw new ReflectionException( new NoSuchMethodException(operationName), "Cannot find the operation " + operationName + " in " + dClassName); } }
public Constructor getConstructor (Class... parameterTypes) throws NoSuchMethodException { for (Constructor c : constructors) { if (c.isPublic() && c.match(parameterTypes)) return c; } throw new NoSuchMethodException(); }
/** @param name the name of the method * @param parameterTypes the types of the parameters of the method * @return the declared method that matches the name and parameter types of this type. * @throws NoSuchMethodException */ public Method getDeclaredMethod (String name, Class... parameterTypes) throws NoSuchMethodException { for (Method m : getDeclaredMethods()) { if (m.match(name, parameterTypes)) return m; } throw new NoSuchMethodException(); }
/** @param name the name of the method * @param parameterTypes the types of the parameters of the method * @return the public method that matches the name and parameter types of this type or one of its super interfaces. * @throws NoSuchMethodException */ public Method getMethod (String name, Class... parameterTypes) throws NoSuchMethodException { for (Method m : getMethods()) { if (m.match(name, parameterTypes)) return m; } throw new NoSuchMethodException(); }
public Constructor getConstructor (Class... parameterTypes) throws NoSuchMethodException { for (Constructor c : constructors) { if (c.isPublic() && c.match(parameterTypes)) return c; } throw new NoSuchMethodException(); }
/** @param name the name of the method * @param parameterTypes the types of the parameters of the method * @return the declared method that matches the name and parameter types of this type. * @throws NoSuchMethodException */ public Method getDeclaredMethod (String name, Class... parameterTypes) throws NoSuchMethodException { for (Method m : getDeclaredMethods()) { if (m.match(name, parameterTypes)) return m; } throw new NoSuchMethodException(); }
public static Field[] helper5(Class<?> clazz, Class<?>... params) throws NoSuchMethodException { callcount++; events.add("helper5(" + clazz.getName() + ")"); if (params == null || params.length == 0) { return null; } else if (params[0] == String.class) { return null; } throw new NoSuchMethodException("" + params[0]); }
@Override public final NoSuchMethodException noSuchMethod(final String name) { final NoSuchMethodException result = new NoSuchMethodException(String.format(getLoggingLocale(), noSuchMethod$str(), name)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String noSuchField = "WFLYJCA0075: Field %s not found";
public static byte[] testDexASMifier(Class<?> clz, String methodName, String generateClassName) throws Exception { DexClassNode clzNode = new DexClassNode(DexConstants.ACC_PUBLIC, "L" + generateClassName + ";", "Ljava/lang/Object;", null); Method m = clz.getMethod(methodName, DexClassVisitor.class); if (m == null) { throw new java.lang.NoSuchMethodException(methodName); } m.setAccessible(true); if (Modifier.isStatic(m.getModifiers())) { m.invoke(null, clzNode); } else { m.invoke(clz.newInstance(), clzNode); } return translateAndCheck(clzNode); }
@Test(expected = NoSuchMethodException.class) public void testRethrowCheckedException() throws Exception { Throwables.rethrow(new NoSuchMethodException()); } }