Diagnostics
The Analysis API allows you to access and analyze compiler diagnostics (errors and warnings) associated with entire files or specific elements.
Diagnostics in a KtFile
To collect diagnostics for an entire file, use collectDiagnostics():
The KaDiagnosticCheckerFilter enum allows you to control which kinds of diagnostics are included:
ONLY_COMMON_CHECKERS: Includes diagnostics only from the compiler checkers.ONLY_EXTENDED_CHECKERS: Includes diagnostics from extended checkers (that typically run only in the IDE).EXTENDED_AND_COMMON_CHECKERS: Includes diagnostics from both common and extended checkers.
Diagnostics on an element
To get diagnostics for a specific element, use diagnostics:
Note that the returned list of diagnostics does not include diagnostics for nested KtElements.
KtDiagnosticWithPsi
collectDiagnostics and diagnostics return a collection of KtDiagnosticWithPsi instances. This interface provides access to information about the diagnostic.
Member  | Description  | 
|---|---|
  | The severity of the diagnostic (e.g.,   | 
  | The name of the diagnostic factory that produced the diagnostic.  | 
  | The default message associated with the diagnostic.  | 
  | The   | 
  | The text ranges within the   |