Class DiagMessage

java.lang.Object
org.checkerframework.framework.source.DiagMessage

@AnnotatedFor("nullness") public class DiagMessage extends Object
A DiagMessage is a kind, a message key, and arguments. The message key will be expanded according to the user locale. Any arguments will then be interpolated into the localized message. A DiagMessage may also carry suggested fixes; see withFixes(java.util.List<org.checkerframework.framework.source.SuggestedFixData>).

By contrast, javax.tools.Diagnostic has just a string message.

  • Constructor Details

    • DiagMessage

      public DiagMessage(Diagnostic.Kind kind, @CompilerMessageKey String messageKey, Object... args)
      Create a DiagMessage.
      Parameters:
      kind - the kind of message
      messageKey - the message key
      args - the arguments that will be interpolated into the localized message
    • DiagMessage

      public DiagMessage(JavaExpressionParseException jppe)
      Creates a DiagMessage corresponding to the given Java Expression parse exception.
      Parameters:
      jppe - a Java Expression parse exception
  • Method Details

    • error

      public static DiagMessage error(@CompilerMessageKey String messageKey, Object... args)
      Create a DiagMessage with kind ERROR.
      Parameters:
      messageKey - the message key
      args - the arguments that will be interpolated into the localized message
      Returns:
      a new DiagMessage
    • warning

      public static DiagMessage warning(@CompilerMessageKey String messageKey, Object... args)
      Create a DiagMessage with kind MANDATORY_WARNING.
      Parameters:
      messageKey - the message key
      args - the arguments that will be interpolated into the localized message
      Returns:
      a new DiagMessage
    • getKind

      public Diagnostic.Kind getKind()
      Returns the kind of this DiagMessage.
      Returns:
      the kind of this DiagMessage
    • getMessageKey

      public @CompilerMessageKey String getMessageKey()
      Returns the message key of this DiagMessage.
      Returns:
      the message key of this DiagMessage
    • getArgs

      public Object[] getArgs()
      Returns the customized optional arguments for the message.
      Returns:
      the customized optional arguments for the message
    • getFixes

      public List<SuggestedFixData> getFixes()
      Returns the suggested fixes for this diagnostic (possibly empty). The returned list is unmodifiable.
      Returns:
      the suggested fixes for this diagnostic
    • withFix

      public DiagMessage withFix(@Nullable SuggestedFixData fix)
      Returns a copy of this DiagMessage with the given suggested fix added, or this instance if fix is null. Does not modify this instance.
      Parameters:
      fix - a suggested fix for this diagnostic, or null if none could be computed
      Returns:
      a copy of this DiagMessage with fix added, or this instance if fix is null
    • withFixes

      public DiagMessage withFixes(List<SuggestedFixData> moreFixes)
      Returns a copy of this DiagMessage with the given suggested fixes added (as alternatives). Does not modify this instance.
      Parameters:
      moreFixes - suggested fixes for this diagnostic
      Returns:
      a copy of this DiagMessage with moreFixes added
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

      @SideEffectFree public String toString()
      Overrides:
      toString in class Object
    • mergeLists

      public static @Nullable List<DiagMessage> mergeLists(@Nullable List<DiagMessage> list1, @Nullable List<DiagMessage> list2)
      Returns the concatenation of the lists.
      Parameters:
      list1 - a list of DiagMessage, or null
      list2 - a list of DiagMessage, or null
      Returns:
      the concatenation of the lists