You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2006/10/19 16:54:20 UTC

svn commit: r465648 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/internal/services/ main/java/org/apache/tapestry/runtime/ test/java/org/apache/tapestry/internal/services/ test/java/org/apache/tapestry/runtime/

Author: hlship
Date: Thu Oct 19 07:54:19 2006
New Revision: 465648

URL: http://svn.apache.org/viewvc?view=rev&rev=465648
Log:
Change LifecycleEvent.storeResult() to return true if the event is aborted (which streamlines some of the runtime-generated code).

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorker.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/LifecycleEvent.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorkerTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/runtime/LifecycleEventTest.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorker.java?view=diff&rev=465648&r1=465647&r2=465648
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorker.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorker.java Thu Oct 19 07:54:19 2006
@@ -28,8 +28,6 @@
 /**
  * Converts one of the methods of {@link org.apache.tapestry.runtime.ComponentLifecycle} into a
  * chain of command that, itself, invokes certain methods marked with an annotation.
- * 
- * 
  */
 public class ComponentLifecycleMethodWorker implements ComponentClassTransformWorker
 {
@@ -87,7 +85,7 @@
         boolean isVoid = sig.getReturnType().equals("void");
 
         if (!isVoid)
-            builder.add("$2.storeResult(($w) ");
+            builder.add("if ($2.storeResult(($w) ");
 
         // This is the best part; the method can even be private and this still works. It's a lot
         // like how javac enables access to private members for inner classes (by introducing
@@ -100,13 +98,12 @@
         if (!isVoid)
         {
             // Complete the call to storeResult(), with a string that
-            // identifies the class and the method.
-            builder.addln(", \"%s.%s\");", transformation.getClassName(), sig.getMediumDescription());
+            // identifies the class and the method. Finish off the if(...) that
+            // checks the return value and returns early. The return value of
+            // LifecycleEvent.storeResult() is true if the event is aborted by the call.
 
-            // Really, this could be omitted from the final annotated method invocation, since
-            // the method will end up returning either way. Let HotSpot catch that (I'm sure it
-            // can).
-            builder.addln(CHECK_ABORT_FLAG);
+            builder.addln(", \"%s.%s\")) return;", transformation.getClassName(), sig
+                    .getMediumDescription());
         }
         else
             builder.addln(";");

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/LifecycleEvent.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/LifecycleEvent.java?view=diff&rev=465648&r1=465647&r2=465648
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/LifecycleEvent.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/LifecycleEvent.java Thu Oct 19 07:54:19 2006
@@ -22,8 +22,9 @@
  * annotated methods corresponding to the particular lifecycle method. The chain of command executes
  * until a particular result is specified (via the return value of one of the annotated methods),
  * which terminates the chain (potentially skipping some of the method invocations).
- * 
- * 
+ * <p>
+ * TODO: It's beginning to look like LifecycleEvents will always accept only boolean values, so we
+ * may want to un-genericize this type.
  */
 public final class LifecycleEvent<T>
 {
@@ -67,23 +68,26 @@
      * @param result
      *            the provided result, or null if the method did not provide a result
      * @param methodDescription
-     *            describes the method invoked, which returned the value
+     *            describes the method invoked, the method that returned the value
+     * @return true if the value was non-null, and the event is now aborted
      */
     @SuppressNullCheck
-    public void storeResult(T result, String methodDescription)
+    public boolean storeResult(T result, String methodDescription)
     {
         if (result == null)
-            return;
+            return false;
 
         // TODO: IllegalStateException if _abort is true?
 
         if (!_expectedType.isInstance(result))
         {
             _log.error(RuntimeMessages.wrongEventResultType(methodDescription, _expectedType));
-            return;
+            return false;
         }
 
         _result = result;
         _aborted = true;
+
+        return true;
     }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorkerTest.java?view=diff&rev=465648&r1=465647&r2=465648
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorkerTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentLifecycleMethodWorkerTest.java Thu Oct 19 07:54:19 2006
@@ -128,8 +128,8 @@
                 tf,
                 TransformConstants.SETUP_RENDER_SIGNATURE,
                 "{ if ($2.isAborted()) return; ",
-                "$2.storeResult(($w) aMethod(), \"biff.Baz.aMethod()\");",
-                "if ($2.isAborted()) return; }");
+                "if ($2.storeResult(($w) aMethod(), \"biff.Baz.aMethod()\")) return;",
+                "}");
 
         replay();
 
@@ -160,8 +160,7 @@
                 tf,
                 TransformConstants.SETUP_RENDER_SIGNATURE,
                 "{ if ($2.isAborted()) return;",
-                "$2.storeResult(($w) aMethod(), \"foo.Bar.aMethod()\");",
-                "if ($2.isAborted()) return;",
+                "if ($2.storeResult(($w) aMethod(), \"foo.Bar.aMethod()\")) return;",
                 "bMethod($1); }");
 
         replay();

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/runtime/LifecycleEventTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/runtime/LifecycleEventTest.java?view=diff&rev=465648&r1=465647&r2=465648
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/runtime/LifecycleEventTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/runtime/LifecycleEventTest.java Thu Oct 19 07:54:19 2006
@@ -49,7 +49,7 @@
 
         LifecycleEvent<Integer> event = new LifecycleEvent<Integer>(log, Integer.class, 99);
 
-        event.storeResult(88, "some method");
+        assertTrue(event.storeResult(88, "some method"));
 
         assertEquals(true, event.isAborted());
         assertEquals(88, (int) event.getResult());
@@ -66,7 +66,7 @@
 
         LifecycleEvent<Integer> event = new LifecycleEvent<Integer>(log, Integer.class, 99);
 
-        event.storeResult(null, "{some method}");
+        assertFalse(event.storeResult(null, "{some method}"));
 
         assertEquals(false, event.isAborted());
         assertEquals(99, (int) event.getResult());
@@ -87,7 +87,7 @@
 
         LifecycleEvent event = new LifecycleEvent<Integer>(log, Integer.class, 99);
 
-        event.storeResult("88", "{some method}");
+        assertFalse(event.storeResult("88", "{some method}"));
 
         assertEquals(false, event.isAborted());
         assertEquals(new Integer(99), event.getResult());