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

Java5 configureClassNode does not take care of parameter annotations

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.8.1, 1.7.11
    • Compiler
    • None
    • Patch

    Description

      whenever annotation parameters are specified in byte-code, the Java5 vm-plugin does not include those annotations as AnnotationNode instances when configuring a ClassNode for that particular class.

      the following code is from a local test-case:

      void testParameterAnnotation() { 
      
              GroovyClassLoader gcl = new GroovyClassLoader() 
      
              gcl.parseClass """ 
                  import java.lang.annotation.* 
      
                  @Target(ElementType.METHOD) 
                  @Retention(RetentionPolicy.RUNTIME) 
                  @interface MethodAnnotation {} 
      
                  @Target(ElementType.PARAMETER) 
                  @Retention(RetentionPolicy.RUNTIME) 
                  @interface ParameterAnnotation {} 
      
                  interface MyInterface { 
                      @MethodAnnotation 
                      def method(@ParameterAnnotation def param) 
                  } 
              """ 
      
              GroovyCodeSource codeSource = new GroovyCodeSource(""" 
                  class MyInterfaceImpl implements MyInterface { 
                      def method(def param) {} 
                  } 
              """, "script" + System.currentTimeMillis() + ".groovy", "/groovy/script") 
      
              CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, gcl) 
              cu.addSource(codeSource.getName(), codeSource.scriptText); 
              cu.compile(CompilePhase.FINALIZATION.phaseNumber) 
      
              def classNode = cu.getClassNode("MyInterfaceImpl") 
              def interfaceClassNode = classNode.getInterfaces().find { it.nameWithoutPackage == 'MyInterface' } 
      
              def methodNode = interfaceClassNode.getDeclaredMethods("method")[0] 
      
              // check if the AnnotationNode for 'MethodAnnotation' has been created 
              assert methodNode.getAnnotations().any { AnnotationNode an -> an.classNode.nameWithoutPackage == 'MethodAnnotation' } 
              
              // this one will fail, since parameter annotations are ignored by Java5Plugin (and above) 
              assert methodNode.getParameters()[0].getAnnotations().any { AnnotationNode an -> an.classNode.nameWithoutPackage == 'ParameterAnnotation' } 
      }
      

      Attachments

        1. java5_param_annos.patch
          3 kB
          Andre Steingress

        Activity

          People

            blackdrag Jochen Theodorou
            andre.steingress Andre Steingress
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: