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

javax.lang.model.util.Elements.getAllMembers() does not return initializers

XMLWordPrintable

      The spec for method javax.lang.model.util.Elements.getAllMembers() says:
      ...
      Returns all members of a type element, whether inherited or declared directly. For a class the result also includes its constructors and *initializers*, but not local or anonymous classes.
      ...

      But, in fact, getAllMembers() does not return initializers. For example, the following TestProc processor does not print out initializers defined in Source.

      --
      public class Source {
           static {}
           {}
      }
      --
      import javax.annotation.processing.AbstractProcessor;
      import javax.annotation.processing.RoundEnvironment;
      import javax.annotation.processing.SupportedAnnotationTypes;
      import javax.lang.model.element.TypeElement;
      import javax.lang.model.element.Element;
      import java.util.Set;

      @SupportedAnnotationTypes("*")
      public class TestProc extends AbstractProcessor {
           public boolean process(Set<? extends TypeElement> set, RoundEnvironment re) {
               if(re.processingOver()) return true;

               TypeElement te =
                       re.getSpecifiedTypeElements().toArray(new TypeElement[0])[0];
               for(Element e: processingEnv.getElementUtils().getAllMembers(te)) {
                   System.out.println("e: " + e + " " + e.getKind());
               }
               return true;
           }
      }
      --

      The result is something like the following (there are no any initializers):
      e: getClass() METHOD
      e: hashCode() METHOD
      e: equals(java.lang.Object) METHOD
      e: clone() METHOD
      e: toString() METHOD
      e: notify() METHOD
      e: notifyAll() METHOD
      e: wait(long) METHOD
      e: wait(long,int) METHOD
      e: wait() METHOD
      e: finalize() METHOD
      e: Source() CONSTRUCTOR

      It looks like the implementation does not comply to spec.

            darcy Joe Darcy
            agavrilosunw Alexey Gavrilov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: