Skip to content

PsiDiagnosticUtils

open class PsiDiagnosticUtils

Utilities for rendering the source location of PSI elements as human-readable strings for use in diagnostic and log messages.

Constructors

PsiDiagnosticUtils

constructor()

Types

LineAndColumn

A line and column position in a file, optionally carrying the text of the line.

LineAndColumnRange

A range spanning from a start to an end LineAndColumn position.

Companion functions

atLocation

open fun atLocation(@NotNull element: PsiElement): String

Returns a human-readable description of the source location of the given element (its file plus line and column), falling back to an offset-based description if the element is invalid.

open fun atLocation(expression: KtExpression): String

Returns a human-readable description of the source location of the given expression.

open fun atLocation(@NotNull node: ASTNode): String

Returns a human-readable description of the source location of the given AST node.

@NotNull
open fun atLocation(@NotNull file: PsiFile, @NotNull textRange: TextRange): String

Returns a human-readable description of the location of textRange within file.

@NotNull
open fun atLocation(
    file: PsiFile, 
    textRange: TextRange, 
    document: Document
): String

Returns a human-readable description of the location of textRange within file, using the given document to compute the line and column.

offsetToLineAndColumn

@NotNull
open fun offsetToLineAndColumn(@Nullable document: Document, offset: Int): PsiDiagnosticUtils.LineAndColumn

Converts a character offset within document to a LineAndColumn. If document is null or empty, the line is -1 and the column field contains the original offset. For a nonempty document, offset is expected to be within its text.