Fix FELIX-2542 - Annotations on methods parameters are not moved on public methods after manipulation

Parameter Annotations were not moved to the interceptor method during the annotation processing. This is now fixed.

As for method annotations, only annotation visible at runtime are moved, others are ignored.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@987909 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/manipulator/manipulator-java5/pom.xml b/ipojo/tests/manipulator/manipulator-java5/pom.xml
index 218346f..99844e8 100644
--- a/ipojo/tests/manipulator/manipulator-java5/pom.xml
+++ b/ipojo/tests/manipulator/manipulator-java5/pom.xml
@@ -17,7 +17,7 @@
 	under the License.

 -->

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

 	<parent>

 		<groupId>ipojo.tests</groupId>

 		<artifactId>ipojo.tests</artifactId>

@@ -85,14 +85,12 @@
 			<plugin>

 				<groupId>org.apache.felix</groupId>

 				<artifactId>maven-ipojo-plugin</artifactId>

+				<version>1.7.0-SNAPSHOT</version>

 				<executions>

 					<execution>

 						<goals>

 							<goal>ipojo-bundle</goal>

 						</goals>

-						<configuration>

-							<ignoreAnnotations>true</ignoreAnnotations>

-						</configuration>

 					</execution>

 				</executions>

 			</plugin>

@@ -104,6 +102,21 @@
 					<target>1.5</target>

 				</configuration>

 			</plugin>

+

+			<plugin>

+				<groupId>org.apache.felix</groupId>

+				<artifactId>maven-junit4osgi-plugin</artifactId>

+				<version>1.1.0-SNAPSHOT</version>

+				<executions>

+					<execution>

+						<goals>

+							<goal>test</goal>

+						</goals>

+						<configuration>

+						</configuration>

+					</execution>

+				</executions>

+			</plugin>

 		</plugins>

 	</build>

 </project>

diff --git a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Annotation.java b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Annotation.java
index 0e21b2c..efdc265 100644
--- a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Annotation.java
+++ b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Annotation.java
@@ -1,5 +1,8 @@
 package org.apache.felix.ipojo.test.scenarios.component;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
 import org.apache.felix.ipojo.test.scenarios.component.Marker.Type;
 
 public class Annotation {
@@ -25,5 +28,19 @@
     public Annotation() {
         
     }
+    
+    public void doSomethingWithParams(@Marker(name="marker", type=Type.BAR, 
+            sub=@SubMarker(subname="foo"),
+            arrayOfObjects={"foo", "bar", "baz"},
+            arrayOfAnnotations= {@SubMarker(subname="foo")}) String foo, 
+            @Invisible String bar, 
+            @bla @SubMarker(subname = "baz") String baz) {
+        System.out.println("Foo ...");
+    }
+    
+    @Retention(RetentionPolicy.RUNTIME)
+    @interface bla {
+        
+    }
 
 }
diff --git a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/Annotation.java b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/Annotation.java
index 6128a1d..81b8831 100644
--- a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/Annotation.java
+++ b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/Annotation.java
@@ -2,6 +2,7 @@
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
+import java.util.Arrays;
 
 import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
 import org.apache.felix.ipojo.test.scenarios.component.Marker;
@@ -99,6 +100,43 @@
         assertEquals("Check submarker", "bar", sub.subname());
     }
     
+    public void testParameterAnnotations() {
+        Method method = null;
+        try {
+            method = this.clazz.getMethod("doSomethingWithParams", new Class[] {String.class, String.class, String.class});
+        } catch (Exception e) {
+            fail("Cannot find the doSomethingWithParams method : " + e.getMessage());
+        } 
+        assertNotNull("Check method existence", method);
+        
+        java.lang.annotation.Annotation[][] annotations = method.getParameterAnnotations();
+        assertNotNull("Check annotations size - 1", annotations);
+        assertEquals("Check annotations size - 3", 3, annotations.length);
+        
+        // Check internals
+        // First parameter (foo)
+        java.lang.annotation.Annotation[] fooAnns = annotations[0];
+        assertEquals("Check fooAnns length", 1, fooAnns.length);
+        Marker marker = (Marker) fooAnns[0];
+        assertNotNull("Check marker", marker);
+        assertEquals("Check marker name", "marker", marker.name());
+        assertEquals("Check marker type", Marker.Type.BAR, marker.type());
+        assertEquals("Check sub marker attribute", "foo", marker.sub().subname());
+        assertEquals("Check objects [0]", "foo", marker.arrayOfObjects()[0]);
+        assertEquals("Check objects [1]", "bar", marker.arrayOfObjects()[1]);
+        assertEquals("Check objects [2]", "baz", marker.arrayOfObjects()[2]);
+        assertEquals("Check annotations[0]", "foo", marker.arrayOfAnnotations()[0].subname());
+        
+        // Second parameter (bar), no annotation (invisible)
+        java.lang.annotation.Annotation[] barAnns = annotations[1];
+        assertEquals("Check barAnns length", 0, barAnns.length);
+        
+        // Third parameter (baz), two annotations
+        java.lang.annotation.Annotation[] bazAnns = annotations[2];
+        System.out.println(Arrays.toString(bazAnns));
+        assertEquals("Check bazAnns length", 2, bazAnns.length);
+    }
+    
     private Marker getMarkerAnnotation(java.lang.annotation.Annotation[] annotations) {
         for (int i = 0; i < annotations.length; i++) {
             if (annotations[i].annotationType().getName().equals("org.apache.felix.ipojo.test.scenarios.component.Marker")) {