You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/06/22 02:10:51 UTC

svn commit: r1138260 - in /tapestry/tapestry5/trunk: plastic/src/main/java/org/apache/tapestry5/internal/plastic/ plastic/src/main/java/org/apache/tapestry5/plastic/ plastic/src/test/groovy/org/apache/tapestry5/plastic/ tapestry-core/src/main/java/org/...

Author: hlship
Date: Wed Jun 22 00:10:50 2011
New Revision: 1138260

URL: http://svn.apache.org/viewvc?rev=1138260&view=rev
Log:
Simplify MethodInvocation to provide the java.lang.reflect.Method being invoked, rather than separate properties derived from the Method

Modified:
    tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/internal/plastic/AbstractMethodInvocation.java
    tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/plastic/MethodInvocation.java
    tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/MethodAdviceTests.groovy
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/BridgeClassTransformation.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java

Modified: tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/internal/plastic/AbstractMethodInvocation.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/internal/plastic/AbstractMethodInvocation.java?rev=1138260&r1=1138259&r2=1138260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/internal/plastic/AbstractMethodInvocation.java (original)
+++ tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/internal/plastic/AbstractMethodInvocation.java Wed Jun 22 00:10:50 2011
@@ -95,16 +95,6 @@ public abstract class AbstractMethodInvo
         return this;
     }
 
-    public String getMethodName()
-    {
-        return bundle.methodDescription.methodName;
-    }
-
-    public int getParameterCount()
-    {
-        return bundle.methodDescription.argumentTypes.length;
-    }
-
     public <T extends Annotation> boolean hasAnnotation(Class<T> annotationType)
     {
         return getAnnotation(annotationType) != null;
@@ -112,23 +102,14 @@ public abstract class AbstractMethodInvo
 
     public <T extends Annotation> T getAnnotation(Class<T> annotationType)
     {
-        return method().getAnnotation(annotationType);
+        return getMethod().getAnnotation(annotationType);
     }
 
-    public Method method()
+    public Method getMethod()
     {
         return bundle.getMethod(getInstance());
     }
 
-    public Class getReturnType()
-    {
-        return method().getReturnType();
-    }
-
-    public Class getParameterType(int index)
-    {
-        return method().getParameterTypes()[index];
-    }
-
+    /** This is implemented in a runtime-generated subclass. */
     protected abstract void proceedToAdvisedMethod();
 }

Modified: tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/plastic/MethodInvocation.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/plastic/MethodInvocation.java?rev=1138260&r1=1138259&r2=1138260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/plastic/MethodInvocation.java (original)
+++ tapestry/tapestry5/trunk/plastic/src/main/java/org/apache/tapestry5/plastic/MethodInvocation.java Wed Jun 22 00:10:50 2011
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry5.plastic;
 
+import java.lang.reflect.Method;
+
 /**
  * A representation of the invocation of a method that allows the behavior of the method to be advised: either by
  * changing parameter values, or by changing the return value, or by catch or throwing different exceptions. Provides
@@ -82,15 +84,6 @@ public interface MethodInvocation extend
      */
     MethodInvocation setCheckedException(Exception exception);
 
-    /** Returns the name of the advised method. */
-    String getMethodName();
-
-    /** Returns the number of parameters passed to the advised method. */
-    int getParameterCount();
-
-    /** Returns the method's return type. */
-    Class getReturnType();
-
-    /** Returns the type of the indicated parameter. */
-    Class getParameterType(int index);
+    /** Returns the method being invoked. */
+    Method getMethod();
 }

Modified: tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/MethodAdviceTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/MethodAdviceTests.groovy?rev=1138260&r1=1138259&r2=1138260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/MethodAdviceTests.groovy (original)
+++ tapestry/tapestry5/trunk/plastic/src/test/groovy/org/apache/tapestry5/plastic/MethodAdviceTests.groovy Wed Jun 22 00:10:50 2011
@@ -18,14 +18,10 @@ class MethodAdviceTests extends Abstract
             findMethod(pc, "aSingleMethod").addAdvice ({
                 didInvoke = true
 
-                assert it.methodName == "aSingleMethod"
-                assert it.parameterCount == 1
+                assert it.method.name == "aSingleMethod"
 
                 assert it.getParameter(0) == 123
 
-                assert it.returnType == void.class
-                assert it.getParameterType(0) == int.class
-
                 assert it.hasAnnotation(Deprecated.class) == false
                 assert it.hasAnnotation(Maybe.class) == true
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/BridgeClassTransformation.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/BridgeClassTransformation.java?rev=1138260&r1=1138259&r2=1138260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/BridgeClassTransformation.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/BridgeClassTransformation.java Wed Jun 22 00:10:50 2011
@@ -15,6 +15,7 @@
 package org.apache.tapestry5.internal.transform;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 import java.util.List;
 
 import org.apache.tapestry5.ComponentResources;
@@ -389,7 +390,7 @@ public class BridgeClassTransformation i
 
                 public Class getResultType()
                 {
-                    return invocation.getReturnType();
+                    return method().getReturnType();
                 }
 
                 public Object getResult()
@@ -399,12 +400,12 @@ public class BridgeClassTransformation i
 
                 public Class getParameterType(int index)
                 {
-                    return invocation.getParameterType(index);
+                    return method().getParameterTypes()[index];
                 }
 
                 public int getParameterCount()
                 {
-                    return invocation.getParameterCount();
+                    return method().getParameterTypes().length;
                 }
 
                 public Object getParameter(int index)
@@ -414,7 +415,12 @@ public class BridgeClassTransformation i
 
                 public String getMethodName()
                 {
-                    return invocation.getMethodName();
+                    return method().getName();
+                }
+
+                private Method method()
+                {
+                    return invocation.getMethod();
                 }
 
                 public <T extends Annotation> T getMethodAnnotation(Class<T> annotationClass)

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java?rev=1138260&r1=1138259&r2=1138260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java Wed Jun 22 00:10:50 2011
@@ -1421,22 +1421,27 @@ public class InternalUtils
 
                     public Class getResultType()
                     {
-                        return invocation.getReturnType();
+                        return method().getReturnType();
+                    }
+
+                    private Method method()
+                    {
+                        return invocation.getMethod();
                     }
 
                     public Class getParameterType(int index)
                     {
-                        return invocation.getParameterType(index);
+                        return method().getParameterTypes()[index];
                     }
 
                     public int getParameterCount()
                     {
-                        return invocation.getParameterCount();
+                        return method().getParameterTypes().length;
                     }
 
                     public String getMethodName()
                     {
-                        return invocation.getMethodName();
+                        return method().getName();
                     }
 
                     public <T extends Annotation> T getMethodAnnotation(Class<T> annotationClass)