1616import java .lang .System .Logger ;
1717
1818import java .util .List ;
19- import java .util .Objects ;
2019import java .util .Set ;
2120
2221import java .util .concurrent .locks .Condition ;
3837
3938import static java .lang .System .getLogger ;
4039
40+ import static java .util .Objects .requireNonNull ;
41+
4142final class Processor implements AutoCloseable , javax .annotation .processing .Processor {
4243
4344 private static final Logger LOGGER = getLogger (Processor .class .getName ());
4445
46+ // @GuardedBy("lock")
4547 private final Consumer <? super ProcessingEnvironment > cpe ;
4648
49+ // @GuardedBy("lock")
4750 // run() method invoked under lock
4851 private final Runnable r ;
4952
5053 private final Lock lock ;
5154
55+ // @GuardedBy("lock")
5256 private final Condition c ;
5357
5458 // @GuardedBy("lock")
5559 private boolean closed ;
5660
57- Processor (final Consumer <? super ProcessingEnvironment > cpe ,
58- final Runnable r ) {
61+ /**
62+ * Creates a new {@link Processor}.
63+ *
64+ * <p>This {@link Processor} will be invoked by a {@link BlockingCompilationTask} as part of an invocation of its
65+ * {@link BlockingCompilationTask#run()} method. Its {@link #init(ProcessingEnvironment)} method will be invoked as
66+ * part of {@linkplain javax.annotation.processing.Processor the standard <code>Processor</code> lifecycle}. It will
67+ * call the {@link Consumer#accept(Object) accept(ProcessingEnvironment)} method on the supplied {@link
68+ * Consumer}. Then it will block until {@link #close()} is invoked (from a separate thread, obviously). Before
69+ * exiting, it will invoke the {@link Runnable#run() run()} method of the supplied {@link Runnable}.</p>
70+ *
71+ * @param cpe a {@link Consumer} of {@link ProcessingEnvironment} instances, typically {@link
72+ * BlockingCompilationTask#complete(Object)}; must not be {@code null}
73+ *
74+ * @param r a {@link Runnable} that is invoked at the conclusion of an invocation of the {@link
75+ * #init(ProcessingEnvironment)} method; may be {@code null}
76+ *
77+ * @see #init(ProcessingEnvironment)
78+ *
79+ * @see #close()
80+ *
81+ * @see BlockingCompilationTask
82+ *
83+ * @see javax.annotation.processing.Processor
84+ */
85+ Processor (final Consumer <? super ProcessingEnvironment > cpe , // usually BlockingCompliationTask::complete
86+ final Runnable r ) { // usually BlockingCompliationTask::obtrudeException
5987 super ();
60- this .cpe = Objects . requireNonNull (cpe , "cpe" );
88+ this .cpe = requireNonNull (cpe , "cpe" );
6189 this .r = r == null ? Processor ::sink : r ;
6290 this .lock = new ReentrantLock ();
6391 this .c = this .lock .newCondition ();
@@ -83,12 +111,15 @@ public final void close() {
83111 }
84112
85113 /**
86- * Initializes this {@link Processor}.
114+ * Initializes this {@link Processor} by calling the {@link Consumer#accept(Object) accept(Object)} method on the
115+ * {@link Consumer} {@linkplain #Processor(Consumer, Runnable) supplied at construction time} with the supplied {@link
116+ * ProcessingEnvironment}, <strong>and then blocking until another thread invokes the {@link #close()}
117+ * method</strong>.
87118 *
88119 * @param pe a {@link ProcessingEnvironment}; must not be {@code null}
89120 *
90121 * @deprecated This method should be called only by a Java compiler in accordance with annotation processing
91- * contracts.
122+ * contracts. All other usage will result in undefined behavior.
92123 */
93124 @ Deprecated // to be called only by a Java compiler in accordance with annotation processing contracts
94125 @ Override // Processor;
@@ -108,6 +139,21 @@ public final void init(final ProcessingEnvironment pe) {
108139 }
109140 }
110141
142+ /**
143+ * Returns an {@linkplain List#of() empty, immutable, determinate <code>List</code>} when invoked, regardless of
144+ * arguments.
145+ *
146+ * @param element ignored; may be {@code null}
147+ *
148+ * @param annotation ignored; may be {@code null}
149+ *
150+ * @param member ignored; may be {@code null}
151+ *
152+ * @param userText ignored; may be {@code null}
153+ *
154+ * @return an {@linkplain List#of() empty, immutable, determinate <code>List</code>} when invoked, regardless of
155+ * arguments
156+ */
111157 @ Override // Processor
112158 public final Iterable <? extends Completion > getCompletions (final Element element ,
113159 final AnnotationMirror annotation ,
@@ -116,21 +162,43 @@ public final Iterable<? extends Completion> getCompletions(final Element element
116162 return List .of ();
117163 }
118164
165+ /**
166+ * Returns an {@linkplain Set#of() empty, immutable, determinate <code>Set</code>} when invoked.
167+ *
168+ * @return an {@linkplain Set#of() empty, immutable, determinate <code>Set</code>} when invoked
169+ */
119170 @ Override // Processor
120171 public final Set <String > getSupportedAnnotationTypes () {
121172 return Set .of ();
122173 }
123174
175+ /**
176+ * Returns an {@linkplain Set#of() empty, immutable, determinate <code>Set</code>} when invoked.
177+ *
178+ * @return an {@linkplain Set#of() empty, immutable, determinate <code>Set</code>} when invoked
179+ */
124180 @ Override // Processor
125181 public final Set <String > getSupportedOptions () {
126182 return Set .of ();
127183 }
128184
185+ /**
186+ * Returns the return value of an invocation of the {@link SourceVersion#latestSupported()} method when invoked.
187+ *
188+ * @return the return value of an invocation of the {@link SourceVersion#latestSupported()} method when invoked
189+ */
129190 @ Override // Processor
130191 public final SourceVersion getSupportedSourceVersion () {
131192 return SourceVersion .latestSupported ();
132193 }
133194
195+ /**
196+ * Returns {@code false} when invoked, regardless of arguments.
197+ *
198+ * @param annotations ignored; may be {@code null}
199+ *
200+ * @param roundEnvironment ignored; may be {@code null}
201+ */
134202 @ Override // Processor
135203 public final boolean process (final Set <? extends TypeElement > annotations , final RoundEnvironment roundEnvironment ) {
136204 return false ;
0 commit comments