diff -r 4a93f2679691 -r 86aabecda7a3 boot/src/main/java/org/apidesign/html/boot/spi/Fn.java
--- a/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java Tue Nov 05 23:06:32 2013 +0100
+++ b/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java Wed Nov 06 15:15:54 2013 +0100
@@ -62,6 +62,31 @@
return FnContext.currentPresenter() == presenter;
}
+ /** Helper method to check if the provided instance is valid function.
+ * Checks if the parameter is non-null and if so, does {@link #isValid()}
+ * check.
+ *
+ * @param fnOrNull function or null
+ * @return true if the parameter is non-null and valid
+ * @since 0.7
+ */
+ public static boolean isValid(Fn fnOrNull) {
+ return fnOrNull != null && fnOrNull.isValid();
+ }
+
+ /** Helper method to find current presenter and ask it to define new
+ * function by calling {@link Presenter#defineFn(java.lang.String, java.lang.String...)}.
+ *
+ * @param caller the class who wishes to define the function
+ * @param code the body of the function (can reference this
and names
variables)
+ * @param names names of individual parameters
+ * @return the function object that can be {@link Fn#invoke(java.lang.Object, java.lang.Object...) invoked}
+ * @since 0.7
+ */
+ public static Fn define(Class> caller, String code, String... names) {
+ return FnContext.currentPresenter().defineFn(code, names);
+ }
+
/** The currently active presenter.
*
* @return the currently active presenter or null