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

Correct statement of kinds of elements Processor.process operates over

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 18
    • core-libs
    • None
    • behavioral
    • minimal
    • Spec clarification/correction to describe long-standing behavior.
    • Java API
    • SE

      Summary

      Correct Processor.process method to not imply types are the only kind of element that can be processed.

      Problem

      As currently written, the Processor.process implies only type elements can be processed while package elements and module elements are also subject to annotation processing.

      Solution

      Update the specification of Processor.process and add an explanatory note to RoundEnvironment.getRootElements.

      Specification

      --- a/src/java.compiler/share/classes/javax/annotation/processing/Processor.java
      +++ b/src/java.compiler/share/classes/javax/annotation/processing/Processor.java
      @@ -322,7 +322,7 @@ public interface Processor {
           void init(ProcessingEnvironment processingEnv);
      
           /**
      -     * Processes a set of annotation interfaces on type elements
      +     * Processes a set of annotation interfaces on {@linkplain RoundEnvironment#getRootElements() root elements}
            * originating from the prior round and returns whether or not
            * these annotation interfaces are claimed by this processor.  If {@code
            * true} is returned, the annotation interfaces are claimed and subsequent
      diff --git a/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java b/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java
      index c50c6b787a6..3ff6b05a79e 100644
      --- a/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java
      +++ b/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java
      @@ -25,8 +25,7 @@
      
       package javax.annotation.processing;
      
      -import javax.lang.model.element.Element;
      -import javax.lang.model.element.TypeElement;
      +import javax.lang.model.element.*;
       import java.util.LinkedHashSet;
       import java.util.Collections;
       import java.util.Set;
      @@ -58,9 +57,16 @@ public interface RoundEnvironment {
           boolean errorRaised();
      
           /**
      -     * Returns the {@linkplain Processor root elements} for annotation processing generated
      +     * Returns the {@linkplain Processor root elements} for annotation processing {@linkplain Filer generated}
            * by the prior round.
            *
      +     * @apiNote
      +     * Root elements correspond to the top-level declarations in
      +     * compilation units (JLS section {@jls 7.3}). Root elements are
      +     * most commonly {@linkplain TypeElement types}, but can also be
      +     * {@linkplain PackageElement packages} or {@linkplain
      +     * ModuleElement modules}.
      +     *
            * @return the root elements for annotation processing generated
            * by the prior round, or an empty set if there were none

            darcy Joe Darcy
            darcy Joe Darcy
            Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: