Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: 1.5
-
Fix Version/s: 1.5.2
-
Component/s: groovy-jdk
-
Labels:None
-
Environment:SUN JRE 1.5.0.13
Windows XP SP2
-
Testcase included:yes
-
Number of attachments :
Description
First, create the following annotation in Java:
package problem; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Test { String name() default ""; }
Second, create the following groovy script:
import problem.Test; class Script { @Test(name="problems") void teste() { } }
Finally, try to find the annotated method in Java:
GroovyClassLoader loader = new GroovyClassLoader(TesteMain.class.getClassLoader()); Class clazz = loader.parseClass(new File("c:\\Script.groovy")); System.out.println(clazz.getCanonicalName()); for (Method m : clazz.getMethods()) { for (Annotation a : m.getDeclaredAnnotations()) System.out.println(a.toString()); }
The output will only show the class name, not the annotated method. Using a java class instead of a Groovy script, everything works fine.
How have you run the above code? (I have seen the same problem while working with the IntelliJ IDEA plugin). Can you try it out from console?
./alex
–
.w( the_mindstorm )p.