scala.tools.refactoring.transformation
Replace the first sequence of elements with another sequence.
Applies a transformation to all subtrees of a tree T, returning a new tree,typically of the same kind as T.
Applies a transformation to all subtrees of a tree T, returning a new tree,typically of the same kind as T.
If the transformation fails on one child, abort and fail the whole application.
Creates a transformation that always returns the value x.
Creates a transformation that always returns the value x.
Always fails, independent of the input.
Always fails, independent of the input.
Locates the imports in a PackageDef.
Locates the imports in a PackageDef. If we have nested packages, it will only match in the innermost.
Applies a transformation to all subtrees of a tree T, returning a new tree,typically of the same kind as T.
Applies a transformation to all subtrees of a tree T, returning a new tree,typically of the same kind as T.
If the transformation fails on one child, apply the
identity transformation id
and don't fail, unlike
allChildren
.
Creates a function call fun
on the selector and passes a function with
a single parameter param
and the body body
.
Creates a function call fun
on the selector and passes a function with
a single parameter param
and the body body
.
Example:
someExpr becomes someExpr fun (param => body)
Creates a function call fun
on the selector and passes a function with
no parameter and the body body
.
Creates a function call fun
on the selector and passes a function with
no parameter and the body body
.
Example:
someExpr becomes someExpr fun (body)
Do a transformation until it succeeded once, then just fail.
Do a transformation until it succeeded once, then just fail.
Note that because of the statefulness of once, you need to make sure that it isn't accidentally passed as a by-name parameter to another transformation and instantiated multiple times.
We often want to use transformations as predicates, which execute the next transformations if the result is true.
We often want to use transformations as predicates, which execute the next transformations if the result is true. For example:
val tree_with_range_pos = filter[Tree] { case t: Tree => t.pos.isRange }
We can then use the predicate like this: tree_with_range_pos andThen do_something_with_the_tree orElse nothing
Always succeeds and returns the input unchanged.
Always succeeds and returns the input unchanged.
Construct a transformation from a partial function; this is the most commonly used way to create new transformations, for example like:
Construct a transformation from a partial function; this is the most commonly used way to create new transformations, for example like:
val reverse_all_class_members = transformation[Tree, Tree] { case t: Template => t.copy(body = t.body.reverse) }
Applies a transformation bottom-up, that is, it applies the transformation to the children of the tree first and then to their parent.
Applies a transformation bottom-up, that is, it applies the transformation to the children of the tree first and then to their parent. The consequence is that the parent "sees" its transformed children.
Applies a transformation top-down, that is, it applies the transformation to the tree T and then passes the transformed T to all children.
Applies a transformation top-down, that is, it applies the transformation to the tree T and then passes the transformed T to all children. The consequence is that the children "see" their new parent.