diff options
author | Paul Phillips <paulp@improving.org> | 2012-02-23 09:21:12 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-02-23 09:21:16 -0800 |
commit | 382a16e948b146c6e32a4c9e7f01fb2624717e57 (patch) | |
tree | 3b3685e72b6d645adf5df14abeffe5384194e329 /src/library | |
parent | 329d99829d4e51d0847000439de595de7b565686 (diff) | |
download | scala-382a16e948b146c6e32a4c9e7f01fb2624717e57.tar.gz scala-382a16e948b146c6e32a4c9e7f01fb2624717e57.tar.bz2 scala-382a16e948b146c6e32a4c9e7f01fb2624717e57.zip |
One more to derive trees.
ClassDefs, CaseDefs, and LabelDefs. Dotting eyes,
crossing tees. Point of diminishing returns is reached,
declare victory and withdraw.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/reflect/api/Trees.scala | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/src/library/scala/reflect/api/Trees.scala b/src/library/scala/reflect/api/Trees.scala index 7d3477a227..bf427df09a 100644 --- a/src/library/scala/reflect/api/Trees.scala +++ b/src/library/scala/reflect/api/Trees.scala @@ -681,10 +681,10 @@ trait Trees { self: Universe => sys.error("Not a DefDef: " + t + "/" + t.getClass) } def copyValDef(tree: Tree)( - mods: Modifiers = null, - name: Name = null, - tpt: Tree = null, - rhs: Tree = null + mods: Modifiers = null, + name: Name = null, + tpt: Tree = null, + rhs: Tree = null ): ValDef = tree match { case ValDef(mods0, name0, tpt0, rhs0) => treeCopy.ValDef(tree, @@ -696,6 +696,22 @@ trait Trees { self: Universe => case t => sys.error("Not a ValDef: " + t + "/" + t.getClass) } + def copyClassDef(tree: Tree)( + mods: Modifiers = null, + name: Name = null, + tparams: List[TypeDef] = null, + impl: Template = null + ): ClassDef = tree match { + case ClassDef(mods0, name0, tparams0, impl0) => + treeCopy.ClassDef(tree, + if (mods eq null) mods0 else mods, + if (name eq null) name0 else name, + if (tparams eq null) tparams0 else tparams, + if (impl eq null) impl0 else impl + ) + case t => + sys.error("Not a ClassDef: " + t + "/" + t.getClass) + } def deriveDefDef(ddef: Tree)(applyToRhs: Tree => Tree): DefDef = ddef match { case DefDef(mods0, name0, tparams0, vparamss0, tpt0, rhs0) => @@ -715,6 +731,24 @@ trait Trees { self: Universe => case t => sys.error("Not a Template: " + t + "/" + t.getClass) } + def deriveClassDef(cdef: Tree)(applyToImpl: Template => Template): ClassDef = cdef match { + case ClassDef(mods0, name0, tparams0, impl0) => + treeCopy.ClassDef(cdef, mods0, name0, tparams0, applyToImpl(impl0)) + case t => + sys.error("Not a ClassDef: " + t + "/" + t.getClass) + } + def deriveCaseDef(cdef: Tree)(applyToBody: Tree => Tree): CaseDef = cdef match { + case CaseDef(pat0, guard0, body0) => + treeCopy.CaseDef(cdef, pat0, guard0, applyToBody(body0)) + case t => + sys.error("Not a CaseDef: " + t + "/" + t.getClass) + } + def deriveLabelDef(ldef: Tree)(applyToRhs: Tree => Tree): LabelDef = ldef match { + case LabelDef(name0, params0, rhs0) => + treeCopy.LabelDef(ldef, name0, params0, applyToRhs(rhs0)) + case t => + sys.error("Not a LabelDef: " + t + "/" + t.getClass) + } class Traverser { protected var currentOwner: Symbol = definitions.RootClass |