scala.tools.nsc.typechecker.AnalyzerPlugins
Adapt a tree that has an annotated type to the given type tp, taking into account the given mode (see method adapt in trait Typers).
Adapt a tree that has an annotated type to the given type tp, taking into account the given mode (see method adapt in trait Typers).
An implementation cannot rely on canAdaptAnnotations being called before. If the implementing class cannot do the adapting, it should return the tree unchanged.
Decide whether this analyzer plugin can adapt a tree that has an annotated type to the given type tp, taking into account the given mode (see method adapt in trait Typers).
Selectively activate this analyzer plugin, e.
Selectively activate this analyzer plugin, e.g. according to the compiler phase.
Note that the current phase can differ from the global compiler phase (look for enteringPhase
invocations in the compiler). For instance, lazy types created by the UnPickler are completed
at the phase in which their symbol is created. Observations show that this can even be the
parser phase. Since symbol completion can trigger subtyping, typing etc, your plugin might
need to be active also in phases other than namer and typer.
Typically, this method can be implemented as
global.phase.id < global.currentRun.picklerPhase.id
Let analyzer plugins change the expected type before type checking a tree.
Let analyzer plugins change the types assigned to definitions.
Let analyzer plugins change the types assigned to definitions. For definitions that have an annotated type, the assigned type is obtained by typing that type tree. Otherwise, the type is inferred by typing the definition's righthand side.
In order to know if the type was inferred, you can query the wasEmpty
field in the tpt
TypeTree of the definition (for DefDef and ValDef).
(*) If the type of a method or value is inferred, the type-checked tree is stored in the
analyzer.transformed
hash map, indexed by the definition's rhs tree.
NOTE: Invoking the type checker can lead to cyclic reference errors. For instance, if this
method is called from the type completer of a recursive method, type checking the mehtod
rhs will invoke the same completer again. It might be possible to avoid this situation by
assigning tpe
to defTree.symbol
(untested) - the final type computed by this method
will then be assigned to the definition's symbol by monoTypeCompleter (in Namers).
The hooks into typeSig
allow analyzer plugins to add annotations to (or change the types
of) definition symbols. This cannot not be achieved by using pluginsTyped
: this method
is only called during type checking, so changing the type of a symbol at this point is too
late: references to the symbol might already be typed and therefore obtain the the original
type assigned during naming.
is the definition for which the type was computed. The different cases are outlined below. Note that this type is untyped (for methods and values with inferred type, the typed rhs trees are available in analyzer.transformed).
Case defTree: Template
Case defTree: ClassDef
Case defTree: ModuleDef
Case defTree: DefDef
Case defTree: ValDef
pluginsTypeSigAccessor
)Case defTree: TypeDef
Modify the types of field accessors.
Modify the types of field accessors. The namer phase creates method types for getters and setters based on the type of the corresponding field.
Note: in order to compute the method type of an accessor, the namer calls typeSig
on the
ValDef
tree of the corresponding field. This implies that the pluginsTypeSig
method
is potentially called multiple times for the same ValDef tree.
The method type created by the namer for the accessor
The typer for the ValDef (not for the rhs)
The ValDef corresponding to the accessor
The accessor method symbol (getter, setter, beanGetter or beanSetter)
Let analyzer plugins modify the type that has been computed for a tree.
Let analyzer plugins modify the type that has been computed for a tree.
The type inferred by the type checker, initially (for first plugin) tree.tpe
The yper that type checked tree
The type-checked tree
Mode that was used for typing tree
Expected type that was used for typing tree
Modify the type of a return expression.
Modify the type of a return expression. By default, return expressions have type NothingClass.tpe.
The type of the return expression
The typer that was used for typing the return tree
The typed return expression tree
The return type of the enclosing method
(analyzerPlugin: StringAdd).self
(analyzerPlugin: StringFormat).self
(analyzerPlugin: ArrowAssoc[Analyzer.AnalyzerPlugin]).x
(Since version 2.10.0) Use leftOfArrow
instead
(analyzerPlugin: Ensuring[Analyzer.AnalyzerPlugin]).x
(Since version 2.10.0) Use resultOfEnsuring
instead