@Test public void executeVisitorMethod() { VisitorUtils.executeVisitorMethod(visitorA, visitableFoo); verify(visitableFoo).fooA(); }
public static void executeVisitorMethod(Object visitor, Object visitedObject) { Class<?> visitableClass = visitedObject.getClass(); Method visitMethod = ReflectionTools.findMethod(visitor.getClass(), "visit", visitedObject); if (visitMethod != null) { try { visitMethod.invoke(visitor, new Object[]{visitedObject}); return; } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); throw new RuntimeException(e); } } throw new IllegalArgumentException("visit("+visitableClass.getSimpleName()+") method not found in visitor class "+visitor.getClass().getName()); }
VisitorUtils { public static void executeVisitorMethod(Object visitor, Object visitedObject) { Class<?> visitableClass = visitedObject.getClass(); Method visitMethod = ReflectionTools.findMethod(visitor.getClass(), "visit", visitedObject); if (visitMethod != null) { try { visitMethod.invoke(visitor, new Object[]{visitedObject}); return; } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); throw new RuntimeException(e); } } throw new IllegalArgumentException("visit("+visitableClass.getSimpleName()+") method not found in visitor class "+visitor.getClass().getName()); } }
VisitorUtils { public static void executeVisitorMethod(Object visitor, Object visitedObject) { Class<?> visitableClass = visitedObject.getClass(); Method visitMethod = ReflectionTools.findMethod(visitor.getClass(), "visit", visitedObject); if (visitMethod != null) { try { visitMethod.invoke(visitor, new Object[]{visitedObject}); return; } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); throw new RuntimeException(e); } } throw new IllegalArgumentException("visit("+visitableClass.getSimpleName()+") method not found in visitor class "+visitor.getClass().getName()); }  }
VisitorUtils { public static void executeVisitorMethod(Object visitor, Object visitedObject) { Class<?> visitableClass = visitedObject.getClass(); Method visitMethod = ReflectionTools.findMethod(visitor.getClass(), "visit", visitedObject); if (visitMethod != null) { try { visitMethod.invoke(visitor, new Object[]{visitedObject}); return; } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); throw new RuntimeException(e); } } throw new IllegalArgumentException("visit("+visitableClass.getSimpleName()+") method not found in visitor class "+visitor.getClass().getName()); }  static void executeVisitorMethod(Object visitor, Object visitedObject); }
VisitorUtils { public static void executeVisitorMethod(Object visitor, Object visitedObject) { Class<?> visitableClass = visitedObject.getClass(); Method visitMethod = ReflectionTools.findMethod(visitor.getClass(), "visit", visitedObject); if (visitMethod != null) { try { visitMethod.invoke(visitor, new Object[]{visitedObject}); return; } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); throw new RuntimeException(e); } } throw new IllegalArgumentException("visit("+visitableClass.getSimpleName()+") method not found in visitor class "+visitor.getClass().getName()); }  static void executeVisitorMethod(Object visitor, Object visitedObject);  }