[jboss-cvs] JBossAS SVN: r59072 - in branches/Branch_AOP_1_5/aop/src: main/org/jboss/aop/instrument main/org/jboss/aop/util test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 18 06:10:37 EST 2006
Author: kabir.khan at jboss.com
Date: 2006-12-18 06:10:31 -0500 (Mon, 18 Dec 2006)
New Revision: 59072
Modified:
branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java
branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/util/ReflectToJavassist.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/AnnotationsInWrapperMethodOnlyTestCase.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/POJO.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/TestAnnotation.java
Log:
[JBAOP-329] Parameter annotations should exist in wrapper method and not the internal method
Modified: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java 2006-12-18 10:55:16 UTC (rev 59071)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java 2006-12-18 11:10:31 UTC (rev 59072)
@@ -37,6 +37,8 @@
import javassist.NotFoundException;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.MethodInfo;
+import javassist.bytecode.ParameterAnnotationsAttribute;
+import javassist.bytecode.annotation.Annotation;
/**
* Comment
@@ -235,22 +237,43 @@
}
}
- protected void moveAnnotations(CtMethod src, CtMethod dest)
+ protected void moveAnnotations(CtMethod src, CtMethod dest) throws NotFoundException
{
MethodInfo mi = src.getMethodInfo2();
MethodInfo wmi = dest.getMethodInfo2();
- AnnotationsAttribute invisible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.invisibleTag);
- if (invisible != null)
+
+ moveAnnotations(mi, wmi, AnnotationsAttribute.invisibleTag);
+ moveAnnotations(mi, wmi, AnnotationsAttribute.visibleTag);
+ int numParams = src.getParameterTypes().length;
+ moveParameterAnnotations(numParams, mi, wmi, ParameterAnnotationsAttribute.visibleTag);
+ moveParameterAnnotations(numParams, mi, wmi, ParameterAnnotationsAttribute.invisibleTag);
+ }
+
+ private void moveAnnotations(MethodInfo src, MethodInfo dest, String annotationTag)
+ {
+ AnnotationsAttribute attribute = (AnnotationsAttribute) src.getAttribute(annotationTag);
+ if (attribute != null)
{
- wmi.addAttribute(invisible.copy(wmi.getConstPool(), new HashMap()));
+ dest.addAttribute(attribute.copy(dest.getConstPool(), new HashMap()));
+ src.addAttribute(new AnnotationsAttribute(src.getConstPool(), annotationTag));
}
- AnnotationsAttribute visible = (AnnotationsAttribute) mi.getAttribute(AnnotationsAttribute.visibleTag);
- if (visible != null)
+ }
+
+ private void moveParameterAnnotations(int numParams, MethodInfo src, MethodInfo dest, String paramsTag)
+ {
+ ParameterAnnotationsAttribute params = (ParameterAnnotationsAttribute)src.getAttribute(paramsTag);
+ if (params != null)
{
- wmi.addAttribute(visible.copy(wmi.getConstPool(), new HashMap()));
+ dest.addAttribute(params.copy(dest.getConstPool(), new HashMap()));
+ ParameterAnnotationsAttribute srcParams = new ParameterAnnotationsAttribute(src.getConstPool(), paramsTag);
+ Annotation[][] emptyParamAnnotations = new Annotation[numParams][];
+ for (int i = 0 ; i < numParams ; i++)
+ {
+ emptyParamAnnotations[i] = new Annotation[0];
+ }
+ srcParams.setAnnotations(emptyParamAnnotations);
+ src.addAttribute(srcParams);
}
- mi.addAttribute(new AnnotationsAttribute(mi.getConstPool(), AnnotationsAttribute.invisibleTag));
- mi.addAttribute(new AnnotationsAttribute(mi.getConstPool(), AnnotationsAttribute.visibleTag));
}
protected static String getAopReturnStr(CtMethod method)throws NotFoundException
Modified: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/util/ReflectToJavassist.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/util/ReflectToJavassist.java 2006-12-18 10:55:16 UTC (rev 59071)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/util/ReflectToJavassist.java 2006-12-18 11:10:31 UTC (rev 59072)
@@ -55,6 +55,7 @@
Class clazz = field.getDeclaringClass();
return classToJavassist(field.getDeclaringClass()).getField(field.getName());
}
+
public static CtConstructor constructorToJavassist(Constructor con) throws NotFoundException
{
Class clazz = con.getDeclaringClass();
Modified: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/AnnotationsInWrapperMethodOnlyTestCase.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/AnnotationsInWrapperMethodOnlyTestCase.java 2006-12-18 10:55:16 UTC (rev 59071)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/AnnotationsInWrapperMethodOnlyTestCase.java 2006-12-18 11:10:31 UTC (rev 59072)
@@ -24,8 +24,12 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
+import javassist.CtMethod;
+import javassist.NotFoundException;
+
import org.jboss.aop.Advised;
import org.jboss.aop.Advisor;
+import org.jboss.aop.util.ReflectToJavassist;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -64,6 +68,7 @@
Advisor advisor = ((Advised)pojo)._getAdvisor();
ArrayList hasAnnotation = new ArrayList();
+ ArrayList hasParameterAnnotation = new ArrayList();
for (int i = 0 ; i < methods.length ; i++)
{
Object ann = advisor.resolveAnnotation(methods[i], TestAnnotation.class);
@@ -71,11 +76,25 @@
{
hasAnnotation.add(methods[i].getName());
}
+
+ CtMethod ctmethod = ReflectToJavassist.methodToJavassist(methods[i]);
+ Object[][] paramAnnotations = ctmethod.getParameterAnnotations();
+ for (int p = 0 ; p < paramAnnotations.length ; p++)
+ {
+ if (paramAnnotations[p].length > 0)
+ {
+ hasParameterAnnotation.add(methods[i].getName() + "1");
+ }
+ }
}
assertFalse("Expected to find annotation for 'method'", hasAnnotation.size() == 0);
+ assertFalse("Expected to find parameter annotation for 'method'", hasParameterAnnotation.size() == 0);
assertTrue("Expected to find annotation for 'method' only, it was found for " + hasAnnotation, hasAnnotation.size() == 1);
+ assertTrue("Expected to find parameter annotation for 'method' only, it was found for " + hasParameterAnnotation, hasAnnotation.size() == 1);
assertEquals("method", hasAnnotation.get(0));
+ assertEquals("method1", hasParameterAnnotation.get(0));
+ assertTrue("Class was not woven", Advised.class.isAssignableFrom(POJO.class));
}
}
Modified: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/POJO.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/POJO.java 2006-12-18 10:55:16 UTC (rev 59071)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/POJO.java 2006-12-18 11:10:31 UTC (rev 59072)
@@ -28,10 +28,8 @@
*/
public class POJO
{
- /**
- * @@org.jboss.test.aop.regression.jbaop316annotationsinwrapperonly.TestAnnotation
- */
- public void method()
+ @TestAnnotation
+ public void method(int i, @TestAnnotation String s)
{
}
Modified: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/TestAnnotation.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/TestAnnotation.java 2006-12-18 10:55:16 UTC (rev 59071)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/regression/jbaop316annotationsinwrapperonly/TestAnnotation.java 2006-12-18 11:10:31 UTC (rev 59072)
@@ -21,11 +21,15 @@
*/
package org.jboss.test.aop.regression.jbaop316annotationsinwrapperonly;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
-public interface TestAnnotation {
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface TestAnnotation {
}
More information about the jboss-cvs-commits
mailing list