public Tree transform(Tree tree) { if (tree == null) return null; switch (tree) { case ClassDef(int mods, Name name, TypeDef[] tparams, ValDef[][] vparams, Tree tpe, Template impl): return copy.ClassDef(tree, mods, name, transform(tparams), transform(vparams), transform(tpe), transform(impl)); case PackageDef(Tree packaged, Template impl): return copy.PackageDef(tree, transform(packaged), transform(impl)); case ModuleDef(int mods, Name name, Tree tpe, Template impl): return copy.ModuleDef(tree, mods, name, transform(tpe), transform(impl)); case ValDef(int mods, Name name, Tree tpe, Tree rhs): return copy.ValDef(tree, mods, name, transform(tpe), transform(rhs)); case PatDef(int mods, Tree pat, Tree rhs): return copy.PatDef(tree, mods, transform(pat), transform(rhs)); case DefDef(int mods, Name name, TypeDef[] tparams, ValDef[][] vparams, Tree tpe, Tree rhs): return copy.DefDef(tree, mods, name, transform(tparams), transform(vparams), transform(tpe), transform(rhs)); case TypeDef(int mods, Name name, Tree rhs): return copy.TypeDef(tree, mods, name, transform(rhs)); case Import(Tree expr, Name[] selectors): return copy.Import(tree, transform(expr), selectors); case CaseDef(Tree pat, Tree guard, Tree body): return copy.CaseDef(tree, transform(pat), transform(guard), transform(body)); case Template(Tree[] parents, Tree[] body): return copy.Template(tree, transform(parents), transform(body)); case LabelDef(Tree[] params,Tree rhs): return copy.LabelDef(tree, transform(params), transform(rhs)); case Block(Tree[] stats): return copy.Block(tree, transform(stats)); case Tuple(Tree[] trees): return copy.Tuple(tree, transform(trees)); case Visitor(CaseDef[] cases): return copy.Visitor(tree, transform(cases)); case Function(ValDef[] vparams, Tree body): return copy.Function(tree, transform(vparams), transform(body)); case Assign(Tree lhs, Tree rhs): return copy.Assign(tree, transform(lhs), transform(rhs)); case If(Tree cond, Tree thenp, Tree elsep): return copy.If(tree, transform(cond), transform(thenp), transform(elsep)); case New(Template templ): return copy.New(tree, transform(templ)); case Typed(Tree expr, Tree tpe): return copy.Typed(tree, transform(expr), transform(tpe)); case TypeApply(Tree fun, Tree[] args): return copy.TypeApply(tree, transform(fun), transform(args)); case Apply(Tree fun, Tree[] args): return copy.Apply(tree, transform(fun), transform(args)); case Super(Tree tpe): return copy.Super(tree, transform(tpe)); case This(Tree qualifier): return copy.This(tree, transform(qualifier)); case Select(Tree qualifier, Name selector): return copy.Select(tree, transform(qualifier), selector); case Ident(Name name): return copy.Ident(tree, name); case Literal(Object value): return copy.Literal(tree, value); case TypeTerm(): return copy.TypeTerm(tree); case SingletonType(Tree ref): return copy.SingletonType(tree, transform(ref)); case SelectFromType(Tree qualifier, Name selector): return copy.SelectFromType(tree, transform(qualifier), selector); case FunType(Tree[] argtpes, Tree restpe): return copy.FunType(tree, transform(argtpes), transform(restpe)); case CompoundType(Tree[] parents, Tree[] refinements): return copy.CompoundType(tree, transform(parents), transform(refinements)); case AppliedType(Tree tpe, Tree[] args): return copy.AppliedType(tree, transform(tpe), transform(args)); case CovariantType(Tree tpe): return copy.CovariantType(tree, transform(tpe)); default: return tree;
public Tree[] transform(Tree[] ts) { for (int i = 0; i < ts.length; i++) { Tree t = transform(ts[i]); if (t != ts[i]) { Tree[] res = new Tree[ts.length]; System.arraycopy(ts, 0, res, 0, i); res[i] = t; for (int j = i + 1; j < ts.length; j++) res[j] = transform(ts[j]); return res; }
    public Tree transform(Tree tree) {        if (tree == null)            return null;        switch (tree) {	case ClassDef(int mods,		      Name name,		      TypeDef[] tparams,		      ValDef[][] vparams,		      Tree tpe,		      Template impl):	    return copy.ClassDef(tree,				 mods,				 name,				 transform(tparams),				 transform(vparams),				 transform(tpe),				 transform(impl));	case PackageDef(Tree packaged, Template impl):	    return copy.PackageDef(tree,				   transform(packaged),				   transform(impl));	case ModuleDef(int mods,		       Name name,		       Tree tpe,		       Template impl):	    return copy.ModuleDef(tree,				  mods,				  name,				  transform(tpe),				  transform(impl));	case ValDef(int mods,		    Name name,		    Tree tpe,		    Tree rhs):	    return copy.ValDef(tree,			       mods,			       name,			       transform(tpe),			       transform(rhs));	case PatDef(int mods,		    Tree pat,		    Tree rhs):	    return copy.PatDef(tree,			       mods,			       transform(pat),			       transform(rhs));	case DefDef(int mods,		    Name name,		    TypeDef[] tparams,		    ValDef[][] vparams,		    Tree tpe,		    Tree rhs):	    return copy.DefDef(tree,			       mods,			       name,			       transform(tparams),			       transform(vparams),			       transform(tpe),			       transform(rhs));	case TypeDef(int mods,		     Name name,		     Tree rhs):	    return copy.TypeDef(tree,				mods,				name,				transform(rhs));	case Import(Tree expr, Name[] selectors):	    return copy.Import(tree,			       transform(expr),			       selectors);	case CaseDef(Tree pat, Tree guard, Tree body):	    return copy.CaseDef(tree,				transform(pat),				transform(guard),				transform(body));	case Template(Tree[] parents, Tree[] body):	    return copy.Template(tree,				 transform(parents),				 transform(body));	case LabelDef(Tree[] params,Tree rhs):	    return copy.LabelDef(tree,				 transform(params),				 transform(rhs));	case Block(Tree[] stats):	    return copy.Block(tree,			      transform(stats));	case Tuple(Tree[] trees):	    return copy.Tuple(tree,			      transform(trees));	case Visitor(CaseDef[] cases):	    return copy.Visitor(tree,				transform(cases));	case Function(ValDef[] vparams, Tree body):	    return copy.Function(tree,				 transform(vparams),				 transform(body));	case Assign(Tree lhs, Tree rhs):	    return copy.Assign(tree,			       transform(lhs),			       transform(rhs));	case If(Tree cond, Tree thenp, Tree elsep):	    return copy.If(tree,			   transform(cond),			   transform(thenp),			   transform(elsep));	case New(Template templ):	    return copy.New(tree,			    transform(templ));	case Typed(Tree expr, Tree tpe):	    return copy.Typed(tree,			      transform(expr),			      transform(tpe));	case TypeApply(Tree fun, Tree[] args):	    return copy.TypeApply(tree,				  transform(fun),				  transform(args));	case Apply(Tree fun, Tree[] args):	    return copy.Apply(tree,			      transform(fun),			      transform(args));	case Super(Tree tpe):	    return copy.Super(tree,			      transform(tpe));	case This(Tree qualifier):	    return copy.This(tree,			     transform(qualifier));	case Select(Tree qualifier, Name selector):	    return copy.Select(tree,			       transform(qualifier),			       selector);	case Ident(Name name):	    return copy.Ident(tree, name);	case Literal(Object value):	    return copy.Literal(tree, value);	case TypeTerm():	    return copy.TypeTerm(tree);	case SingletonType(Tree ref):	    return copy.SingletonType(tree,				      transform(ref));	case SelectFromType(Tree qualifier, Name selector):	    return copy.SelectFromType(tree,				       transform(qualifier),				       selector);	case FunType(Tree[] argtpes, Tree restpe):	    return copy.FunType(tree,				transform(argtpes),				transform(restpe));	case CompoundType(Tree[] parents, Tree[] refinements):	    return copy.CompoundType(tree,				     transform(parents),				     transform(refinements));	case AppliedType(Tree tpe, Tree[] args):	    return copy.AppliedType(tree,				    transform(tpe),				    transform(args));	case CovariantType(Tree tpe):	    return copy.CovariantType(tree,				      transform(tpe));	default:	    return tree;        }    }