AbstractMessager

Ron Shapiro ronshapiro at google.com
Tue Jul 23 13:25:07 UTC 2019


Correct. I often need to know whether the same round should do more
processing.

Typically we run many different validations and only want to generate code
if all of those have passed. These validations span different methods and
classes, so keeping track of the state can often get ugly.

Adding those default methods may be a helpful calling convenience, but it
wouldn't assist in determining whether an error has been printed in one of
the methods that already exists.

בתאריך יום ב׳, 22 ביולי 2019, 19:37, מאת Joe Darcy ‏<joe.darcy at oracle.com>:

> Hi Ron,
>
> I take it you aren't finding
>
>      RoundEnvironment.errorRaised()
>
> https://docs.oracle.com/en/java/javase/12/docs/api/java.compiler/javax/annotation/processing/RoundEnvironment.html#errorRaised()
>
> to be sufficient? This will indicate an error has been raised started at
> the *next* round of annotation processing.
>
> I would be more tempted to add some default methods like
>
>   * warn/printWarn(CharSequence msg)
>   * warn/printWarn(CharSequence msg, Element e)
>   * error/printError(CharSequence msg)
>   * error/printError(CharSequence msg, Element e)
>
> Cheers,
>
> -Joe
>
> On 7/19/2019 1:09 PM, Ron Shapiro wrote:
> > In a number of processors that I've implemented, I've wanted to wrap a
> > Messager instance to track if I've printed a diagnostic with an ERROR
> > kind so I can know to abort any generation if the inputs are invalid.
> >
> > There are a number of ways to do this, but what always feels like
> > would be most natural is to be able to create a ForwardingMessager of
> > some sort. I think the easiest way to do this is if there were already
> > an AbstractMessager class, so I wanted to propose adding it to the JSR
> > 269 APIs.
> >
> > The implementation would be rather simple, just telescoping the calls
> > with `null` arguments, just like JavacMessager works.
> >
> > @Override
> > public void printMessage(Diagnostic.Kind kind, CharSequence msg) {
> >     printMessage(kind, msg, null);
> > }
> >
> > @Override
> > public void printMessage(Diagnostic.Kind kind, CharSequence msg,
> > Element e) {
> >     printMessage(kind, msg, e, null);
> > }
> >
> > // etc
> >
> > Alternatively, the methods could become default methods, which is
> > probably the easiest change and doesn't introduce a new type.
> >
> > Does something like this make sense?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20190723/654de80e/attachment.html>


More information about the compiler-dev mailing list