Class Diagnostics

java.lang.Object
be.imgn.gaia.processing.Diagnostics

public final class Diagnostics extends Object
Reports errors, warnings and notes at a precise place in the source: an element, one of its annotations, or one attribute of that annotation.
diagnostics.on(method).error("must be public");
diagnostics.on(type).annotation("com.example.Mapper").attribute("target").error("must be an interface");

It counts the errors it reports, so a step can report every problem it finds, then skip generating code if there was any.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    final class 
    A report about an element, possibly narrowed to one of its annotations and one attribute of it.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Reports the error an exception carries, with its message, at the place it names: its element, one of its annotations, or one attribute of that annotation.
    void
    error(String message)
    Reports an error about no element in particular, such as an invalid option.
    int
    Returns the number of errors reported so far through these diagnostics.
    boolean
    Returns whether any error was reported through these diagnostics.
    void
    note(String message)
    Reports a note about no element in particular.
    on(Element element)
    Starts a report about an element.
    void
    warning(String message)
    Reports a warning about no element in particular.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • on

      public Diagnostics.Report on(Element element)
      Starts a report about an element.
      Parameters:
      element - the element the report is about
      Returns:
      the report, to narrow to an annotation and then report
    • error

      public void error(String message)
      Reports an error about no element in particular, such as an invalid option. It makes the compilation fail.
      Parameters:
      message - the message
    • error

      public void error(ProcessingException exception)
      Reports the error an exception carries, with its message, at the place it names: its element, one of its annotations, or one attribute of that annotation. It makes the compilation fail. The stack trace of the exception is not reported.
      try {
          validate(element);
      } catch (ProcessingException e) {
          diagnostics.error(e);
      }
      
      Parameters:
      exception - the exception
    • warning

      public void warning(String message)
      Reports a warning about no element in particular.
      Parameters:
      message - the message
    • note

      public void note(String message)
      Reports a note about no element in particular.
      Parameters:
      message - the message
    • errorCount

      public int errorCount()
      Returns the number of errors reported so far through these diagnostics.
      Returns:
      the number of errors
    • hasErrors

      public boolean hasErrors()
      Returns whether any error was reported through these diagnostics.
      Returns:
      true if an error was reported