Printer

dotty.tools.dotc.printing.Printer
See thePrinter companion object
abstract class Printer

The base class of all printers

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def annotText(annot: Annotation): Text

Textual description of regular annotation in terms of its tree

Textual description of regular annotation in terms of its tree

Attributes

def dclText(sym: Symbol): Text

Textual representation of symbol's declaration

Textual representation of symbol's declaration

Attributes

Textual representation of single denotation's declaration

Textual representation of single denotation's declaration

Attributes

def dclsText(syms: List[Symbol], sep: String): Text

Textual representation of all symbols in given list, using dclText for displaying each.

Textual representation of all symbols in given list, using dclText for displaying each.

Attributes

A description of sym's location

A description of sym's location

Attributes

The fully qualified name of the symbol

The fully qualified name of the symbol

Attributes

def kindString(sym: Symbol): String

The kind of the symbol

The kind of the symbol

Attributes

def locatedText(sym: Symbol): Text

Textual representation of symbol and its location

Textual representation of symbol and its location

Attributes

def locationText(sym: Symbol): Text

If symbol's owner is a printable class C, the text "in C", otherwise ""

If symbol's owner is a printable class C, the text "in C", otherwise ""

Attributes

def nameString(name: Name): String

The name, possibly with with namespace suffix if debugNames is set: /L for local names, /V for other term names, /T for type names

The name, possibly with with namespace suffix if debugNames is set: /L for local names, /V for other term names, /T for type names

Attributes

def nameString(sym: Symbol): String

The name of the given symbol. If !settings.debug, the original name where expansions of operators are translated back to operator symbol. E.g. $eq => =. If settings.uniqid, adds id.

The name of the given symbol. If !settings.debug, the original name where expansions of operators are translated back to operator symbol. E.g. $eq => =. If settings.uniqid, adds id.

Attributes

def plain: Printer

A plain printer without any embellishments

A plain printer without any embellishments

Attributes

The context in which this printer operates

The context in which this printer operates

Attributes

def toText(name: Name): Text

The name as a text

The name as a text

Attributes

def toText(sym: Symbol): Text

Textual representation, including symbol's kind e.g., "class Foo", "method Bar". If hasMeaninglessName is true, uses the owner's name to disambiguate identity.

Textual representation, including symbol's kind e.g., "class Foo", "method Bar". If hasMeaninglessName is true, uses the owner's name to disambiguate identity.

Attributes

def toText(denot: Denotation): Text

Textual representation of denotation

Textual representation of denotation

Attributes

def toText(const: Constant): Text

Textual representation of constant

Textual representation of constant

Attributes

def toText(annot: Annotation): Text

Textual representation of annotation

Textual representation of annotation

Attributes

def toText(tp: Type): Text

Textual representation of type

Textual representation of type

Attributes

def toText(tree: LambdaParam): Text

Textual representation of lambda param

Textual representation of lambda param

Attributes

def toText(sc: Scope): Text

Textual representation of all definitions in a scope using dclText for each

Textual representation of all definitions in a scope using dclText for each

Attributes

def toText[T <: Untyped](tree: Tree[T]): Text

Textual representation of tree

Textual representation of tree

Attributes

Textual representation of source position

Textual representation of source position

Attributes

def toText(result: SearchResult): Text

Textual representation of implicit search result

Textual representation of implicit search result

Attributes

def toText(result: ImportInfo): Text

Textual representation of info relating to an import clause

Textual representation of info relating to an import clause

Attributes

Textual representation of a constraint

Textual representation of a constraint

Attributes

Textual representation of a GADT constraint

Textual representation of a GADT constraint

Attributes

Textual representation of a reference in a capture set

Textual representation of a reference in a capture set

Attributes

def toTextPrefix(tp: Type): Text

Textual representation of a prefix of some reference, ending in . or #

Textual representation of a prefix of some reference, ending in . or #

Attributes

Textual representation of singleton type reference

Textual representation of singleton type reference

Attributes

Concrete methods

def atPrec(prec: Precedence)(op: => Text): Text

Generate text using op, assuming a given precedence level prec.

Generate text using op, assuming a given precedence level prec.

atPrec vs changePrec

This is to be used when changing precedence inside some sort of parentheses: for instance, to print T[A] use toText(T) ~ '[' ~ atPrec(GlobalPrec) { toText(A) } ~ ']'.

If the presence of the parentheses depends on precedence, inserting them manually is most certainly a bug. Use changePrec instead to generate them exactly when needed.

Attributes

def changePrec(prec: Precedence)(op: => Text): Text

Generate text using op, assuming a given precedence level prec. If new level prec is lower than previous level, put text in parentheses.

Generate text using op, assuming a given precedence level prec. If new level prec is lower than previous level, put text in parentheses.

atPrec vs changePrec

To pretty-print A op B, you need something like changePrec(parsing.precedence(op, isType)) { toText(a) ~ op ~ toText(b) } // BUGGY that will insert parentheses around A op B if, for instance, the preceding operator has higher precedence.

But that does not handle infix operators with left- or right- associativity.

If op and op' have the same precedence and associativity, A op B op' C parses as (A op B) op' C if op and op' are left-associative, and as A op (B op' C) if they're right-associative, so we need respectively

val prec = parsing.precedence(op)
// either:
changePrec(prec) { toText(a) ~ op ~ atPrec(prec + 1) { toText(b) } } // for left-associative op and op'
// or:
changePrec(prec) { atPrec(prec + 1) { toText(a) } ~ op ~ toText(b) } // for right-associative op and op'

Attributes

The current precedence level. When pretty-printing arguments of operator op, currentPrecedence must equal op's precedence level, so that pretty-printing expressions using lower-precedence operators can insert parentheses automatically by calling changePrec.

The current precedence level. When pretty-printing arguments of operator op, currentPrecedence must equal op's precedence level, so that pretty-printing expressions using lower-precedence operators can insert parentheses automatically by calling changePrec.

Attributes

def toText(elems: Iterable[Showable], sep: String): Text

Render elements alternating with sep string

Render elements alternating with sep string

Attributes

def toTextGlobal(elem: Showable): Text

Render element within lowest precedence

Render element within lowest precedence

Attributes

def toTextGlobal(elems: Iterable[Showable], sep: String): Text

Render elements within lowest precedence

Render elements within lowest precedence

Attributes

def toTextLocal(elem: Showable): Text

Render element within highest precedence

Render element within highest precedence

Attributes

def toTextLocal(elems: Iterable[Showable], sep: String): Text

Render elements within highest precedence

Render elements within highest precedence

Attributes