Record Class Diagnostic

java.lang.Object
java.lang.Record
com.darkcollective.relix.embed.Diagnostic
Record Components:
message - what is wrong, in the analyser's own words
location - where, when the analyser knew
severity - whether this stops the query or merely remarks on it

public record Diagnostic(String message, Optional<SourceLocation> location, Severity severity) extends Record
One thing wrong with a query, as data rather than as an exception.

What Relix.validate returns. The rest of the API throws, which is right when the author of the query is the author of the program; a caller building a query from user input needs to render the problem instead, and cannot do that from a stack trace.

It carries a Severity because not everything the analyser reports is fatal. A caller that treats every diagnostic as a refusal would stop on a warning, which is the analyser saying "this is odd" rather than "this cannot run".

Since:
1.0
  • Constructor Details

  • Method Details

    • isError

      public boolean isError()
      Returns whether this diagnostic stops the query from running.
      Returns:
      whether this diagnostic stops the query from running
      Since:
      1.0
    • of

      public static Diagnostic of(String message)
      A diagnostic with no location — an error nothing could attribute to a position. A syntax error is not normally one of those: see of(String, SourceLocation).
      Parameters:
      message - what is wrong
      Returns:
      the diagnostic
      Since:
      1.0
    • of

      public static Diagnostic of(String message, SourceLocation location)
      A diagnostic at a known position — a syntax error the frontend could place.
      Parameters:
      message - what is wrong
      location - where; must not be null
      Returns:
      the diagnostic
      Since:
      1.0
    • of

      public static Diagnostic of(SemanticError error)
      The diagnostic for a semantic error.
      Parameters:
      error - the analyser's error; must not be null
      Returns:
      the diagnostic
      Since:
      1.0
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • message

      public String message()
      Returns the value of the message record component.
      Returns:
      the value of the message record component
    • location

      public Optional<SourceLocation> location()
      Returns the value of the location record component.
      Returns:
      the value of the location record component
    • severity

      public Severity severity()
      Returns the value of the severity record component.
      Returns:
      the value of the severity record component