Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6250150

Apt ignores annotation inheritance when selecting processor factories

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 5.0
    • tools
    • apt
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux hipnosi.net 2.4.27-2um #1 Sun Aug 8 09:45:02 UTC 2004 i686 i686 i386 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      (It was not possible to submit this to subcategory "apt" from the public front-end, so I had to submit it to subcategory "tools" instead.)

      If an annotation type, e.g. Bean is annotated with @Inherited, apt will not consider annotation inheritance when the explicitly annotated classes are not in the included set - even if those classes are superclasses of classes that ARE in the included set.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      When I call apt specifying a specific -factory argument, a factory whose supportedAnnotationTypes() returns Collections.singleton("Bean") (see below), apt does not recognise that class Test is (via annotation inheritance from AbstractBean) annotated with @Bean if AbstractBean is not in the included set. However, if AbstractBean *is* in the included set, it works. See example code below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Output should be identical in both cases.
      ACTUAL -
      For

      apt -cp annotationprocessor:libfoo -factory AddGetAndSetMethods fooapp/Test.java

      there is no output.
      For the workaround:

      apt -cp annotationprocessor:libfoo -factory AddGetAndSetMethods fooapp/Test.java libfoo/*.java

      the output is correct:

      Visited Test
      Visited AbstractBean


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      ==> libfoo/AbstractBean.java <==
      @Bean public abstract class AbstractBean {}
       
      ==> libfoo/Bean.java <==
      public @interface Bean {}
       
      ==> fooapp/Test.java <==
      public class Test extends AbstractBean {}
       
      ==> annotationprocessor/AddGetAndSetMethods.java <==
      import com.sun.mirror.apt.AnnotationProcessor;
      import com.sun.mirror.apt.AnnotationProcessors;
      import com.sun.mirror.apt.AnnotationProcessorEnvironment;
      import com.sun.mirror.apt.AnnotationProcessorFactory;
       
      import com.sun.mirror.declaration.AnnotationTypeDeclaration;
      import com.sun.mirror.declaration.ClassDeclaration;
      import com.sun.mirror.declaration.FieldDeclaration;
      import com.sun.mirror.declaration.MethodDeclaration;
      import com.sun.mirror.declaration.Modifier;
      import com.sun.mirror.declaration.TypeDeclaration;
       
      import com.sun.mirror.type.TypeMirror;
      import com.sun.mirror.type.VoidType;
       
      import com.sun.mirror.util.SimpleDeclarationVisitor;
       
      import java.util.Collection;
      import java.util.LinkedList;
      import java.util.List;
      import java.util.Set;
       
      import static com.sun.mirror.declaration.Modifier.*;
      import static com.sun.mirror.util.DeclarationVisitors.*;
      import static java.util.Collections.*;
       
      public class AddGetAndSetMethods implements AnnotationProcessorFactory {
       
        private static final Collection<String> supportedAnnotations =
          singleton ("Bean");
       
        private static final Collection<String> supportedOptions = emptySet ();
       
        public Collection<String> supportedAnnotationTypes() {
          return supportedAnnotations;
        }
       
        public Collection<String> supportedOptions () {
          return supportedOptions;
        }
         
        public AnnotationProcessor getProcessorFor
        (Set<AnnotationTypeDeclaration> atds, AnnotationProcessorEnvironment env) {
          return atds.isEmpty () ? AnnotationProcessors.NO_OP : new Processor (env);
        }
         
        public static class Processor extends SimpleDeclarationVisitor
        implements AnnotationProcessor {
         
          private final AnnotationProcessorEnvironment env;
           
          public Processor (AnnotationProcessorEnvironment env) {
            this.env = env;
          }
           
          public void process () {
            for (TypeDeclaration typeDecl : env.getTypeDeclarations ()) {
              typeDecl.accept (this);
            }
          }
           
          public void visitClassDeclaration (final ClassDeclaration c) {
            System.err.println ("Visited " + c);
          }
           
        } // end of class Processor
       
      } // end of class AddGetAndSetMethods

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      As above: include all source files in the apt run, including source files for superclasses.
      ###@###.### 2005-04-04 17:37:54 GMT

            darcy Joe Darcy
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: