Class TestDiagnostic

java.lang.Object
org.checkerframework.framework.test.diagnostics.TestDiagnostic
Direct Known Subclasses:
DetailedTestDiagnostic

public class TestDiagnostic extends Object
Represents an expected error/warning message in a Java test file or an error/warning reported by the Java compiler. By contrast, TestDiagnosticLine represents a set of TestDiagnostics, all of which were read from the same line of a file. Subclass DetailedTestDiagnostic is used when the Checker Framework is invoked with the -Adetailedmsgtext flag.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Path
    The path to the test file.
    protected final String
    The base file name of the test file.
    protected final boolean
    Whether this diagnostic should no longer be reported after whole program inference.
    protected final DiagnosticKind
    The diagnostic kind of the output.
    protected final long
    The line number of the diagnostic output.
    protected final String
    The full diagnostic message.
    protected final String
    The message key that usually appears between parentheses in diagnostic messages.
    protected final boolean
    Whether the message key had parentheses around it.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TestDiagnostic(Path file, long lineNumber, DiagnosticKind kind, String message, boolean isFixable)
    Basic constructor that sets the immutable fields of this diagnostic.
    TestDiagnostic(Path file, long lineNumber, DiagnosticKind kind, String messageKey, String message, boolean isFixable)
    Basic constructor that sets the immutable fields of this diagnostic.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Equality is compared based the file name, not the full path, on the messageKey, not the full message, and without considering isFixable and messageKeyParens.
    The path to the test file.
    The base file name of the test file.
    The diagnostic kind of the output.
    long
    The line number of the diagnostic output.
    The full diagnostic message.
    The message key, without surrounding parentheses.
    int
     
    boolean
    Whether WPI can fix the test.
    static boolean
    Determine whether the full diagnostic message should be used as message key.
    Returns the internal representation of this, formatted.
    Returns a representation of this diagnostic as if it appeared in a diagnostics file.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • file

      protected final Path file
      The path to the test file.
    • filename

      protected final String filename
      The base file name of the test file.
    • lineNumber

      protected final long lineNumber
      The line number of the diagnostic output.
    • kind

      protected final DiagnosticKind kind
      The diagnostic kind of the output.
    • message

      protected final String message
      The full diagnostic message.
    • messageKey

      protected final String messageKey
      The message key that usually appears between parentheses in diagnostic messages. Parentheses are removed and field messageKeyParens indicates whether they were present.
    • messageKeyParens

      protected final boolean messageKeyParens
      Whether the message key had parentheses around it.
    • isFixable

      protected final boolean isFixable
      Whether this diagnostic should no longer be reported after whole program inference.
  • Constructor Details

    • TestDiagnostic

      public TestDiagnostic(Path file, long lineNumber, DiagnosticKind kind, String messageKey, String message, boolean isFixable)
      Basic constructor that sets the immutable fields of this diagnostic.
      Parameters:
      file - the path to the test file
      lineNumber - the line number of the diagnostic output
      kind - the diagnostic kind of the output
      messageKey - the message key
      message - the full diagnostic message
      isFixable - whether WPI can fix the test
    • TestDiagnostic

      public TestDiagnostic(Path file, long lineNumber, DiagnosticKind kind, String message, boolean isFixable)
      Basic constructor that sets the immutable fields of this diagnostic.
      Parameters:
      file - the path to the test file
      lineNumber - the line number of the diagnostic output
      kind - the diagnostic kind of the output
      message - the full diagnostic message
      isFixable - whether WPI can fix the test
  • Method Details

    • keepFullMessage

      public static boolean keepFullMessage(String message)
      Determine whether the full diagnostic message should be used as message key. This is useful to ensure e.g. stack traces are fully shown.
      Parameters:
      message - the full message
      Returns:
      whether the full diagnostic message should be used
    • getFile

      public Path getFile()
      The path to the test file.
      Returns:
      the path to the test file
    • getFilename

      public String getFilename()
      The base file name of the test file.
      Returns:
      the base file name of the test file
    • getLineNumber

      public long getLineNumber()
      The line number of the diagnostic output.
      Returns:
      the line number of the diagnostic output
    • getKind

      public DiagnosticKind getKind()
      The diagnostic kind of the output.
      Returns:
      the diagnostic kind of the output
    • getMessageKey

      public String getMessageKey()
      The message key, without surrounding parentheses.
      Returns:
      the message key
    • getMessage

      public String getMessage()
      The full diagnostic message.
      Returns:
      the full diagnostic message
    • isFixable

      public boolean isFixable()
      Whether WPI can fix the test.
      Returns:
      whether WPI can fix the test
    • equals

      public boolean equals(@Nullable Object otherObj)
      Equality is compared based the file name, not the full path, on the messageKey, not the full message, and without considering isFixable and messageKeyParens.
      Overrides:
      equals in class Object
      Returns:
      true if this and otherObj are equal according to file, lineNumber, kind, and messageKey
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a representation of this diagnostic as if it appeared in a diagnostics file. This uses only the base file name, not the full path, and only the message key, not the full message. Field messageKeyParens influences whether the message key is output in parentheses.
      Overrides:
      toString in class Object
      Returns:
      a representation of this diagnostic as if it appeared in a diagnostics file
    • repr

      public String repr()
      Returns the internal representation of this, formatted.
      Returns:
      the internal representation of this, formatted