Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2392

Can't reflect groovy script annotations in java

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Cannot Reproduce
    • 1.5
    • 1.5.2
    • groovy-jdk
    • None
    • SUN JRE 1.5.0.13
      Windows XP SP2

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            vinigodoy Vinícius Godoy de Mendonça
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: