/** * Scoped use method * * @param self any Object * @param categoryClass a category class to use * @param closure the closure to invoke with the category in place * @return the value returned from the closure * @since 1.0 */ public static <T> T use(Object self, Class categoryClass, Closure<T> closure) { return GroovyCategorySupport.use(categoryClass, closure); }
/** * Scoped use method with list of categories. * * @param self any Object * @param categoryClassList a list of category classes * @param closure the closure to invoke with the categories in place * @return the value returned from the closure * @since 1.0 */ public static <T> T use(Object self, List<Class> categoryClassList, Closure<T> closure) { return GroovyCategorySupport.use(categoryClassList, closure); }
return GroovyCategorySupport.use(list, closure);
GroovyCategorySupport.use(ServletCategory.class, closure); } catch (RuntimeException runtimeException) { StringBuilder error = new StringBuilder("GroovyServlet Error: ");
/** * Scoped use method with list of categories. * * @param self any Object * @param categoryClassList a list of category classes * @param closure the closure to invoke with the categories in place * @return the value returned from the closure * @since 1.0 */ public static <T> T use(Object self, List<Class> categoryClassList, Closure<T> closure) { return GroovyCategorySupport.use(categoryClassList, closure); }
/** * Scoped use method * * @param self any Object * @param categoryClass a category class to use * @param closure the closure to invoke with the category in place * @return the value returned from the closure * @since 1.0 */ public static Object use(Object self, Class categoryClass, Closure closure) { return GroovyCategorySupport.use(categoryClass, closure); }
/** * Scoped use method * * @param self any Object * @param categoryClass a category class to use * @param closure the closure to invoke with the category in place * @return the value returned from the closure */ public static Object use(Object self, Class categoryClass, Closure closure) { return GroovyCategorySupport.use(categoryClass, closure); }
/** * Scoped use method with list of categories. * * @param self any Object * @param categoryClassList a list of category classes * @param closure the closure to invoke with the categories in place * @return the value returned from the closure * @since 1.0 */ public static Object use(Object self, List categoryClassList, Closure closure) { return GroovyCategorySupport.use(categoryClassList, closure); }
/** * Scoped use method with list of categories. * * @param self any Object * @param categoryClassList a list of category classes * @param closure the closure to invoke with the categories in place * @return the value returned from the closure */ public static Object use(Object self, List categoryClassList, Closure closure) { return GroovyCategorySupport.use(categoryClassList, closure); }
/** * Scoped use method with list of categories. * * @param self any Object * @param categoryClassList a list of category classes * @param closure the closure to invoke with the categories in place * @return the value returned from the closure * @since 1.0 */ public static Object use(Object self, List<Class> categoryClassList, Closure closure) { return GroovyCategorySupport.use(categoryClassList, closure); }
/** * Scoped use method * * @param self any Object * @param categoryClass a category class to use * @param closure the closure to invoke with the category in place * @return the value returned from the closure * @since 1.0 */ public static <T> T use(Object self, Class categoryClass, Closure<T> closure) { return GroovyCategorySupport.use(categoryClass, closure); }
/** * Scoped use method * * @param self any Object * @param categoryClass a category class to use * @param closure the closure to invoke with the category in place * @return the value returned from the closure * @since 1.0 */ public static Object use(Object self, Class categoryClass, Closure closure) { return GroovyCategorySupport.use(categoryClass, closure); }
@SuppressWarnings("rawtypes") @Override protected final void act() { if (action != null) { if (action instanceof Closure) { //noinspection RawUseOfParameterizedType GroovyCategorySupport.use(Arrays.<Class>asList(), (Closure) action); } else { action.run(); } } }
/** for testing only */ public Outcome run(final int max) { return GroovyCategorySupport.use(Continuable.categories, new Closure<Outcome>(null) { @Override public Outcome call() { int remaining = max; List<String> functions = new ArrayList<String>(); Next n = Next.this; while(n.yield==null) { functions.add(n.f.getClass().getCanonicalName()); if (--remaining == 0) { int len = functions.size(); throw new AssertionError("Did not terminate; ran " + len + " steps ending with: " + functions.subList(len - 20, len)); } n = n.step(); } return n.yield; } }); }
/** * Allows you to use a list of categories, specifying the list as varargs. * <code>use(CategoryClass1, CategoryClass2) { ... }</code> * This method saves having to wrap the the category * classes in a list. * * @param self any Object * @param array a list of category classes and a Closure * @return the value returned from the closure */ public static Object use(Object self, Object[] array) { if (array.length < 2) throw new IllegalArgumentException( "Expecting at least 2 arguments, a category class and a Closure"); Closure closure; try { closure = (Closure) array[array.length - 1]; } catch (ClassCastException e) { throw new IllegalArgumentException("Expecting a Closure to be the last argument"); } List list = new ArrayList(array.length - 1); for (int i = 0; i < array.length - 1; ++i) list.add(array[i]); return GroovyCategorySupport.use(list, closure); }
/** * Allows you to use a list of categories, specifying the list as varargs. * <code>use(CategoryClass1, CategoryClass2) { ... }</code> * This method saves having to wrap the the category * classes in a list. * * @param self any Object * @param array a list of category classes and a Closure * @return the value returned from the closure * @since 1.0 */ public static Object use(Object self, Object[] array) { if (array.length < 2) throw new IllegalArgumentException( "Expecting at least 2 arguments, a category class and a Closure"); Closure closure; try { closure = (Closure) array[array.length - 1]; } catch (ClassCastException e) { throw new IllegalArgumentException("Expecting a Closure to be the last argument"); } List list = new ArrayList(array.length - 1); for (int i = 0; i < array.length - 1; ++i) list.add(array[i]); return GroovyCategorySupport.use(list, closure); }
return GroovyCategorySupport.use(list, closure);
/** * Resumes this program by either returning the value from {@link Continuable#suspend(Object)} or * throwing an exception */ public Outcome run0(final Outcome cn, List<Class> categories) { return GroovyCategorySupport.use(categories, new Closure<Outcome>(null) { @Override public Outcome call() { Next n = cn.resumeFrom(e,k); while(n.yield==null) { if (interrupt!=null) { // TODO: correctly reporting a source location requires every block to have the line number n = new Next(new ThrowBlock(UNKNOWN, new ConstantBlock(interrupt), true),n.e,n.k); interrupt = null; } n = n.step(); } e = n.e; k = n.k; return n.yield; } }); }
/** * Create a scope based on given categoryClasses and invoke closure within that scope. * * @param categoryClasses the list of classes containing category methods * @param closure the closure during which to make the category class methods available * @return the value returned from the closure */ public static Object use(List categoryClasses, Closure closure) { newScope(); try { for (Iterator i = categoryClasses.iterator(); i.hasNext(); ) { Class clazz = (Class) i.next(); use(clazz); } return closure.call(); } finally { endScope(); } }
/** * Create a scope based on given categoryClass and invoke closure within that scope. * * @param categoryClass the class containing category methods * @param closure the closure during which to make the category class methods available * @return the value returned from the closure */ public static Object use(Class categoryClass, Closure closure) { newScope(); try { use(categoryClass); return closure.call(); } finally { endScope(); } }