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

Annotation for inner interface in Java stub should not use dollar notation

    XMLWordPrintableJSON

Details

    • Patch

    Description

      From looking at the code, this issue appears to affect all versions after 1.7.3, but I've only tested a few.

      As with many other places in the code, printAnnotation needs to replace '$' with '.' in inner interface class names. Otherwise a "cannot find symbol" error occurs during java compilation.

      In 1.7.4, the patch is:

      diff --git a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
      index eff3ac1..7a1e92e 100644
      --- a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
      +++ b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
      @@ -591,7 +591,7 @@ public class JavaStubGenerator
           private void printAnnotations(PrintWriter out, AnnotatedNode annotated) {
               if (!java5) return;
               for (AnnotationNode annotation : annotated.getAnnotations()) {
      -            out.print("@" + annotation.getClassNode().getName() + "(");
      +            out.print("@" + annotation.getClassNode().getName().replace('$', '.') + "(");
                   boolean first = true;
                   Map<String, Expression> members = annotation.getMembers();
                   for (String key : members.keySet()) {
      

      In master, it would be:

      diff --git a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
      index 1e8f585..42fc5e2 100644
      --- a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
      +++ b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
      @@ -716,7 +716,7 @@ public class JavaStubGenerator {
           }
       
           private void printAnnotation(PrintWriter out, AnnotationNode annotation) {
      -        out.print("@" + annotation.getClassNode().getName() + "(");
      +        out.print("@" + annotation.getClassNode().getName().replace('$', '.') + "(");
               boolean first = true;
               Map<String, Expression> members = annotation.getMembers();
               for (String key : members.keySet()) {
      

      Attachments

        1. groovy-annots2.zip
          124 kB
          Eric Sword
        2. groovy-annots.zip
          50 kB
          Eric Sword

        Activity

          People

            paulk Paul King
            agrimm Andy Grimm
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: