1 Reply Latest reply: Nov 23, 2008 11:43 PM by 843793 RSS

    How to figure out when a visit to a class is ended

    843793
      Question: How to perform actions that are called when the visits to members of a class is finished?

      Currently, DeclarationVisitor have visit functions for members of a class, but there doesn't seem to be an interface that is called AFTER all members of the class has been visited. Is there is a function like visitFinished () or like that?

      Without this interface, it forces developers to write some code twice: once in the AnnotationProcessor and again inside DeclarationVisitor to detect and deal with new definitions of Enums / Classes / Nested classes, which is really bad.

      Did I miss anything?
        • 1. Re: How to figure out when a visit to a class is ended
          843793
          coconut99_99 wrote:
          Question: How to perform actions that are called when the visits to members of a class is finished?

          Currently, DeclarationVisitor have visit functions for members of a class, but there doesn't seem to be an interface that is called AFTER all members of the class has been visited. Is there is a function like visitFinished () or like that?

          Without this interface, it forces developers to write some code twice: once in the AnnotationProcessor and again inside DeclarationVisitor to detect and deal with new definitions of Enums / Classes / Nested classes, which is really bad.
          The visitor structure in apt is a bit awkard and much improved in JSR 269. If you can use JDK 6, I recommend switching to javac and javax.annotation.processing and javax.lang.model.* instead of using apt.

          With that said, to get sequencing on the apt era visitors, you can use

          com.sun.mirror.util.DeclarationVisitors.getSourceOrderDeclarationScanner(pre, post)

          to return a visitor that gets called in a fixed iteration order. The annotation processor should generally just be the outermost loop iterating over the types from the input files.